What is the easiest way to extract an audio track from a video file and save it as an MP3 file?
8 Answers
Very simple CLI solution:
ffmpeg -i VIDEOFILE -acodec libmp3lame -metadata TITLE="Name of Song" OUTPUTFILE.mp3
In case you don't have ffmpeg installed:
sudo apt-get install ffmpeg
-
1I needed to list codecs before, with ffmpeg -codecs, to know availability– CapelliCJun 3, 2013 at 17:30
-
2In case ffmpeg says
Unknown encoder 'libmp3lame'
, try tosudo apt-get install libavcodec-extra-53
– NIAAug 12, 2013 at 12:10 -
1
Package ffmpeg is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'ffmpeg' has no installation candidate
– MERoseOct 18, 2015 at 13:21 -
1@MERose change
ffmpeg
toavconv
. It is a fork of ffmpeg, and is compatible with ffmpeg options (at least the ones in the answer).– Hi-AngelMar 19, 2016 at 9:56 -
1you can also get a piece of it.
-ss 00:00:03 -t 00:00:08
will give you 7 seconds from the 2nd. I use this to produce my custom ringtones :)– AugustoJul 8, 2019 at 13:35
You can do this in VLC.
Once you have started VLC:
- select "Media" --> "Convert/Save"
- Click "Add..." and select the file you want
- Click "Convert / Save" (on the bottom)
- Provide a "Destination file:"
- Select the "Profile" (i.e. "Audio - MP3", "Audio - Vorbis (OGG)", etc.)
- Click "Start"
- Relax and enjoy your shoes
You can install VLC from Synaptic or the Software Center.
-
1HowToGeek reported [their vlc ripping method] as rending poor quality audio. Jan 18, 2015 at 20:27
-
avidemux can do this.
It is inside Ubuntu Software Center or you can install it from the command line with:
sudo apt-get install avidemux
-
-
Here it is: avidemux.org/admWiki/doku.php?id=tutorial:save_only_audio– Zaar HaiNov 6, 2018 at 12:43
Using avconv
(from the command line, no need to install ffmpeg as avconv is its port to ubuntu)
- use
avconv -i "input file name"
to discover the file (video and audio mappings). In the example shown below, the audio that I wanted to strip had 0:0 "index". (If you read thoroughly the output fromavconv -i ...
command you will get this. - Then issue the command
avconv -i "input file name" -map 0:0 -c:a copy -metadata TITLE="title name" -metadata AUTHOR="author name" "output file name"
Test it with several output file formats and see.
-
probably the fastest (didn't time it though). +1 for the '-c:a copy'. to note: make sure the output is in the same format as the encoding in the video, or you'd need to specify codec in space of 'copy' Dec 16, 2014 at 11:41
The best way would be to use a tool that just handles the container. For MP4 I would recommend the MP4Box
tool from the gpac package. For other containers like Matroska there are projects and tools like MKVToolNix.
Retrieve information about the file (Note: You could also do this with mediainfo
):
$ MP4Box -info 29c3-5400-en-hacking_cisco_phones_h264.mp4
* Movie Info *
Timescale 1000 - Duration 00:54:30.144
Fragmented File no - 2 track(s)
File Brand isom - version 512
Created: UNKNOWN DATE
File has no MPEG4 IOD/OD
iTunes Info:
Name: Hacking Cisco Phones
Artist: Ang Cui, Michael Costello
Album: Chaos Communication Congress 2012 (29C3)
Comment: http://events.ccc.de/congress/2012/Fahrplan/events/5400.en.html
Genre: lecture
Encoder Software: Lavf54.29.104
Track # 1 Info - TrackID 1 - TimeScale 25 - Duration 00:54:30.080
Media Info: Language "Undetermined" - Type "vide:avc1" - 81752 samples
Visual Track layout: x=0 y=0 width=1024 height=576
MPEG-4 Config: Visual Stream - ObjectTypeIndication 0x21
AVC/H264 Video - Visual Size 720 x 576
AVC Info: 1 SPS - 1 PPS - Profile Main @ Level 3
NAL Unit length bits: 32
Pixel Aspect Ratio 64:45 - Indicated track size 1024 x 576
Self-synchronized
Track # 2 Info - TrackID 2 - TimeScale 48000 - Duration 00:54:30.143
Media Info: Language "English" - Type "soun:mp4a" - 153285 samples
MPEG-4 Config: Audio Stream - ObjectTypeIndication 0x40
MPEG-4 Audio MPEG-4 Audio AAC LC - 2 Channel(s) - SampleRate 48000
Synchronized on stream 1
Alternate Group ID 1
Extracting individual tracks to raw format:
$ MP4Box -raw 1 29c3-5400-en-hacking_cisco_phones_h264.mp4
Extracting MPEG-4 AVC-H264 stream to h264
$ MP4Box -raw 2 29c3-5400-en-hacking_cisco_phones_h264.mp4
Extracting MPEG-4 AAC
Show original file and results:
$ ls -1 29c3-5400-en-hacking_cisco_phones_h264*
29c3-5400-en-hacking_cisco_phones_h264.mp4
29c3-5400-en-hacking_cisco_phones_h264_track1.h264
29c3-5400-en-hacking_cisco_phones_h264_track2.aac
Which video format do you want to convert from? I use audacity to extract audio from mp4 and flv videos (haven't tried other formats but I assume it'll work just the same). When you open up the file, the video part is ignored, instead you'll have only the audio to work on (like normalize or truncate silence) and then export it to any formats including mp3.
This can be easily done with avidemux (sudo apt-get install avidemux
to install it).
Open the video file with avidemux, then choose a codec for the Audio in the combobox, then go to "Audio" menu and you'll find a "Save..." option.
Download mkvmerge
GUI from the Ubuntu Software Center:
- Add the video file and unselect the video part
- click "Start Muxing"
- The audio file will be save in the same directory were the video file is located.