Warm tip: This article is reproduced from serverfault.com, please click

How to record audio with ffmpeg on linux?

发布于 2013-11-07 04:51:03

I'd like to record audio from my microphone. My OS is ubuntu. I've tried the following and got errors

$ ffmpeg -f alsa -ac 2 -i hw:1,0 -itsoffset 00:00:00.5 -f video4linux2 -s 320x240 -r 25 /dev/video0 out.mpg

ffmpeg version 0.8.8-4:0.8.8-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav
developers
  built on Oct 22 2013 12:31:55 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release.
Please use avconv instead.
ALSA lib conf.c:3314:(snd_config_hooks_call) Cannot open shared library
libasound_module_conf_pulse.so
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM hw:1,0
[alsa @ 0xbda7a0] cannot open audio device hw:1,0 (No such file or directory)
hw:1,0: Input/output error

Then I tried

$ ffmpeg -f oss -i /dev/dsp audio.mp3

ffmpeg version 0.8.8-4:0.8.8-0ubuntu0.12.04.1, Copyright (c) 2000-2013 the Libav
developers
built on Oct 22 2013 12:31:55 with gcc 4.6.3
*** THIS PROGRAM IS DEPRECATED ***
This program is only provided for compatibility and will be removed in a future release.
Please use avconv instead.
[oss @ 0x1ba57a0] /dev/dsp: No such file or directory
/dev/dsp: Input/output error

I haven't been able to get ffmpeg to find my microphone. How can I tell ffmpeg to record from my microphone?
It seems the 'Deprecated' message can be ignored because of this topic

Questioner
Conor Patrick
Viewed
0
GreenGuerilla 2014-02-28 07:29:05

I realise this is a bit old. Just in case anyone else is looking:

ffmpeg -f alsa -ac 2 -i default -itsoffset 00:00:00.5 -f video4linux2 -s 320x240 -r 25 -i /dev/video0 out.mpg

This way it will use the default device to record from. You were also missing a -i before the video capture device - /dev/device0

If you want to get more specific you should take a look in /proc/asound. Check the cards, devices, pcm files and the card subdirectories. You should be able to glean enough information there to be able to make an educated guess; e.g hw:1,0 or hw:2,0

The documentation may provide further clues:

The same goes for the webcam - it may not be /dev/video0, perhaps you have an external webcam plugged in and its at /dev/video1 - Have a look in the /dev directory and see whats available