Not able to read Video from Capture Card with GPU (Unsupported Format) while Reading with CPU works fine

Hello all,

First of all, i am new to the Open CV World and just started a few weeks ago. I tried to solve this error by reading questions to similar problems, but until now, i couldn’t fix it.
Context:
I am working with a stereo webcam, which has two HDMI video signals as output. These signals are captured by a Video Capture Card (see Hardware). I am trying to access one (for now at least) of the input signals with Open CV.
When using the Open CV examples from GitHub, the video signal can be accessed by CPU functions and can be shown in a window in real time. So there is a video signal coming from the capture card.

Problem:
But for performance reasons, i have to use the GPU. When using the GPU Examples from GitHub, I get an Unsupported Format Error message for the following line:

cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);
$ ./run /dev/video0
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.6.0-dev) /home/nvidiapc/openCV/opencv_contrib/modules/cudacodec/src/cuvid_video_source.cpp:65: error: (-210:Unsupported format or combination of formats) Unsupported video source in function 'CuvidVideoSource'

Aborted (core dumped)

My Capture Card uses /dev/video0 and /dev/video1 for the two input signals.
ffprobe gives me the following output for /dev/video0:

$ ffprobe -loglevel error -show_entries stream=pix_fmt -of csv=p=0 /dev/video0
yuv420p

And v4l2 the following information:

$ sudo v4l2-ctl --device=/dev/video0 --all
Driver Info:
	Driver name      : Pro Capture
	Card type        : 00-01 Pro Capture Dual HDMI 4K+
	Bus info         : PCI:0000:07:00.0
	Driver version   : 5.17.3
	Capabilities     : 0x84200001
		Video Capture
		Streaming
		Extended Pix Format
		Device Capabilities
	Device Caps      : 0x04200001
		Video Capture
		Streaming
		Extended Pix Format
Priority: 0
Video input : 0 (Auto: ok)
Format Video Capture:
	Width/Height      : 1920/1080
	Pixel Format      : 'YUYV' (YUYV 4:2:2)
	Field             : None
	Bytes per Line    : 3840
	Size Image        : 4147200
	Colorspace        : Default
	Transfer Function : Default (maps to Rec. 709)
	YCbCr/HSV Encoding: Default (maps to ITU-R 601)
	Quantization      : Default (maps to Limited Range)
	Flags             : 
Streaming Parameters Video Capture:
	Capabilities     : timeperframe
	Frames per second: 50.000 (10000000/200001)
	Read buffers     : 0
                     brightness 0x00980900 (int)    : min=-100 max=100 step=1 default=0 value=0 flags=slider
                       contrast 0x00980901 (int)    : min=50 max=200 step=1 default=100 value=100 flags=slider
                     saturation 0x00980902 (int)    : min=0 max=200 step=1 default=100 value=100 flags=slider
                            hue 0x00980903 (int)    : min=-90 max=90 step=1 default=0 value=0 flags=slider

My Question:
Do you have any ideas how i can make this work? Is there something i am missing?
Also let me know if you need some additional information aswell! Thank you in advance!

System:
Ubuntu 22.04 LTS
OpenCV(4.6.0-dev)
Cuda 11.7

Hardware:
Graphics: Nvidia RTX 3070 TI
Video Capture Card: Magewell Pro Capture Dual HDMI 4K Plus LT

Full Code:

#include <iostream>
#include "opencv2/opencv_modules.hpp"
#if defined(HAVE_OPENCV_CUDACODEC)

#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

#include <opencv2/core.hpp>
#include <opencv2/core/opengl.hpp>
#include <opencv2/cudacodec.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <opencv2/imgproc.hpp>

