'This is the second parameter question of avformat_open_input() of libavformat

I have a plan to import real-time video/audio images from two cameras on a Windows PC, and then use FFMPEG's av_image_fill_arrays() function to combine the two images into one Rect for streaming.

As shown in the image below, we are also considering synchronizing the two cameras.

[enter image description here][1] [1]: https://i.stack.imgur.com/AqEGm.png

But before that, avformat_open_input() I do not know how to use this function.

AVFormatContext     *inputContext = nullptr;
AVInputFormat       *inputFormat = av_find_input_format("dshow"); // linux -> v412
AVDictionary        *options = nullptr;

char temp[128] = {0x00,};
snprintf(temp, 127, "video_size=1920x1080;pixel_format=yuyv422;framerate=30;");
av_dict_parse_string(&options, str_tmp, "=", ";", 0);

if (ret = avformat_open_input(&m_InputContext, "video=@device_pnp_\\\\?\\usb#vid_1bcf&pid_2c99&mi_00#8&3ea22a0&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global", inputFormat, &options) != 0)
{
    // exception
    av_dict_free(&options);
    std::cerr << "avformat_open_input() error: " << str_tmp << std::endl;
    return -1;
}

The value entered in the second parameter is an alternative name that can be obtained when the following command is entered in cmd.(Added escape character)

ffmpeg -list_devices true -f dshow -i dummy

What method should I use to get camera control in ffmpeg?



Solution 1:[1]

It looks like you have to call avdevice_register_all().

In my machine, the following code works (with different device name):

avdevice_register_all();

AVFormatContext     *inputContext = avformat_alloc_context();
AVInputFormat       *inputFormat = av_find_input_format("dshow");
AVDictionary        *options = nullptr;

int ret;

if (ret = avformat_open_input(&inputContext, "video=@device_pnp_\\\\?\\usb#vid_1bcf&pid_2c99&mi_00#8&3ea22a0&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\\global", inputFormat, &options) != 0)
{
    // exception
    av_dict_free(&options);
    std::cerr << "avformat_open_input() error: " << std::endl;
    return -1;
}

In case it's not working, try testing it using FFplay (command line tool):

ffplay -f dshow -i "video=@device_pnp_\\?\usb#vid_1bcf&pid_2c99&mi_00#8&3ea22a0&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rotem