【问题标题】:How can I use avformat_open_input function (ffmpeg)如何使用 avformat_open_input 函数(ffmpeg)
【发布时间】:2016-02-11 13:18:26
【问题描述】:

我买了一个HD HDMI to 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_inputconst 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  

谢谢。

【问题讨论】:

    标签: c++ opencv video ffmpeg


    【解决方案1】:

    这是我使用 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 2012-04-23
      • 2017-02-08
      • 2019-02-11
      • 2013-02-01
      • 1970-01-01
      相关资源
      最近更新 更多