opencv3.2编译报错icv_add_video_stream_FFMPEG

原文:https://blog.csdn.net/guo_lei_lamant/article/details/81568346
opencv3.2编译报错:

[ 51%] Built target opencv_photo
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_images.cpp.o
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap.cpp.o
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_mjpeg_encoder.cpp.o
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_mjpeg_decoder.cpp.o
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_dc1394_v2.cpp.o
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_v4l.cpp.o
[ 51%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o
In file included from /home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg.cpp:47:0:
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘AVStream* icv_add_video_stream_FFMPEG(AVFormatContext*, AVCodecID, int, int, int, double, int):
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1541:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
         c->flags |= CODEC_FLAG_GLOBAL_HEADER;
                     ^
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*):
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1569:30: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
     if (oc->oformat->flags & AVFMT_RAWPICTURE) {
                              ^
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close():
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp:1743:35: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
         if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 )
                                   ^
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool):
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp:2039:32: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
     if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
                                ^
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp: In static member function ‘static AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext*, AVCodecID, int, int, int, double, AVPixelFormat):
/home/yk/opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp:2338:25: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
             c->flags |= CODEC_FLAG_GLOBAL_HEADER;
                         ^
modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:206: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o' failed
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1
make[2]: *** 正在等待未完成的任务....
CMakeFiles/Makefile2:4045: recipe for target 'modules/videoio/CMakeFiles/opencv_videoio.dir/all' failed
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

解决方法:
opencv-3.2.0/modules/videoio/src/cap_ffmpeg_impl.hpp 里最顶端添加了:

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

你可能感兴趣的:(OpenCV)