使用ffmpeg构建opencv时出错

时间:2017-10-23 08:13:21

标签: c++ opencv ffmpeg

我根据此article安装了ffmpeg。 ffmpeg安装还可以。 现在我用ffmpeg支持构建opencv,我有一些错误。 错误是

/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp:1484:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
         c->flags |= CODEC_FLAG_GLOBAL_HEADER;
                     ^
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp:1512:30: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
     if (oc->oformat->flags & AVFMT_RAWPICTURE) {
                              ^
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp:1686:35: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
         if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 )
                                   ^
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp:1920:32: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
     if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
                                ^
In file included from /home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp: In static member function ‘static AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext*, AVCodecID, int, int, int, double, AVPixelFormat)’:
/home/coie/Softwares/Libraries/opencv-2.4.13.3/modules/highgui/src/cap_ffmpeg_impl.hpp:2214:25: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
             c->flags |= CODEC_FLAG_GLOBAL_HEADER;
                         ^
modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:230: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o' failed
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
CMakeFiles/Makefile2:2349: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed

可能出现什么问题?

3 个答案:

答案 0 :(得分:21)

我的解决方案是使用 grep -r 从FFmpeg中查找缺少的定义(总共2个),这导致在 libavcodec / avcodec.h中找到以下代码

#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020

将其复制并粘贴到顶部:

opencv-3.3.0/modules/videoio/src/cap_ffmpeg_impl.hpp

编译并且即使使用最新的源代码也能正常工作

答案 1 :(得分:2)

CODEC_FLAG_GLOBAL_HEADER的最简单更改是将其更改为AV_CODEC_FLAG_GLOBAL_HEADER,已在较新版本中对其进行了重新定义。

注意前面的“ AV _”

答案 2 :(得分:0)

在opencv:0 / 2.4中没有modules / videoio目录!要获得旧版本(2.4.13-r3)以便在gentoo(4.1.3)上使用最新的media-video / ffmpeg进行编译,我必须在此添加对modules / highgui / src / cap_ffmpeg_api.hpp的更改 补丁:

--- opencv-2.4.13/modules/highgui/src/cap_ffmpeg_api.hpp        2019-05-27 13:28:05.736339890 +0200
+++ opencv-2.4.13-new/modules/highgui/src/cap_ffmpeg_api.hpp    2019-05-27 13:27:48.787198507 +0200
@@ -12,6 +12,10 @@
 #define OPENCV_FFMPEG_API
 #endif

+#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
+#define CODEC_FLAG_GLOBAL_HEADER 
AV_CODEC_FLAG_GLOBAL_HEADER
+#define AVFMT_RAWPICTURE 0x0020
+
 enum
 {
     CV_FFMPEG_CAP_PROP_POS_MSEC=0,

(即,我使用该内容创建了路径和文件/etc/portage/patches/media-libs/opencv-2.4.13-r3/old-ffmpeg.patch。) 在防御gentoo时,我应该提到,新的media-libs / opencv:0 / 3.4.1以及旧的media-video / ffmpeg-3.4.5也是可用的,因此我也可以掩饰一下版本或提交错误以供开发人员替我做...

相关问题