LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-24-2012, 08:39 PM   #1
derstephen
Member
 
Registered: Sep 2011
Location: Northern Colorado
Distribution: Slackware64
Posts: 79

Rep: Reputation: Disabled
Capturing audio from H.264 video as mp3


Hi all, not new to Linux but pretty new to media/codec matters. My story is already getting rather long, but basically I'm trying to capture the audio from a Youtube video as an mp3 file.

I've tried to install ffmpeg, but after spending several hours in dependency hell (texlive alone took a couple of hours just to download) I've decided to try to find a solution using either mencoder/mplayer or avidemux, which I already have installed.

I used the youtube-dl script to get the video (as a .flv) and it works fine; mplayer plays it back perfectly, audio and all. The trouble comes when I try to dump the audio with mplayer or open it in avidemux, in order to end up with a simple .mp3 file. I've found the basic commands online but they don't seem to work for me.

To start with a simple mplayer audio dump to the default stream.dump:

Code:
stephen@darkstar:~$ mplayer FpJpterivWs.flv -dumpaudio                                                                                                                                                                           
MPlayer 20101218-4.5.1 (C) 2000-2010 MPlayer Team

Playing FpJpterivWs.flv.
libavformat file format detected.
[flv @ 0x178b0c0] Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (aac), -aid 0
VIDEO:  [H264]  640x480  0bpp  29.970 fps  193.2 kbps (23.6 kbyte/s)
Core dumped ;)

Exiting... (End of file)
stephen@darkstar:~$ mpg123 stream.dump                                                                                                                                                                                       
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
	version 1.13.3; written and copyright by Michael Hipp and others
	free software (LGPL/GPL) without any warranty but with best wishes

Playing MPEG stream 1 of 1: stream.dump ...
MPEG 1.0 layer I, 394 kbit/s (free format), 32000 Hz joint-stereo
Note: Illegal Audio-MPEG-Header 0x0bc222f8 at offset 1422.
Note: Trying to resync...
Note: Skipped 794 bytes in input.
[parse.c:537] error: Giving up searching valid MPEG header after (over) 64K of junk.

[0:00] Decoding of stream.dump finished.
stephen@darkstar:~$
I should note that I am able to use mpg123 to play preexisting .mp3 files just fine, so I know the mp3 codec is somewhere on my system.

Another option was to use avidemux, but when I do that I get a warning about syncing issues with H.264 movies (of course I don't really care about syncing issues) followed by a message saying "no audio decoder found for this file" (obviously a much bigger problem). Avidemux displays the video just fine, but with no audio whatsoever, so I can't use it to save a separate copy of the audio.

From some of what I find on Google, it seems that Youtube videos used to be pretty simple containers using mp3 audio. Did that change to something else for some reason recently?

Last edited by derstephen; 07-24-2012 at 08:42 PM.
 
Old 07-26-2012, 05:34 AM   #2
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 593

Rep: Reputation: 140Reputation: 140
http://www.cyberciti.biz/faq/linux-u...online-stream/
Code:
mplayer -dumpaudio -dumpfile output_filename.mp3 input.video_file.name
Where,
-dumpaudio : Dumps raw compressed audio stream to ./stream.dump (useful with MPEG/AC-3, in most other cases the resulting file will not be playable). If you give more than one of -dumpaudio, -dumpvideo, -dumpstream on the command line only the last one will work.
-dumpfile filename.mp3 : Specify which file (filename.mp3) MPlayer should dump to. Should be used together with -dumpaudio / -dumpvideo / -dumpstream.
 
Old 07-26-2012, 06:02 AM   #3
414N
Member
 
Registered: Sep 2011
Location: Italy
Distribution: Slackware
Posts: 638

Rep: Reputation: 186Reputation: 186
Quote:
Originally Posted by derstephen View Post
I've tried to install ffmpeg, but after spending several hours in dependency hell (texlive alone took a couple of hours just to download) I've decided to try to find a solution using either mencoder/mplayer or avidemux, which I already have installed.
You don't need texlive to compile ffmpeg, as te-tex (the one which come with Slackware itself) should suffice. You could even disable documentation during build with the "--disable-doc" configure switch.
Remember that, for mp3 encoding, you need lame.
Quote:
Originally Posted by derstephen View Post
I used the youtube-dl script to get the video (as a .flv) and it works fine; mplayer plays it back perfectly, audio and all. The trouble comes when I try to dump the audio with mplayer or open it in avidemux, in order to end up with a simple .mp3 file. I've found the basic commands online but they don't seem to work for me.

To start with a simple mplayer audio dump to the default stream.dump:

Code:
stephen@darkstar:~$ mplayer FpJpterivWs.flv -dumpaudio                                                                                                                                                                           
MPlayer 20101218-4.5.1 (C) 2000-2010 MPlayer Team

Playing FpJpterivWs.flv.
libavformat file format detected.
[flv @ 0x178b0c0] Estimating duration from bitrate, this may be inaccurate
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (aac), -aid 0
VIDEO:  [H264]  640x480  0bpp  29.970 fps  193.2 kbps (23.6 kbyte/s)
Core dumped ;)

Exiting... (End of file)
stephen@darkstar:~$ mpg123 stream.dump                                                                                                                                                                                       
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layers 1, 2 and 3
	version 1.13.3; written and copyright by Michael Hipp and others
	free software (LGPL/GPL) without any warranty but with best wishes

Playing MPEG stream 1 of 1: stream.dump ...
MPEG 1.0 layer I, 394 kbit/s (free format), 32000 Hz joint-stereo
Note: Illegal Audio-MPEG-Header 0x0bc222f8 at offset 1422.
Note: Trying to resync...
Note: Skipped 794 bytes in input.
[parse.c:537] error: Giving up searching valid MPEG header after (over) 64K of junk.

[0:00] Decoding of stream.dump finished.
stephen@darkstar:~$
As you can see from the quoted bold lines, the flv you downloaded contains an h264 video stream and an aac audio stream, so you cannot extract an mp3 track from it without performing a format conversion.
Quote:
Originally Posted by derstephen View Post
Another option was to use avidemux, but when I do that I get a warning about syncing issues with H.264 movies (of course I don't really care about syncing issues) followed by a message saying "no audio decoder found for this file" (obviously a much bigger problem). Avidemux displays the video just fine, but with no audio whatsoever, so I can't use it to save a separate copy of the audio.
Using avidemux for a simple job like this is kinda an overkill. However, it seems like your copy of avidemux was not compiled with mp3 (read: lame) support.
Quote:
Originally Posted by derstephen View Post
From some of what I find on Google, it seems that Youtube videos used to be pretty simple containers using mp3 audio. Did that change to something else for some reason recently?
As I said above, some of them (the low quality ones for the most) still contain an mp3 audio stream, while the others contain an aac one.
I don't know what use you'll make from the extracted audio, but you can safely extract aac inside an mp4 or m4a container and most kinda modern audio devices should be able to read it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Xine h.264 faad audio problem Snigger Ubuntu 1 02-11-2011 05:07 AM
H.264 video lagging with MPlayer Electrode Linux - Software 31 05-23-2010 05:16 AM
capturing realtime audio/video saxena2222 Linux - Newbie 2 03-13-2008 05:15 AM
Encoding to H.264 video codec? ixus_123 Linux - Software 1 02-21-2005 11:42 AM
Capturing video with Cinelerra works, capturing video with Xawtv doesn't! seaelf Slackware 0 06-27-2004 05:18 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:53 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