int main(int argc, const char* argv[])
{
    if (argc != 2) {
        std::cout << "You need to use the program like this..." << std::endl;
        return -1;
    }

    const std::string fname(argv[1]);
    cv::namedWindow("CPU", cv::WINDOW_NORMAL);
    cv::namedWindow("GPU", cv::WINDOW_OPENGL);
    cv::cuda::setGlDevice();

    cv::Mat frame;
    cv::VideoCapture reader(fname);

    cv::cuda::GpuMat d_frame;
    cv::Ptr<cv::cudacodec::VideoReader> d_reader = cv::cudacodec::createVideoReader(fname);

    cv::TickMeter tm;
    std::vector<double> cpu_times;
    std::vector<double> gpu_times;

    int gpu_frame_count=0, cpu_frame_count=0;

    for (;;)
    {
        tm.reset(); tm.start();
        if (!reader.read(frame))
            break;
        tm.stop();
        cpu_times.push_back(tm.getTimeMilli());
        cpu_frame_count++;

        cv::imshow("CPU", frame);
        waitKey(3);
        if (cv::waitKey(3) > 0)
            break;
    }


    for (;;)
    {
        tm.reset(); tm.start();
        if (!d_reader->nextFrame(d_frame))
            break;
        tm.stop();
        gpu_times.push_back(tm.getTimeMilli());
        gpu_frame_count++;

        cv::imshow("GPU", d_frame);

        if (cv::waitKey(3) > 0)
            break;
    }

    if (!cpu_times.empty() && !gpu_times.empty())
    {
        std::cout << std::endl << "Results:" << std::endl;

        std::sort(cpu_times.begin(), cpu_times.end());
        std::sort(gpu_times.begin(), gpu_times.end());

        double cpu_avg = std::accumulate(cpu_times.begin(), cpu_times.end(), 0.0) / cpu_times.size();
        double gpu_avg = std::accumulate(gpu_times.begin(), gpu_times.end(), 0.0) / gpu_times.size();

        std::cout << "CPU : Avg : " << cpu_avg << " ms FPS : " << 1000.0 / cpu_avg << " Frames " << cpu_frame_count << std::endl;
        std::cout << "GPU : Avg : " << gpu_avg << " ms FPS : " << 1000.0 / gpu_avg << " Frames " << gpu_frame_count << std::endl;
    }

    return 0;
}

#else

int main()
{
    std::cout << "OpenCV was built without CUDA Video decoding support\n" << std::endl;
    return 0;
}

#endif
1 Like

cv::cuda::VideoReader uses the FFMPEG backend so if you can’t use cv::VideoCapture(src, CAP_FFMPEG) then it won’t work with cv::cuda::VideoReader.

That said I did manage to get the FFMPEG backend to work with direct show

you may be able to follow a similar procedure with V4L2 devices on linux but I coudn’t guarantee it. An alternative would be to write your own parser to read the raw input from your stereo cams by inheriting from cv::cudacodec::RawVideoSource.

Thank you for your answer.
I did a comparison within the Code that actually is functioning. Opening the camera like this works:

cv::VideoCapture camL(0, cv::CAP_V4L2), camR(1, cv::CAP_V4L2);

While opening the camera like this failed (camL.isOpen() and camR.isOpen() return false):

cv::VideoCapture camL(0, cv::CAP_FFMPEG), camR(1, cv::CAP_FFMPEG);

So there is something not working with FFMPEG. I will definitely try your linked suggestion and report on my progress.

Thanks again for your answer.
I looked up the cudacodec::RawVideoSource and have to say, that’s above what I have the ability to implement.
About the linked Thread: Should this even work on Ubuntu? For what I know you can only use direct show on Windows?

It definitely won’t work with directshow, but you can try it with V4L2 see the FFMpeg docs. I don’t know if this will work but you can give it a shot and instead of

you could try

OPENCV_FFMPEG_CAPTURE_OPTIONS=input_format;v4l2

Thanks again, but unfortunately i couldn’t even build the changes you made to the source files. When building i get a ton of undefined reference to:

