繁体   English   中英

使用 ffmpeg 构建 opencv 时出错

[英]Error in building opencv with ffmpeg

我根据这篇文章安装了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

可能有什么问题?

我的解决方案是使用grep -r从 FFmpeg 中 grep 缺失的定义(总共 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

编译,即使使用最新源,一切都可以正常工作

CODEC_FLAG_GLOBAL_HEADER 最简单的更改是将其更改为 AV_CODEC_FLAG_GLOBAL_HEADER,它在较新的版本中重新定义。

注意前面的“AV_”

在 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,我应该提到,新媒体- libs/opencv:0/3.4.1 也可用,旧的 media-video/ffmpeg-3.4.5 也是如此,所以我也可以尝试屏蔽版本或提交错误让开发人员为我做这件事。 ..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM