使用ffmpeg

时间:2018-01-26 04:39:36

标签: ubuntu ffmpeg webcam

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

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

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     libavdevice 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:输入/输出错误

1 个答案:

答案 0 :(得分: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" (英特尔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。例如,选择&#34; MIC2 ADC&#34;从英特尔卡(见上面的列表),我们将使用:

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

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