How to record audio with ffmpeg on linux?
Solution 1
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
Solution 2
solved !
ffmpeg -f pulse -ac 2 -i default -f x11grab -r 30 -s 1920x1080 -i :0.0 -acodec pcm_s16le -vcodec libx264 -preset ultrafast -threads 0 -y /media/t/TBVolume/desktop/output.mkv
![Conor Patrick](https://i.stack.imgur.com/FU0Z5.jpg?s=256&g=1)
Comments
-
Conor Patrick almost 2 years
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 -
Leigh over 9 yearsIt would be helpful to others to also provide a brief description explaining how this solves the problem.
-
llogan about 4 yearsQuestion is about Linux, but your answer is for Windows.
-
Keith Bennett almost 4 yearsThe "dshow" can be replaced with "avfoundation" for it to work with Linux and Mac OS.
-
Cosimo over 3 yearsWhen using pulse audio, it's useful to be able to select exactly which audio device to record.
ffmpeg -sources pulse
will list the available pulse sources. In my case the one I wanted was the system's default mixed sound output device (alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo.monitor
). The ffmpeg command then becomes:ffmpeg -i pulse -ac 2 -i 'alsa_output.usb-Burr-Brown_from_TI_USB_Audio_CODEC-00.analog-stereo.monitor'
-
llogan over 3 years@KeithBennett avfoundation is only for macOS/iOS. Linux can use alsa and pulse.