gpt4 book ai didi

c++ - 如何使用 avformat_open_input 函数 (ffmpeg)

转载 作者:行者123 更新时间:2023-11-28 05:50:35 43 4
gpt4 key购买 nike

我买了一台高清HDMI转UVC设备,它有HDMI视频源输入和UVC视频输出here .
我将它从笔记本电脑 A(输入源 HDMI)连接到笔记本电脑 B(输出 USB)。
我在笔记本电脑 B 上安装了 Ubuntu 14.04 桌面,在笔记本电脑 A 上安装了 Win 8.1。
B 还安装了 ffmpeg、opencv 和 sdl 库。
我的目标是通过 B 上的 HD HDMI to UVC 从 A 捕获视频和音频。
所以我决定使用ffmpeg的libav。
我看到了this并使用了 avformat_open_input 函数,但此函数返回了错误。
我以为是因为avformat_open_input的第二个参数(const char * url)不合法导致的。
我知道 url 应该类似于 video:video device name:audio:audio card name
如何指示设备名称?

这是终端中 v4l2-ctl --list-devices 命令的结果。

HD WebCam (usb-0000:02:03.0-1):   
/dev/video0
HD TV CAM (usb-0000:03:00.0-2.1):
/dev/video1

以及终端中 arecord -l 的结果。

**** List of CAPTURE Hardware Devices ****  
card 0: AudioPCI [Ensoniq AudioPCI], device 0: ES1371/1 [ES1371 DAC2/ADC]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: CAM [HD TV CAM], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

谢谢。

最佳答案

这是我使用 FFmpeg 的 API 访问 USB 网络摄像头的解决方案。

int CaptureCam() 
{

avdevice_register_all(); /* for device & add libavdevice/avdevice.h headerfile*/
avcodec_register_all();
av_register_all();

char *dev_name = "/dev/video0"; // here mine is video0 , it may vary.
AVInputFormat *inputFormat =av_find_input_format("v4l2");
AVDictionary *options = NULL;
av_dict_set(&options, "framerate", "20", 0);

AVFormatContext *pAVFormatContext = NULL;

// check video source
if(avformat_open_input(&pAVFormatContext, dev_name, inputFormat, NULL) != 0)
{
cout<<"\nOops, could'nt open video source\n\n";
return -1;
}
else
{
cout<<"\n Success !";
}

} // end function

关于c++ - 如何使用 avformat_open_input 函数 (ffmpeg),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35340437/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com