Error in building opencv with ffmpeg
Solution 1
My solution is to grep the missing defines (2 in total) from FFmpeg by using grep -r which leads to the following code found in 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
Copy and paste it to the top of:
opencv-3.3.0/modules/videoio/src/cap_ffmpeg_impl.hpp
Compile and everything works even with the latest sources
Solution 2
Easiest change for the CODEC_FLAG_GLOBAL_HEADER is to change it to AV_CODEC_FLAG_GLOBAL_HEADER, it was redefined in a newer version.
Note the "AV_" in front
Solution 3
in opencv:0/2.4 there is no modules/videoio directory! to get that old version (2.4.13-r3) to compile with newest media-video/ffmpeg on gentoo (4.1.3) I had to add above changes to modules/highgui/src/cap_ffmpeg_api.hpp with this patch:
--- 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,
(i.e. I created the path and file /etc/portage/patches/media-libs/opencv-2.4.13-r3/old-ffmpeg.patch with that contents.) in defense to gentoo, I should mention, the new media-libs/opencv:0/3.4.1 is also available, as is the old media-video/ffmpeg-3.4.5, so I could alternatively also play around with masking out versions or file a bug for developers to do that for me...
Related videos on Youtube
batuman
Updated on July 09, 2022Comments
-
batuman almost 2 years
I installed ffmpeg according to this article. ffmpeg installation was ok. Now I build opencv with ffmpeg support and I have some errors. The errors are
/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
What could be wrong?
-
Anonymous over 6 yearsSame issues with Ubuntu 16.04, ffmpeg from github and opencv 3.3.0.
-
batuman over 6 years@Anonymous yes mine Ubuntu 16.04 and opencv 2.4.13.4. How to solve issue?
-
batuman over 6 yearsThat is the version conflict. OpenCV hasn't updated to match ffmpeg's latest version. I changed to earlier version of ffmpeg from this link (ffmpeg.org/releases) and compiled with --enable-shared flag, now is ok.
-
-
Mark almost 6 yearsWorks for opencv 3.2 as well.
-
Phil almost 6 yearsI also needed this for opencv 3.4 on ubuntu 16.
-
yaobin about 4 yearsThis may work around the compile error but may introduce a new problem. You need to check if the definition of
AVFMT_RAWPICTURE 0x0020
makes sense in theOpenCV
code you are building. But if thisvideoio
module is not at all your focus, it should be fine to work around the compile error this way. -
Arjun Kumar over 2 yearsworks for OpenCV 3.2 on raspi 3+