【问题标题】:Error when initializing webcam with ffmpeg使用 ffmpeg 初始化网络摄像头时出错
【发布时间】:2018-07-05 11:16:10
【问题描述】:

我正在尝试使用ffmpeg 设置网络摄像头并流式传输到本地主机。

这是我在终端中输入的命令:

ffmpeg -f alsa -ac 2 -i hw:1,0 -f v4l2 -s 1280x720 -r 10 -i /dev/video1 -vcodec libx264 -pix_fmt yuv420p -preset ultrafast -r 25 -g 20 -b:v 2500k -codec:a libmp3lame -ar 44100 -threads 6 -b:a 11025 -bufsize 512k -f flv rtmp://localhost:80/

这就是发生的事情:

ffmpeg 版本 2.8.11-0ubuntu0.16.04.1 版权所有 (c) 2000-2017 FFmpeg 开发者 使用 gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.4) 构建 20160609 配置: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir= /usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger - -enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite - -enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse - -enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis - -enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libav 设备 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100

ALSA lib pcm_hw.c:1700:(_snd_pcm_hw_open) 卡的值无效

[alsa @ 0x21c45c0] 无法打开音频设备 hw:1,0(没有这样的文件或目录)

hw:1,0:输入/输出错误

【问题讨论】:

    标签: ubuntu ffmpeg webcam


    【解决方案1】:

    https://trac.ffmpeg.org/wiki/Capture/ALSA中所述

    你应该试试这些:

    选择输入卡
    input_device 告诉 ffmpeg 你想使用哪个音频采集卡或设备。要获取您机器上所有已安装卡的列表,您可以键入 arecord -l 或 arecord -L(更长的输出)。

    列出记录卡或设备:

    $ arecord -l
    
    **** List of CAPTURE Hardware Devices ****
    card 0: ICH5 [Intel ICH5], device 0: Intel ICH [Intel ICH5]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: ICH5 [Intel ICH5], device 1: Intel ICH - MIC ADC [Intel ICH5 - MIC ADC]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: ICH5 [Intel ICH5], device 2: Intel ICH - MIC2 ADC [Intel ICH5 - MIC2 ADC]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 0: ICH5 [Intel ICH5], device 3: Intel ICH - ADC2 [Intel ICH5 - ADC2]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    card 1: U0x46d0x809 [USB Device 0x46d:0x809], device 0: USB Audio [USB Audio]
      Subdevices: 1/1
      Subdevice #0: subdevice #0
    

    我们可以看到安装了 2 个提供捕获功能的声卡,即“卡 0”(Intel ICH5)和“卡 1”(USB 网络摄像头上的麦克风)。最简单的做法是使用-f alsa -i hw:0-f alsa -i hw:1 直接引用它们中的每一个:

    ffmpeg -f alsa -i hw:1 -t 30 out.wav
    

    这将为我们提供 30 秒的 WAV 音频输出,从我们的 USB 摄像头的默认录音设备(麦克风)录制。可以使用alsamixer 工具(见下文)选择默认记录设备,或使用hw:<X>,<Y> 中的附加参数Y 指定设备,其中=card,=device。例如,要从 Intel 卡中选择“MIC2 ADC”(请看上面的列表),我们将使用:

    ffmpeg -f alsa -i hw:0,2 -t 30 out.wav
    

    最好的方法是使用 alsamixer 工具选择您的卡和默认录音设备,因为某些声卡通过ffmpeg 命令行选择默认输入的方法很复杂。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-19
      • 2011-12-30
      • 2020-01-02
      • 1970-01-01
      • 1970-01-01
      • 2016-10-23
      • 2017-12-27
      • 2014-08-06
      相关资源
      最近更新 更多