Compiling OpenCV with ffmpeg GPU support
i am trying to get FFMPEG to use GPU to improve the speed of my program. I got FFMPEG from cloning https://git.ffmpeg.org/ffmpeg.git and followed the steps here https://developer.nvidia.com/ffmpeg to get it working.
I am building opencv 3.1.0 by cloning, git clone https://github.com/opencv/opencv.git and using git checkout -b v3.1.0 3.1.0. I also had to cherry pick some git commits to make this working properly.
When I bulid Opencv; -- Video I/O: -- DC1394 1.x: NO -- DC1394 2.x: NO -- FFMPEG: YES -- codec: YES (ver 58.20.103) -- format: YES (ver 58.17.100) -- util: YES (ver 56.18.102) -- swscale: YES (ver 5.2.100) -- resample: NO -- gentoo-style: YES
When I run ffmpeg on the terminal:
ffmpeg version N-91329-g830695b Copyright (c) 2000-2018 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609 configuration: --enable-cuda --enable-cuvid --enable-nvenc --enable-nonfree --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-ldflags=-L/usr/local/cuda/lib64 libavutil 56. 18.102 / 56. 18.102 libavcodec 58. 20.103 / 58. 20.103 libavformat 58. 17.100 / 58. 17.100 libavdevice 58. 4.101 / 58. 4.101 libavfilter 7. 25.100 / 7. 25.100 libswscale 5. 2.100 / 5. 2.100 libswresample 3. 2.100 / 3. 2.100
However, when I run make -j15, I get an error:
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1313:21: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
^
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1337:30: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
if (oc->oformat->flags & AVFMT_RAWPICTURE) {
^
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘void CvVideoWriter_FFMPEG::close()’:
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1525:35: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
if( (oc->oformat->flags & AVFMT_RAWPICTURE) == 0 )
^
In file included from /home/jio/opencv/modules/videoio/src/cap_ffmpeg.cpp:45:0:
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool CvVideoWriter_FFMPEG::open(const char*, int, double, int, int, bool)’:
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:1825:32: error: ‘AVFMT_RAWPICTURE’ was not declared in this scope
if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) {
^
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp: In static member function ‘static AVStream* OutputMediaStream_FFMPEG::addVideoStream(AVFormatContext*, AVCodecID, int, int, int, double, AVPixelFormat)’:
/home/jio/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:2124:25: error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
Any help would be greatly appreciated.
mismatched ffmpeg version (opencv does not support latest)
https://stackoverflow.com/questions/4...
Thanks for the help! I solved the compilation errors, and was able to do
sudo make install
however I don't know how to validate the installation. I was checking by runningwatch nvidia-smi
and checking if ffmpeg was using GPU, however I think there is a better way.