Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to record audio with ffmpeg on linux?

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

like image 950
Conor Patrick Avatar asked Nov 07 '13 04:11

Conor Patrick


People also ask

Can you record with ffmpeg?

Quicktime Player is natively installed on most of Mac computers. This tutorial focuses on Linux and Mac. FFmpeg is a powerful command line tool that allows you to record your computer screen and your voice. You can also easily convert videos to several formats.


2 Answers

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:

  • http://www.alsa-project.org/main/index.php/DeviceNames

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

like image 128
GreenGuerilla Avatar answered Oct 09 '22 00:10

GreenGuerilla


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 
like image 44
tatsu Avatar answered Oct 09 '22 01:10

tatsu