...
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_mjpeg_encoder.cpp.o
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_mjpeg_decoder.cpp.o
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/backend_plugin.cpp.o
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/backend_static.cpp.o
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/container_avi.cpp.o
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_v4l.cpp.o
[ 13%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o
[ 13%] Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_create_derived_context(AVHWDeviceType, AVBufferRef*)::FreeChildContext::free(AVHWDeviceContext*)':
cap_ffmpeg.cpp:(.text._ZZL25hw_create_derived_context14AVHWDeviceTypeP11AVBufferRefEN16FreeChildContext4freeEP17AVHWDeviceContext+0x27): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `InternalFFMpegRegister::~InternalFFMpegRegister()':
cap_ffmpeg.cpp:(.text._ZN22InternalFFMpegRegisterD2Ev[_ZN22InternalFFMpegRegisterD5Ev]+0xb): undefined reference to `av_log_set_callback(void (*)(void*, int, char const*, __va_list_tag*))'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `ffmpeg_log_callback(void*, int, char const*, __va_list_tag*)':
cap_ffmpeg.cpp:(.text._ZL19ffmpeg_log_callbackPviPKcP13__va_list_tag+0x11): undefined reference to `av_log_get_level()'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::init()':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4initEv+0x10): undefined reference to `avdevice_register_all()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4initEv+0xd0): undefined reference to `av_init_packet(AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4initEv+0x171): undefined reference to `av_init_packet(AVPacket*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::close()':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0x30): undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0x4e): undefined reference to `avformat_close_input(AVFormatContext**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0x5f): undefined reference to `av_frame_unref(AVFrame*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0x75): undefined reference to `av_packet_unref(AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0x96): undefined reference to `av_dict_free(AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0xac): undefined reference to `av_packet_unref(AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG5closeEv+0xcd): undefined reference to `av_bsf_free(AVBSFContext**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::processRawPacket()':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0x70): undefined reference to `av_packet_unref(AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0x83): undefined reference to `av_bsf_send_packet(AVBSFContext*, AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0x9a): undefined reference to `av_bsf_receive_packet(AVBSFContext*, AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0xde): undefined reference to `av_bsf_get_by_name(char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0xf2): undefined reference to `av_bsf_alloc(AVBitStreamFilter const*, AVBSFContext**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0x142): undefined reference to `avcodec_parameters_copy(AVCodecParameters*, AVCodecParameters const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG16processRawPacketEv+0x14e): undefined reference to `av_bsf_init(AVBSFContext*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::grabFrame() [clone .part.0]':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG9grabFrameEv.part.0+0x3e): undefined reference to `avcodec_receive_frame(AVCodecContext*, AVFrame*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG9grabFrameEv.part.0+0x58): undefined reference to `av_packet_unref(AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG9grabFrameEv.part.0+0x6d): undefined reference to `av_read_frame(AVFormatContext*, AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG9grabFrameEv.part.0+0x94): undefined reference to `av_packet_unref(AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG9grabFrameEv.part.0+0xe7): undefined reference to `avcodec_send_packet(AVCodecContext*, AVPacket const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG9grabFrameEv.part.0+0xf8): undefined reference to `avcodec_receive_frame(AVCodecContext*, AVFrame*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::getProperty(int) const':
cap_ffmpeg.cpp:(.text._ZNK16CvCapture_FFMPEG11getPropertyEi+0x198): undefined reference to `avcodec_get_name(AVCodecID)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZNK16CvCapture_FFMPEG11getPropertyEi+0x25c): undefined reference to `av_guess_sample_aspect_ratio(AVFormatContext*, AVStream*, AVFrame*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZNK16CvCapture_FFMPEG11getPropertyEi+0x281): undefined reference to `av_guess_sample_aspect_ratio(AVFormatContext*, AVStream*, AVFrame*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZNK16CvCapture_FFMPEG11getPropertyEi+0x2a1): undefined reference to `avcodec_pix_fmt_to_codec_tag(AVPixelFormat)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::seek(long)':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4seekEl+0xcd): undefined reference to `av_seek_frame(AVFormatContext*, int, long, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4seekEl+0xd6): undefined reference to `avcodec_flush_buffers(AVCodecContext*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_create_frames(AVCodecContext*, AVBufferRef*, int, int, AVPixelFormat)':
cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0xb1): undefined reference to `avcodec_get_hw_frames_parameters(AVCodecContext*, AVBufferRef*, AVPixelFormat, AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x105): undefined reference to `av_hwframe_ctx_init(AVBufferRef*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x13b): undefined reference to `av_hwframe_ctx_create_derived(AVBufferRef**, AVPixelFormat, AVBufferRef*, AVBufferRef*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x147): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x19c): undefined reference to `av_hwframe_ctx_init(AVBufferRef*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x50e): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x524): undefined reference to `av_hwframe_ctx_alloc(AVBufferRef*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x73f): undefined reference to `av_hwdevice_get_hwframe_constraints(AVBufferRef*, void const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_framesP14AVCodecContextP11AVBufferRefii13AVPixelFormat+0x75c): undefined reference to `av_hwframe_constraints_free(AVHWFramesConstraints**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_get_format_callback(AVCodecContext*, AVPixelFormat const*)':
cap_ffmpeg.cpp:(.text._ZL22hw_get_format_callbackP14AVCodecContextPK13AVPixelFormat+0xa4): undefined reference to `avcodec_get_hw_config(AVCodec const*, int)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_check_codec(AVCodec*, AVHWDeviceType, char const*)':
cap_ffmpeg.cpp:(.text._ZL14hw_check_codecP7AVCodec14AVHWDeviceTypePKc+0x3e): undefined reference to `av_hwdevice_get_type_name(AVHWDeviceType)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_find_codec(AVCodecID, AVHWDeviceType, int (*)(AVCodec const*), char const*, AVPixelFormat*)':
cap_ffmpeg.cpp:(.text._ZL13hw_find_codec9AVCodecID14AVHWDeviceTypePFiPK7AVCodecEPKcP13AVPixelFormat+0x44): undefined reference to `av_codec_iterate(void**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL13hw_find_codec9AVCodecID14AVHWDeviceTypePFiPK7AVCodecEPKcP13AVPixelFormat+0x7d): undefined reference to `av_codec_is_encoder(AVCodec const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL13hw_find_codec9AVCodecID14AVHWDeviceTypePFiPK7AVCodecEPKcP13AVPixelFormat+0x93): undefined reference to `avcodec_get_hw_config(AVCodec const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL13hw_find_codec9AVCodecID14AVHWDeviceTypePFiPK7AVCodecEPKcP13AVPixelFormat+0xe9): undefined reference to `av_codec_is_encoder(AVCodec const*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_create_derived_context(AVHWDeviceType, AVBufferRef*)':
cap_ffmpeg.cpp:(.text._ZL25hw_create_derived_context14AVHWDeviceTypeP11AVBufferRef+0x81): undefined reference to `av_hwdevice_get_type_name(AVHWDeviceType)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25hw_create_derived_context14AVHWDeviceTypeP11AVBufferRef+0x96): undefined reference to `av_hwdevice_ctx_create_derived(AVBufferRef**, AVHWDeviceType, AVBufferRef*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25hw_create_derived_context14AVHWDeviceTypeP11AVBufferRef+0xb4): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25hw_create_derived_context14AVHWDeviceTypeP11AVBufferRef+0x498): undefined reference to `av_buffer_ref(AVBufferRef*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::retrieveFrame(int, unsigned char**, int*, int*, int*, int*)':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG13retrieveFrameEiPPhPiS2_S2_S2_+0x93): undefined reference to `av_frame_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG13retrieveFrameEiPPhPiS2_S2_S2_+0xa6): undefined reference to `av_hwframe_transfer_data(AVFrame*, AVFrame const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG13retrieveFrameEiPPhPiS2_S2_S2_+0x14d): undefined reference to `av_frame_unref(AVFrame*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG13retrieveFrameEiPPhPiS2_S2_S2_+0x16f): undefined reference to `av_frame_get_buffer(AVFrame*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG13retrieveFrameEiPPhPiS2_S2_S2_+0x237): undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, AVCodecContext*, unsigned char*, unsigned int, AVFrame*, int) [clone .constprop.0]':
cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0x8c): undefined reference to `av_packet_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0xa3): undefined reference to `avcodec_receive_packet(AVCodecContext*, AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0xb2): undefined reference to `av_packet_free(AVPacket**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0xf6): undefined reference to `av_packet_rescale_ts(AVPacket*, AVRational, AVRational)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0x103): undefined reference to `av_write_frame(AVFormatContext*, AVPacket*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0x10e): undefined reference to `av_packet_free(AVPacket**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL25icv_av_write_frame_FFMPEGP15AVFormatContextP8AVStreamP14AVCodecContextPhjP7AVFramei.constprop.0+0x127): undefined reference to `avcodec_send_frame(AVCodecContext*, AVFrame const*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvVideoWriter_FFMPEG::writeFrame(unsigned char const*, int, int, int, int, int)':
cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x186): undefined reference to `av_frame_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x1a9): undefined reference to `av_hwframe_get_buffer(AVBufferRef*, AVFrame*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x1c1): undefined reference to `av_hwframe_transfer_data(AVFrame*, AVFrame const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x200): undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x244): undefined reference to `av_freep(void*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x260): undefined reference to `av_mallocz(unsigned long)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG10writeFrameEPKhiiiii+0x525): undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvVideoWriter_FFMPEG::close()':
cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0x71): undefined reference to `av_free(void*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0x7f): undefined reference to `av_free(void*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0x8d): undefined reference to `avcodec_close(AVCodecContext*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0x9e): undefined reference to `av_free(void*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0xb9): undefined reference to `avformat_free_context(AVFormatContext*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0xc2): undefined reference to `av_freep(void*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0x17a): undefined reference to `av_write_trailer(AVFormatContext*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG5closeEv+0x1ad): undefined reference to `avio_close(AVIOContext*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvVideoWriter_FFMPEG::writeHWFrame(cv::_InputArray const&)':
cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG12writeHWFrameERKN2cv11_InputArrayE+0x41): undefined reference to `av_frame_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG12writeHWFrameERKN2cv11_InputArrayE+0x5f): undefined reference to `av_hwframe_get_buffer(AVBufferRef*, AVFrame*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG12writeHWFrameERKN2cv11_InputArrayE+0x7e): undefined reference to `av_frame_free(AVFrame**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `HWAccelIterator::HWAccelIterator(cv::VideoAccelerationType, bool, AVDictionary*)':
cap_ffmpeg.cpp:(.text._ZN15HWAccelIteratorC2EN2cv21VideoAccelerationTypeEbP12AVDictionary[_ZN15HWAccelIteratorC5EN2cv21VideoAccelerationTypeEbP12AVDictionary]+0xb4d): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN15HWAccelIteratorC2EN2cv21VideoAccelerationTypeEbP12AVDictionary[_ZN15HWAccelIteratorC5EN2cv21VideoAccelerationTypeEbP12AVDictionary]+0xcbc): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN15HWAccelIteratorC2EN2cv21VideoAccelerationTypeEbP12AVDictionary[_ZN15HWAccelIteratorC5EN2cv21VideoAccelerationTypeEbP12AVDictionary]+0xd75): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN15HWAccelIteratorC2EN2cv21VideoAccelerationTypeEbP12AVDictionary[_ZN15HWAccelIteratorC5EN2cv21VideoAccelerationTypeEbP12AVDictionary]+0x140e): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `hw_create_device(AVHWDeviceType, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)':
cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x15e): undefined reference to `av_hwdevice_get_type_name(AVHWDeviceType)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x718): undefined reference to `av_hwdevice_get_type_name(AVHWDeviceType)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x748): undefined reference to `av_hwdevice_ctx_create(AVBufferRef**, AVHWDeviceType, char const*, AVDictionary*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x777): undefined reference to `av_hwdevice_get_type_name(AVHWDeviceType)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0xe20): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x144b): undefined reference to `av_hwdevice_get_type_name(AVHWDeviceType)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x146c): undefined reference to `av_buffer_ref(AVBufferRef*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZL16hw_create_device14AVHWDeviceTypeiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x16d6): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::open(char const*, cv::VideoCaptureParameters const&)':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x8a): undefined reference to `av_log_set_level(int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x96): undefined reference to `av_log_set_callback(void (*)(void*, int, char const*, __va_list_tag*))'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x458): undefined reference to `avformat_network_init()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x51f): undefined reference to `av_log_set_level(int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x74b): undefined reference to `avformat_alloc_context()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x79b): undefined reference to `av_dict_parse_string(AVDictionary**, char const*, char const*, char const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x7b2): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x7c3): undefined reference to `av_find_input_format(char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x7d4): undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x7e6): undefined reference to `avformat_find_stream_info(AVFormatContext*, AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x974): undefined reference to `av_strerror(int, char*, unsigned long)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0xbe4): undefined reference to `av_dict_set(AVDictionary**, char const*, char const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x1714): undefined reference to `av_codec_is_decoder(AVCodec const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x1756): undefined reference to `avcodec_default_get_format(AVCodecContext*, AVPixelFormat const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x1773): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x17f7): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x182f): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x1e77): undefined reference to `av_hwdevice_find_type_by_name(char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x1ea0): undefined reference to `av_dict_get(AVDictionary const*, char const*, AVDictionaryEntry const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x20ec): undefined reference to `avcodec_find_decoder_by_name(char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x2338): undefined reference to `avcodec_find_decoder(AVCodecID)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x2a01): undefined reference to `av_frame_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4openEPKcRKN2cv22VideoCaptureParametersE+0x2a59): undefined reference to `av_stream_get_side_data(AVStream const*, AVPacketSideDataType, int*)'
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvVideoWriter_FFMPEG::open(char const*, int, double, int, int, cv::VideoWriterParameters const&)':
cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xa2): undefined reference to `av_log_set_level(int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xae): undefined reference to `av_log_set_callback(void (*)(void*, int, char const*, __va_list_tag*))'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x438): undefined reference to `avformat_network_init()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x5ce): undefined reference to `av_guess_format(char const*, char const*, char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x603): undefined reference to `av_codec_get_id(AVCodecTag const* const*, unsigned int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x663): undefined reference to `avformat_alloc_context()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x6a0): undefined reference to `av_malloc(unsigned long)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x71f): undefined reference to `av_log_set_level(int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x76b): undefined reference to `avformat_new_stream(AVFormatContext*, AVCodec const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x7b4): undefined reference to `av_dict_parse_string(AVDictionary**, char const*, char const*, char const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xa3c): undefined reference to `av_hwdevice_find_type_by_name(char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xa68): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xa81): undefined reference to `av_codec_is_encoder(AVCodec const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xb64): undefined reference to `avcodec_get_context_defaults3(AVCodecContext*, AVCodec const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xcda): undefined reference to `av_sub_q(AVRational, AVRational)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xde5): undefined reference to `av_opt_set(void*, char const*, char const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xe41): undefined reference to `av_buffer_ref(AVBufferRef*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0xee7): undefined reference to `avcodec_open2(AVCodecContext*, AVCodec const*, AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x1200): undefined reference to `av_buffer_unref(AVBufferRef**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x1216): undefined reference to `av_dict_free(AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x1248): undefined reference to `av_malloc(unsigned long)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x1285): undefined reference to `av_frame_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x12ef): undefined reference to `avio_open(AVIOContext**, char const*, int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x1302): undefined reference to `avformat_write_header(AVFormatContext*, AVDictionary**)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x1464): undefined reference to `avcodec_find_encoder(AVCodecID)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x2121): undefined reference to `av_codec_get_tag(AVCodecTag const* const*, AVCodecID)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x2208): undefined reference to `avformat_get_riff_video_tags()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x2214): undefined reference to `avformat_get_mov_video_tags()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x222a): undefined reference to `av_codec_get_id(AVCodecTag const* const*, unsigned int)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x2282): undefined reference to `avcodec_descriptor_get_by_name(char const*)'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x250f): undefined reference to `av_frame_alloc()'
/usr/bin/ld: cap_ffmpeg.cpp:(.text._ZN20CvVideoWriter_FFMPEG4openEPKcidiiRKN2cv21VideoWriterParametersE+0x254b): undefined reference to `av_free(void*)'
collect2: error: ld returned 1 exit status
gmake[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:267: lib/libopencv_videoio.so.4.6.0] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:6227: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
gmake: *** [Makefile:166: all] Error 2

