LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 06-22-2012, 07:41 PM   #1
p3aul
Member
 
Registered: Jul 2011
Distribution: Ubuntu 10.04
Posts: 116

Rep: Reputation: Disabled
Using ffmpeg to record sound from speakers


Is this possible? what would the command line look like?
Thanks,
Paul
 
Old 06-23-2012, 12:12 PM   #2
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Do you want to capture the sound which is actually playing on the speakers without a microphone?
If so, you can do it easily if your card supports capturing the PCM channel (you can see it with alsamixer) with an ffmpeg line like this:
Code:
ffmpeg -f alsa -i hw:0,0 -acodec XXX outfile.EXT
where XXX is your favorite audio encoder and EXT is your favorite audio container format You might also look at the other audio encoding options of ffmpeg, like ab (audio bitrate), ar (audio rate), ac (audio channels number) and so on.
Of course, you'll need to check your capture devices index (hw:0,0 just being an example) using arecord -l.
If your audio device supports PCM capturing, you could record a PCM (wav) file also with arecord itself.
If your card (like mine) doesn't support direct PCM capture, then you'll need to physically "short-circuit" a pair of connectors on your sound-card in order to be able to record.
If your system sports pulseaudio it might also be possible to exploit it regardless of the possibility to capture the PCM channel of your soundcard:
Code:
ffmpeg -f alsa -i pulse -acodec XXX outfile.EXT
 
Old 06-23-2012, 04:09 PM   #3
p3aul
Member
 
Registered: Jul 2011
Distribution: Ubuntu 10.04
Posts: 116

Original Poster
Rep: Reputation: Disabled
What are some options for the XXX? I havn't a clue!
 
Old 06-23-2012, 05:01 PM   #4
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
Quote:
ffmpeg -formats
shows available codecs (XXX) and file formats (EXT)
 
Old 06-24-2012, 01:11 AM   #5
qlue
Member
 
Registered: Aug 2009
Location: Umzinto, South Africa
Distribution: Crunchbangified Debian 8 (Jessie)
Posts: 747
Blog Entries: 1

Rep: Reputation: 172Reputation: 172
For mp3, I tried
Code:
ffmpeg -f alsa -i hw:0,0 -acodec libmp3lame outfile.mp3
and that worked on my box!
P.S: thanks 414N
 
Old 06-24-2012, 02:30 AM   #6
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
You're welcome
 
Old 06-24-2012, 03:47 AM   #7
p3aul
Member
 
Registered: Jul 2011
Distribution: Ubuntu 10.04
Posts: 116

Original Poster
Rep: Reputation: Disabled
This is what I get for every value of hw that I've tried:
Code:
owner@owner-desktop:/media/My Book/Music/Kingston Trio$ ffmpeg -f alsa -i hw:0,0 -acodec libmp3lame outfile.mp3
FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.1-1ubuntu1.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Sep 16 2011 17:04:18, gcc: 4.4.3
[alsa @ 0x8ef1a60]cannot set channel count to 1 (Invalid argument)
hw:0,0: I/O error occurred
Usually that means that input file is truncated and/or corrupted.
owner@owner-desktop:/media/My Book/Music/Kingston Trio$
 
Old 06-24-2012, 04:02 AM   #8
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Quote:
Originally Posted by p3aul View Post
Code:
[alsa @ 0x8ef1a60]cannot set channel count to 1 (Invalid argument)
hw:0,0: I/O error occurred
Usually that means that input file is truncated and/or corrupted.
As I said before, you should have looked at the other audio encoding options of ffmpeg.
This error means that ffmpeg, by default, is trying to capture the audio from hw:0,0 as mono (1 channel) stream and it fails to do so because it's not a mono stream. Try specifying the -ac 2 option for stereo capture:
Code:
ffmpeg -f alsa -ac 2 -i hw:0,0 -acodec libmp3lame outfile.mp3
If you're using Ubuntu and you have pulseaudio installed I would suggest using the -i pulse option instead of an alsa hardware pointer such ah hw:0,0.
 
Old 06-24-2012, 02:10 PM   #9
p3aul
Member
 
