我计划从Windows上的两个摄像头中导入实时的视频/音频图像,然后使用FFMPEG的av_image_fill_arrays()函数将这两个图像合并成一个Rect进行流传输。
如下图所示,我们也在考虑同步这两个摄像机。
在这里输入图像描述1:https://i.stack.imgur.com/AqEGm.png
但是在此之前,avformat_open_input()我不知道如何使用这个函数。
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;
}
在第二个参数中输入的值是在cmd中输入以下命令时可以获得的另一个名称。(添加转义字符)
ffmpeg -list_devices true -f dshow -i dummy
我应该用什么方法来获得相机的控制?
发布于 2022-03-12 22:21:54
看来你得给avdevice_register_all()
打电话了。
在我的机器中,以下代码工作(具有不同的设备名称):
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;
}
如果它不起作用,尝试使用FFplay (命令行工具)来测试它:
ffplay -f dshow -i "video=@device_pnp_\\?\usb#vid_1bcf&pid_2c99&mi_00#8&3ea22a0&0&0000#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global"
https://stackoverflow.com/questions/71447538
复制相似问题