Full Output

Can you build it successfully without the two changes? If so I think you may be missing libavdevice-dev?

I double checked on this today: Without the changes it builds successfully, however libavdevice-dev is installed. Even after

$ sudo apt-get libavdevice-dev 
$ source ~/.profile

the undefined reference to messages during make install remain.

Sorry I can’t advise futher, all I can tell you is that it compiles and works on Windows with directshow so I had hoped it would work with v4l2 as well.

The errors may be caused by the position of the header in the file. I have it here

That said, even if it compiles it still may not work.

1 Like

Thank you for your advice. It was worth trying.

Did you try moving the position of the header?

Yes, i moved the header to line 95, under #include <libswscale/swscale.h>.
However there are still errors regarding avdevice_register_all();:

/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::init()':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4initEv+0x10): undefined reference to `avdevice_register_all'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:267: lib/libopencv_videoio.so.4.6.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:6227: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

Ahh yes I must have manually added the library.

You need to alter the cmake script to add libavdevice. I don’t have time to check but you could try adding libavdevice to the below

Sorry @cudawarped, I didn’t have time to test this until today.

But unfortunately there remains the same (?) error during sudo make install:

[ 13%] Linking CXX shared library ../../lib/libopencv_videoio.so
/usr/bin/ld: CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o: in function `CvCapture_FFMPEG::init()':
cap_ffmpeg.cpp:(.text._ZN16CvCapture_FFMPEG4initEv+0x10): undefined reference to `avdevice_register_all'
collect2: error: ld returned 1 exit status
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:267: lib/libopencv_videoio.so.4.6.0] Error 1
make[1]: *** [CMakeFiles/Makefile2:6227: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

Is there maybe something wrong how I wrote these extra statements into the Source Code?

Changes to Source files I made

detect_ffmpeg.cmake:

...
22 set(_required_ffmpeg_libraries libavcodec libavformat libavutil libswscale libavdevice)
23 set(_used_ffmpeg_libraries ${_required_ffmpeg_libraries})
...

cap_ffmpeg_impl.hpp

...
94 #include <libavdevice/avdevice.h>
...
625 void CvCapture_FFMPEG::init()
626 {
627     avdevice_register_all(); // <---
...

I’ve tried this on WSL. If you also add libavdevice a to ocv_check_modules as below then it should compile without any errors.

set(_required_ffmpeg_libraries libavcodec libavformat libavutil libswscale libavdevice)
set(_used_ffmpeg_libraries ${_required_ffmpeg_libraries})
if(NOT HAVE_FFMPEG AND PKG_CONFIG_FOUND)
  ocv_check_modules(FFMPEG libavcodec libavformat libavutil libswscale libavdevice)

What I can’t test as WSL doesn’t have drivers to access the webcam is what happens when you set
OPENCV_FFMPEG_CAPTURE_OPTIONS=input_format;v4l2
and open the camera as
VideoCapture cap("/dev/video0", CAP_FFMPEG);
or similar depending on how you access your camera.

Thanks, I did change the files accordingly. The build process went without errors. Then I set OPENCV_FFMPEG_CAPTURE_OPTIONS like this:

setenv("OPENCV_FFMPEG_CAPTURE_OPTIONS", "input_format;v4l2", 1);

and accessed the camera like this:

cv::VideoCapture d_reader(fname, cv::VideoCaptureAPIs::CAP_FFMPEG);

then unfortunately I got the following error message:

$./run /dev/video0
[video4linux2,v4l2 @ 0x564b8b62c380] No such input format: v4l2.

Did I set it correctly or does this mean the way fixing ffmpeg under Windows you suggested can’t be transferred to Ubuntu?

I could not say for sure without testing myself, there may be other arguments which need to be set, have you tried stepping through CvCapture_FFMPEG::open() to see which FFmpeg call fails and what the error code is?
Is your webcam /dev/video0? You should be able to test it with

ffmpeg -f v4l2 -i /dev/video0

or similar.

I am not quite sure how to do that, but I can provide you the Debug Log:

Debug Log
$ ./run /dev/video0
[DEBUG:0@0.000] global /home/nvidiapc/openCV/opencv/modules/highgui/src/backend.cpp (120) createDefaultUIBackend UI: Initializing backend...
[DEBUG:0@0.000] global /home/nvidiapc/openCV/opencv/modules/highgui/src/registry.impl.hpp (87) UIBackendRegistry UI: Builtin backends(3): GTK(1000); GTK3(990); GTK2(980) + BUILTIN(QT5)
[DEBUG:0@0.000] global /home/nvidiapc/openCV/opencv/modules/highgui/src/registry.impl.hpp (112) UIBackendRegistry UI: Available backends(3): GTK(1000); GTK3(990); GTK2(980) + BUILTIN(QT5)
[ INFO:0@0.000] global /home/nvidiapc/openCV/opencv/modules/highgui/src/registry.impl.hpp (114) UIBackendRegistry UI: Enabled backends(3, sorted by priority): GTK(1000); GTK3(990); GTK2(980) + BUILTIN(QT5)
[DEBUG:0@0.000] global /home/nvidiapc/openCV/opencv/modules/highgui/src/backend.cpp (78) createUIBackend UI: trying backend: GTK (priority=1000)
[DEBUG:0@0.000] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (220) getPluginCandidates UI: GTK plugin's glob is 'libopencv_highgui_gtk*.so', 1 location(s)
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (230) getPluginCandidates     - /usr/local/lib: 0
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (234) getPluginCandidates Found 0 plugin(s) for GTK
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/backend.cpp (78) createUIBackend UI: trying backend: GTK3 (priority=990)
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (220) getPluginCandidates UI: GTK3 plugin's glob is 'libopencv_highgui_gtk3*.so', 1 location(s)
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (230) getPluginCandidates     - /usr/local/lib: 0
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (234) getPluginCandidates Found 0 plugin(s) for GTK3
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/backend.cpp (78) createUIBackend UI: trying backend: GTK2 (priority=980)
[DEBUG:0@0.001] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (220) getPluginCandidates UI: GTK2 plugin's glob is 'libopencv_highgui_gtk2*.so', 1 location(s)
[DEBUG:0@0.002] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (230) getPluginCandidates     - /usr/local/lib: 0
[DEBUG:0@0.002] global /home/nvidiapc/openCV/opencv/modules/highgui/src/plugin_wrapper.impl.hpp (234) getPluginCandidates Found 0 plugin(s) for GTK2
[DEBUG:0@0.002] global /home/nvidiapc/openCV/opencv/modules/highgui/src/backend.cpp (106) createUIBackend UI: fallback on builtin code: QT5
[DEBUG:0@0.146] global /home/nvidiapc/openCV/opencv/modules/videoio/src/videoio_registry.cpp (197) VideoBackendRegistry VIDEOIO: Builtin backends(7): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940)
[DEBUG:0@0.146] global /home/nvidiapc/openCV/opencv/modules/videoio/src/videoio_registry.cpp (221) VideoBackendRegistry VIDEOIO: Available backends(7): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940)
[ INFO:0@0.146] global /home/nvidiapc/openCV/opencv/modules/videoio/src/videoio_registry.cpp (223) VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); UEYE(940)
[video4linux2,v4l2 @ 0x5605da05dd40] No such input format: v4l2.

