Advertisement
Guest User

SOFA - FFMPEG patch

a guest
Jul 27th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.51 KB | None | 0 0
  1. diff --git a/applications/plugins/SofaPython/CMakeLists.txt b/applications/plugins/SofaPython/CMakeLists.txt
  2. index 4e09cb8..6e9fc5c 100644
  3. --- a/applications/plugins/SofaPython/CMakeLists.txt
  4. +++ b/applications/plugins/SofaPython/CMakeLists.txt
  5. @@ -111,6 +111,7 @@ if(${CMAKE_COMPILER_IS_GNUCC})
  6.  endif()
  7.  
  8.  AddCompilerDefinitions("SOFA_BUILD_SOFAPYTHON")
  9. +AddCompilerDefinitions("__STDC_CONSTANT_MACROS")
  10.  AddLinkerDependencies(SofaCore SofaSimulationCommon SofaGuiCommon ${PYTHON_LIBRARIES})
  11.  
  12.  include(${SOFA_CMAKE_DIR}/postProject.cmake)
  13. diff --git a/applications/plugins/image/ImageTypes.h b/applications/plugins/image/ImageTypes.h
  14. index 38ef84d..4e2c620 100644
  15. --- a/applications/plugins/image/ImageTypes.h
  16. +++ b/applications/plugins/image/ImageTypes.h
  17. @@ -27,7 +27,7 @@
  18.  #define IMAGE_IMAGETYPES_H
  19.  
  20.  #if  defined (SOFA_HAVE_FFMPEG)  || defined (SOFA_EXTLIBS_FFMPEG)
  21. -#define cimg_use_ffmpeg
  22. +//#define cimg_use_ffmpeg
  23.  #endif
  24.  #ifdef SOFA_IMAGE_HAVE_OPENCV // should be "SOFA_HAVE_OPENCV" -> use "SOFA_IMAGE_HAVE_OPENCV" until the opencv plugin is fixed..
  25.  #define cimg_use_opencv
  26. diff --git a/applications/sofa/gui/SofaGuiCommon/CMakeLists.txt b/applications/sofa/gui/SofaGuiCommon/CMakeLists.txt
  27. index 5b86e3a..4120589 100644
  28. --- a/applications/sofa/gui/SofaGuiCommon/CMakeLists.txt
  29. +++ b/applications/sofa/gui/SofaGuiCommon/CMakeLists.txt
  30. @@ -34,6 +34,7 @@ add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
  31.  
  32.  
  33.  AddCompilerDefinitions("SOFA_BUILD_SOFAGUI")
  34. +AddCompilerDefinitions("__STDC_CONSTANT_MACROS")
  35.  AddLinkerDependencies(SofaComponentMain SofaGraphComponent SofaBaseCollision SofaUserInteraction SofaBaseVisual)
  36.  
  37.  include(${SOFA_CMAKE_DIR}/postProject.cmake)
  38. diff --git a/applications/sofa/gui/SofaGuiMain/CMakeLists.txt b/applications/sofa/gui/SofaGuiMain/CMakeLists.txt
  39. index e8a6624..7afdab7 100644
  40. --- a/applications/sofa/gui/SofaGuiMain/CMakeLists.txt
  41. +++ b/applications/sofa/gui/SofaGuiMain/CMakeLists.txt
  42. @@ -25,6 +25,7 @@ if(SOFA-LIB_GUI_QGLVIEWER)
  43.  endif()
  44.  
  45.  AddCompilerDefinitions("SOFA_BUILD_GUIMAIN")
  46. +AddCompilerDefinitions("__STDC_CONSTANT_MACROS")
  47.  AddLinkerDependencies(SofaGuiCommon)
  48.  
  49.  if(SOFA-LIB_GUI_QT)
  50. diff --git a/applications/sofa/gui/qt/CMakeLists.txt b/applications/sofa/gui/qt/CMakeLists.txt
  51. index 7a2b763..8d1e54a 100644
  52. --- a/applications/sofa/gui/qt/CMakeLists.txt
  53. +++ b/applications/sofa/gui/qt/CMakeLists.txt
  54. @@ -153,6 +153,7 @@ set(FORM_FILES_GROUP "Generated")
  55.  add_library(${PROJECT_NAME} SHARED ${HEADER_FILES} ${MOC_FILES} ${FORM_FILES} ${SOURCE_FILES})
  56.  
  57.  AddCompilerDefinitions("SOFA_BUILD_SOFAGUIQT")
  58. +AddCompilerDefinitions("__STDC_CONSTANT_MACROS")
  59.  AddLinkerDependencies(SofaGuiCommon Qwt SofaBaseVisual SofaExporter SofaLoader SofaOpenglVisual SofaMiscForceField)
  60.  
  61.  
  62. diff --git a/framework/sofa/helper/CMakeLists.txt b/framework/sofa/helper/CMakeLists.txt
  63. index 1ec171b..c9bbd71 100644
  64. --- a/framework/sofa/helper/CMakeLists.txt
  65. +++ b/framework/sofa/helper/CMakeLists.txt
  66. @@ -186,10 +186,46 @@ if(NOT SOFA-MISC_NO_OPENGL)
  67.      )
  68.  endif()
  69.  
  70. -if(SOFA-EXTERNAL_FFMPEG)
  71. +#if((SOFA-EXTERNAL_FFMPEG) AND (NOT WIN32))
  72. +if(SOFA-EXTERNAL_FFMPEG)
  73.      list(APPEND HEADER_FILES "gl/VideoRecorder.h")
  74.  
  75.      list(APPEND SOURCE_FILES "gl/VideoRecorder.cpp")
  76. +    include_directories(${SOFA-EXTERNAL_FFMPEG_PATH}/include)
  77. +    if (WIN32)
  78. + AddLinkerDependencies("${SOFA-EXTERNAL_FFMPEG_PATH}/lib/avformat.lib")
  79. + AddLinkerDependencies("${SOFA-EXTERNAL_FFMPEG_PATH}/lib/avcodec.lib")
  80. + AddLinkerDependencies("${SOFA-EXTERNAL_FFMPEG_PATH}/lib/avutil.lib")
  81. + AddLinkerDependencies("${SOFA-EXTERNAL_FFMPEG_PATH}/lib/swscale.lib")
  82. +        elseif (APPLE)
  83. +                set( FFMPEG_LIBS
  84. +                        "libavcodec.a"
  85. +                        "libavformat.a"
  86. +                        "libavutil.a"
  87. +                        "libswscale.a"
  88. +                        "libbz2.a"
  89. +                        "libmp3lame.a"
  90. +                        "libx264.a"
  91. +                        "libfaac.a"
  92. +                        "libxvidcore.a"
  93. +                        "libswresample.a"
  94. +                        "/usr/lib/libiconv.dylib"
  95. +                        )
  96. +                        find_library(FOUNDATION CoreFoundation)
  97. +            find_library(VIDEO CoreVideo)
  98. +            find_library(VIDEO_DECOD_ACC VideoDecodeAcceleration)
  99. +            find_library(ICONV iconv)
  100. +            target_link_libraries(${PROJECT_NAME}  ${FFMPEG_LIBS} ${FOUNDATION} ${VIDEO} ${VIDEO_DECOD_ACC})
  101. +        elseif (UNIX)
  102. +            AddLinkerDependencies(avcodec)
  103. +            AddLinkerDependencies(avformat)
  104. +            AddLinkerDependencies(avutil)
  105. +            AddLinkerDependencies(swscale)
  106. +            AddLinkerDependencies(avdevice)
  107. +            AddLinkerDependencies(avfilter)
  108. +            AddLinkerDependencies(swresample)
  109. +        endif()
  110. +
  111.  endif()
  112.  
  113.  if(PS3)
  114. diff --git a/framework/sofa/helper/gl/VideoRecorder.cpp b/framework/sofa/helper/gl/VideoRecorder.cpp
  115. index cbf5532..5e87e74 100644
  116. --- a/framework/sofa/helper/gl/VideoRecorder.cpp
  117. +++ b/framework/sofa/helper/gl/VideoRecorder.cpp
  118. @@ -88,7 +88,7 @@ AVFrame *VideoRecorder::alloc_picture(PixelFormat pix_fmt, int width, int height
  119.      return picture;
  120.  }
  121.  
  122. -AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, CodecID codec_id, const std::string& codec)
  123. +AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, AVCodecID codec_id, const std::string& codec)
  124.  {
  125.      AVCodecContext *c;
  126.      AVStream *st;
  127. @@ -99,7 +99,7 @@ AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, CodecID codec_id,
  128.  
  129.      c = st->codec;
  130.      c->codec_id = codec_id;
  131. -    c->codec_type = CODEC_TYPE_VIDEO;
  132. +    c->codec_type = AVMEDIA_TYPE_VIDEO;
  133.  
  134.      /* put sample parameters */
  135.      c->bit_rate = p_bitrate;
  136. @@ -145,8 +145,8 @@ AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, CodecID codec_id,
  137.              c->qcompress = 0.6;
  138.              c->max_b_frames= 3;
  139.              c->me_cmp |= FF_CMP_CHROMA;
  140. -            c->partitions |= X264_PART_I8X8 | X264_PART_I4X4 |
  141. -                    X264_PART_P8X8 | X264_PART_B8X8;
  142. +//            c->partitions |= X264_PART_I8X8 | X264_PART_I4X4 |
  143. +//                    X264_PART_P8X8 | X264_PART_B8X8;
  144.              c->me_method = ME_HEX;
  145.  
  146.              //c->gop_size = 250;
  147. @@ -155,11 +155,11 @@ AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, CodecID codec_id,
  148.              c->scenechange_threshold = 40;
  149.              c->i_quant_factor = 0.71;
  150.              c->b_frame_strategy = 1;
  151. -            c->directpred = 1;
  152. +//            c->directpred = 1;
  153.              c->trellis = 1;
  154. -            c->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS |
  155. -                    CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP;
  156. -            c->weighted_p_pred = 2;
  157. +            c->flags2 = CODEC_FLAG2_FAST    | CODEC_FLAG2_NO_OUTPUT |
  158. +                    CODEC_FLAG2_LOCAL_HEADER | CODEC_FLAG2_IGNORE_CROP |  CODEC_FLAG2_CHUNKS;
  159. +    //        c->weighted_p_pred = 2;
  160.          }
  161.          else if (codec == std::string("mpeg4"))
  162.          {
  163. @@ -180,8 +180,8 @@ AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, CodecID codec_id,
  164.              c->qcompress = 0.6;
  165.              c->max_b_frames= 3;
  166.              c->me_cmp |= FF_CMP_CHROMA;
  167. -            c->partitions |= X264_PART_I8X8 | X264_PART_I4X4 |
  168. -                    X264_PART_P8X8 | X264_PART_B8X8;
  169. +//            c->partitions |= X264_PART_I8X8 | X264_PART_I4X4 |
  170. + //                   X264_PART_P8X8 | X264_PART_B8X8;
  171.              c->me_method = ME_HEX;
  172.  
  173.              //c->gop_size = 250;
  174. @@ -190,13 +190,13 @@ AVStream *VideoRecorder::add_video_stream(AVFormatContext *oc, CodecID codec_id,
  175.              c->scenechange_threshold = 40;
  176.              c->i_quant_factor = 0.71;
  177.              c->b_frame_strategy = 1;
  178. -            c->directpred = 1;
  179. +       //     c->directpred = 1;
  180.              c->trellis = 1;
  181. -            c->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS |
  182. -                    CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP;
  183. -            c->weighted_p_pred = 2;
  184. +            c->flags2 = CODEC_FLAG2_FAST    | CODEC_FLAG2_NO_OUTPUT |
  185. +            CODEC_FLAG2_LOCAL_HEADER | CODEC_FLAG2_IGNORE_CROP | CODEC_FLAG2_CHUNKS;
  186. +    //        c->weighted_p_pred = 2;
  187.  
  188. -            c->cqp = 0;
  189. +//            c->cqp = 0;
  190.  
  191.              /*
  192.                          c->me_range = 16;
  193. @@ -242,7 +242,7 @@ bool VideoRecorder::open_video(AVFormatContext *oc, AVStream *st)
  194.      }
  195.  
  196.      /* open the codec */
  197. -    if (avcodec_open(c, codec) < 0)
  198. +    if (avcodec_open2(c, codec,NULL) < 0)
  199.      {
  200.          std::cerr <<"could not open codec"<<std::endl;
  201.          return false;
  202. @@ -324,7 +324,7 @@ bool VideoRecorder::write_delayed_video_frame(AVFormatContext *oc, AVStream *st)
  203.  
  204.              pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
  205.              if(c->coded_frame->key_frame)
  206. -                pkt.flags |= PKT_FLAG_KEY;
  207. +                pkt.flags |= AV_PKT_FLAG_KEY;
  208.              pkt.stream_index= st->index;
  209.              pkt.data= videoOutbuf;
  210.              pkt.size= out_size;
  211. @@ -388,7 +388,7 @@ bool VideoRecorder::write_video_frame(AVFormatContext *oc, AVStream *st)
  212.          AVPacket pkt;
  213.          av_init_packet(&pkt);
  214.  
  215. -        pkt.flags |= PKT_FLAG_KEY;
  216. +        pkt.flags |= AV_PKT_FLAG_KEY;
  217.          pkt.stream_index= st->index;
  218.          pkt.data= (uint8_t *)pPicture;
  219.          pkt.size= sizeof(AVPicture);
  220. @@ -408,7 +408,7 @@ bool VideoRecorder::write_video_frame(AVFormatContext *oc, AVStream *st)
  221.              std::cout << "Encoded Video Frame: " << c->coded_frame->pts << std::endl;
  222.              pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
  223.              if(c->coded_frame->key_frame)
  224. -                pkt.flags |= PKT_FLAG_KEY;
  225. +                pkt.flags |= AV_PKT_FLAG_KEY;
  226.              pkt.stream_index= st->index;
  227.              pkt.data= videoOutbuf;
  228.              pkt.size= out_size;
  229. @@ -519,11 +519,11 @@ bool VideoRecorder::init(const std::string& filename, unsigned int framerate, un
  230.      }
  231.  
  232.      // set the output parameters (must be done even if no parameters)
  233. -    if (av_set_parameters(pFormatContext, NULL) < 0)
  234. +/*    if (av_set_parameters(pFormatContext, NULL) < 0)
  235.      {
  236.          std::cerr <<"Invalid output format parameters" << std::endl;
  237.          return false;
  238. -    }
  239. +    }*/
  240.  
  241.      // now that all the parameters are set, we can open the audio and
  242.      //   video codecs and allocate the necessary encode buffers */
  243. @@ -533,7 +533,7 @@ bool VideoRecorder::init(const std::string& filename, unsigned int framerate, un
  244.      // open the output file, if needed
  245.      if (!(pFormat->flags & AVFMT_NOFILE))
  246.      {
  247. -        if (url_fopen(&pFormatContext->pb, filename.c_str(), URL_WRONLY) < 0)
  248. +        if (avio_open(&pFormatContext->pb, filename.c_str(), AVIO_FLAG_WRITE) < 0)
  249.          {
  250.              std::cerr <<"Could not open '%s'" << std::endl;
  251.              return false;
  252. @@ -541,7 +541,7 @@ bool VideoRecorder::init(const std::string& filename, unsigned int framerate, un
  253.      }
  254.  
  255.      // write the stream header, if any
  256. -    av_write_header(pFormatContext);
  257. +    avformat_write_header(pFormatContext,NULL);
  258.  
  259.      std::cout << "Start Recording in " << filename << std::endl;
  260.      //everything is ok
  261. @@ -563,7 +563,7 @@ void VideoRecorder::finishVideo()
  262.      av_write_trailer(pFormatContext);
  263.  
  264.      //Dump to stdout
  265. -    dump_format(pFormatContext, 0, p_filename.c_str(), 1);
  266. +    av_dump_format(pFormatContext, 0, p_filename.c_str(), 1);
  267.  
  268.      // close each codec
  269.      if (pVideoStream)
  270. @@ -579,7 +579,7 @@ void VideoRecorder::finishVideo()
  271.      if (!(pFormat->flags & AVFMT_NOFILE))
  272.      {
  273.          // close the output file
  274. -        url_fclose(pFormatContext->pb);
  275. +        avio_close(pFormatContext->pb);
  276.      }
  277.  
  278.      // free the stream
  279. diff --git a/framework/sofa/helper/gl/VideoRecorder.h b/framework/sofa/helper/gl/VideoRecorder.h
  280. index 4c638c4..56278b8 100644
  281. --- a/framework/sofa/helper/gl/VideoRecorder.h
  282. +++ b/framework/sofa/helper/gl/VideoRecorder.h
  283. @@ -95,7 +95,7 @@ public:
  284.      std::string findFilename(const std::string &v);
  285.  
  286.  protected:
  287. -    AVStream *add_video_stream(AVFormatContext *oc, CodecID codec_id, const std::string& codec="");
  288. +    AVStream *add_video_stream(AVFormatContext *oc, AVCodecID codec_id, const std::string& codec="");
  289.      bool open_video(AVFormatContext *oc, AVStream *st);
  290.      AVFrame *alloc_picture(PixelFormat pix_fmt, int width, int height);
  291.      bool write_video_frame(AVFormatContext *oc, AVStream *st);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement