Converting mp4 to mp3
Solution 1
For FFmpeg with Constant Bitrate Encoding (CBR):
ffmpeg -i video.mp4 -vn \
-acodec libmp3lame -ac 2 -ab 160k -ar 48000 \
audio.mp3
or if you want to use Variable Bitrate Encoding (VBR):
ffmpeg -i video.mp4 -vn \
-acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 \
audio.mp3
The VBR example has a target bitrate of 165 Kbit/s with a bitrate range of 140...185.
Solution 2
is the leading audio file converter for the GNOME Desktop. It reads anything GStreamer can read (Ogg Vorbis, AAC, MP3, FLAC, WAV, AVI, MPEG, MOV, M4A, AC3, DTS, ALAC, MPC, Shorten, APE, SID, MOD, XM, S3M, etc...), and writes to WAV, FLAC, MP3, AAC, and Ogg Vorbis files, or use a GNOME Audio Profile.
SoundConverter aims to be simple to use, and very fast. Thanks to its multithreaded design, it will use as many cores as possible to speed up the conversion. It can also extract the audio from videos.
How to Convert MP4 to MP3 with VLC
Open VLC Media Player. Click "Media" > "Convert" to enter the "Open Media" window. Click the "Add" button on the right side of the screen to enter Windows Explorer. Locate the MP4 on your hard drive you want to convert. Click the "Convert" button at the bottom of the screen.
Select the name of the Target file.
Click the "Audio Codec" tab and select "MP3" from the "Codec" drop down box. Press the "Start" button to begin converting your MP4 to MP3 audio.
Click Start
Solution 3
I have a shell-script that uses mplayer
(so it can convert anything mplayer
can play) to extract the audio, and then encode it using lame
.
Here is the code:
#! /bin/bash
# any2mp3.sh
# Converts to mp3 anything mplayer can play
# Needs mplayer amd lame installed
[ $1 ] || { echo "Usage: $0 file1.wma file2.wma"; exit 1; }
for i in "$@"
do
[ -f "$i" ] || { echo "File $i not found!"; exit 1; }
done
[ -f audiodump.wav ] && {
echo "file audiodump.wav already exists"
exit 1
}
for i in "$@"
do
ext=`echo $i | sed 's/[^.]*\.\([a-zA-Z0-9]\+\)/\1/g'`
j=`basename "$i" ".$ext"`
j="$j.mp3"
echo
echo -n "Extracting audiodump.wav from $i... "
mplayer -vo null -vc null -af resample=44100 -ao pcm:waveheader:fast \
"$i" >/dev/null 2>/dev/null || {
echo "Problem extracting file $i"
exit 1
}
echo "done!"
echo -n "Encoding to mp3... "
lame -m s audiodump.wav -o "$j" >/dev/null 2>/dev/null
echo "done!"
echo "File written: $j"
done
# delete temporary dump file
rm -f audiodump.wav
First you need to apt-get install mplayer lame
.
After that, put the code in a file named ''any2mp3.sh'', give permission to execute, and put that in your $PATH, and you will be able to do:
$ any2mp3.sh file.mp4 another-file.wma yet-another.file.ogg
It will convert each file passed to an mp3 with the same name.
It's a little rough, but does the job.
Solution 4
I think the problem is with your syntax of the ffmpeg command.
ffmpeg -i source_filename -vn -ab 192k -acodec libmp3lame -ac 2 output_filename
should work.
Solution 5
I use this small script for converting m4a to mp3.
#!/bin/bash
for i in *.m4a; do
avconv -i "$i" -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 "`basename "$i" .m4a`.mp3"
done
Related videos on Youtube
aki
astalavista everybody, it was a pleasure to accept your answers, i had great time on stack overflow but this is the end of the road for me! share knowledge!
Updated on September 18, 2022Comments
-
aki almost 2 years
I have a video I need to convert to mp3 (from the command line - not GUI):
video.mp4
I tried:
ffmpeg -i -b 192 video.mp4 video.mp3
with no success. I get the following error:
WARNING: library configuration mismatch Seems stream 0 codec frame rate differs from container frame rate: 59.83 (29917/500) -> 59.75 (239/4) WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s Encoder (codec id 86017) not found for output stream #0.0
so I tried lame:
lame -h -b 192 video.mp4 video.mp3
I get:
Warning: unsupported audio format
Am I missing something?
-
duffydack over 12 yearschange -b to -ab
-
-
aki over 12 yearsi get: Expected number for ac but found: liblamemp3
-
aki over 12 yearsi did everything and i get:
-rw-r--r-- 1 aki aki 7104 2011-12-02 10:41 video.mp3
which does not play -
elias over 12 yearsthat's weird... it seems that lame couldn't convert the wav. try removing the
>/dev/null 2>/dev/null
from the code to see the error message. -
aki over 12 yearsno luck, here's the output: pastebin.com/ALrTqCmk of both conversions
-
elias over 12 yearsAnd does the audiodump.wav plays? If it doesn't,
mplayer
couldn't play the video.mp4 file, and then you're really out of luck. Maybe the file you are trying to convert is corrupted, can you test the process with another file? -
aki over 12 yearsno, the wav does not play, nor the mp4 from mplayer
-
elias over 12 yearsYeah, if
mplayer
can't play the mp4, then the conversion won't work with this method. :/ -
elias over 12 yearsah! you're welcome, glad you solved it! :)
-
Darth Egregious over 12 yearsAssuming that lame is already installed.
-
aki over 12 yearsha thanks, that is exactly what i am looking for
-
Jason Scheirer about 12 yearsThe only extra step to this is
sudo apt-get install libavcodec-extra-53
-
thomasrutter over 11 yearsOr since this is Ubuntu, ubuntu-restricted-extras, which includes libavcodec-extra-53 among other things. You may have installed this already as the installation CD prompts to do so.
-
Nathan Osman over 10 yearsBut the OP asked for a command-line solution.
-
andrew.46 about 10 yearsMy edit added in a VBR example and labelled the fixed bitrate example as CBR...
-
Jakke over 9 yearsFor Ubuntu 14 users: askubuntu.com/questions/432542/… => use avconv instead
-
sanoJ almost 5 yearsIf it says
avconv
if not found installffmpeg
and replace it withffmpeg
-
Eric over 4 yearsThis is great !!!
-
Timo over 3 yearsWhat is the difference between CBR and VBR?
When it comes to selecting VBR vs. CBR, It is almost always recommended that you use VBR encoding for your media files as it provides higher quality files. We would suggest that you do not use CBR unless you have a specific need for playback on a device that only supports CBR.
-
Timo about 3 yearsMaybe you can leave
ar
, which should be inHz
and also leave-qscale:a