Yes, I was able to access the Webcam with cv::VideoCapture("/dev/video0") before.

I’d say that’s as far as we can go then without stepping through the code to see where the error is, sorry.

Hello @cudawarped,
i copied my project to Windows to try out your original solution for using ffmpeg with dshow:

Build

OS: Windows 10 Pro (21H2)
OpenCV: 4.6.0
Cuda: 11.7

CMake Config
General configuration for OpenCV 4.6.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            C:/Users/NvidiaPC/OpenCV/opencv_contrib-4.6.0/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2022-08-11T11:28:03Z
    Host:                        Windows 10.0.19044 AMD64
    CMake:                       3.24.0-rc5
    CMake generator:             Visual Studio 17 2022
    CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
    MSVC:                        1932
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (18 files):         + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (33 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe  (ver 19.32.31332.0)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MD /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP  /MDd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.32.31326/bin/Hostx64/x64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /MP   /MD /O2 /Ob2 /DNDEBUG 
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:fast     /MP /MDd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO 
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL 
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    -
    Disabled by dependency:      -
    Unavailable:                 alphamat cvv freetype hdf java julia matlab ovis python2 python3 sfm viz
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI: 
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.12)
    JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.2.0)
    JPEG 2000:                   build (ver 2.4.0)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      YES

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/Users/NvidiaPC/OpenCV/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/Users/NvidiaPC/OpenCV/build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)

  NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             86
    NVIDIA PTX archs:

  cuDNN:                         NO

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/Users/NvidiaPC/OpenCV/opencv-4.6.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            NO

  Java:                          
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    C:/Users/NvidiaPC/OpenCV/build/install
-----------------------------------------------------------------

Configuring done
Generating done

Unfortunately it does not work on first try:

cv::VideoCapture cam(0, cv::VideoCaptureAPIs::CAP_FFMPEG);

leads to the following error message:

Error Message:

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.6.0) Error: Assertion failed (size.width>0 && size.height>0) in cv::imshow, file ...\OpenCV\opencv-4.6.0\modules\highgui\src\window.cpp, line 967