Registered: Jul 2011
Distribution: Ubuntu 10.04
Posts: 116

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by 414N View Post
As I said before, you should have looked at the other audio encoding options of ffmpeg.
This error means that ffmpeg, by default, is trying to capture the audio from hw:0,0 as mono (1 channel) stream and it fails to do so because it's not a mono stream. Try specifying the -ac 2 option for stereo capture:
Code:
ffmpeg -f alsa -ac 2 -i hw:0,0 -acodec libmp3lame outfile.mp3
If you're using Ubuntu and you have pulseaudio installed I would suggest using the -i pulse option instead of an alsa hardware pointer such ah hw:0,0.
Well I actually thought I had it there! It started capturing and when I quit by pressing "q" It saved a file to the current folder. It's size was about 400kb. I tried to play it but there was no sound. I turned the volume all the way up. No noise or static, just nothing. I feel as if I getting there though.
 
Old 06-25-2012, 02:42 AM   #10
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Have you tried specifying pulse as input instead of hw:0,0?
 
Old 06-25-2012, 03:01 AM   #11
qlue
Member
 
Registered: Aug 2009
Location: Umzinto, South Africa
Distribution: Crunchbangified Debian 8 (Jessie)
Posts: 747
Blog Entries: 1

Rep: Reputation: 172Reputation: 172
Also, check in alsamixer that nothing is muted or disabled.
Note, on my laptop, I seem to only be able to record sound from the input device. (microphone or mic input)
I have to use a patch cord between the ear and mic sockets to record sound from the speakers. (which disables the speakers unfortunately. The solution to that might be an external mixer/amp that includes a line out.)
 
Old 06-25-2012, 08:15 PM   #12
p3aul
Member
 
Registered: Jul 2011
Distribution: Ubuntu 10.04
Posts: 116

Original Poster
Rep: Reputation: Disabled
414N: Here is the command line where I just tried -i pulse Still no sound although I do get a file.

Code:
owner@owner-desktop:/media/My Book/Music/Peter, Paul & Mary$ ffmpeg -f alsa -i pulse -acodec libmp3lame outfile.mp3FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: --extra-version=4:0.5.1-1ubuntu1.2 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 4. 0 /  0. 4. 0
  libswscale     0. 7. 1 /  0. 7. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Sep 16 2011 17:04:18, gcc: 4.4.3
[alsa @ 0x9bada60]capture with some ALSA plugins, especially dsnoop, may hang.
Input #0, alsa, from 'pulse':
  Duration: N/A, start: 1340673030.946993, bitrate: N/A
    Stream #0.0: Audio: pcm_s16le, 44100 Hz, mono, s16, 705 kb/s
Output #0, mp3, to 'outfile.mp3':
    Stream #0.0: Audio: libmp3lame, 44100 Hz, mono, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Press [q] to stop encoding
size=     209kB time=26.78 bitrate=  64.0kbits/s    
video:0kB audio:209kB global headers:0kB muxing overhead 0.014939%
owner@owner-desktop:/media/My Book/Music/Peter, Paul & Mary$ q

Last edited by p3aul; 06-25-2012 at 11:11 PM.
 
Old 06-26-2012, 07:45 AM   #13
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 647

Rep: Reputation: 189Reputation: 189
Quote:
Originally Posted by p3aul View Post
414N: Here is the command line where I just tried -i pulse Still no sound although I do get a file.
Last try: run alsamixer, press F5 and make sure that your PCM channel has an unmuted CAPTURE line. If you don't see anything above "PCM", then you're out of luck. If you see a bunch of dashes "----", then press "space" when selecting PCM and you should see a red CAPTURE flag appear. You should now be able to capture from PCM when using the alsa format in ffmpeg.
If your card doesn't support capturing from PCM, then you'll need to go the hardware way, with a simple jack-jack connection between your mic input and speaker output.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ffmpeg can't record desktop + sound lord_didger Linux - Desktop 4 06-19-2012 05:19 AM
record sound from both speakers and mic davidwillis Linux - General 28 04-27-2010 08:48 AM
No sound from external speakers in Fedora 8 (laptop speakers ok) openSauce Linux - Hardware 7 03-15-2009 03:48 PM
sound from laptop speakers although external speakers are connected! superpingu Linux - Laptop and Netbook 1 10-18-2007 06:32 AM
how to record with ffmpeg evaristegalois Linux - Software 1 09-07-2006 06:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration