Extract audio from video with FFmpeg
45sQuick, practical tutorial showing how to extract audio from a video file using a simple FFmpeg command.
▶ Play ClipThis tutorial demonstrates how to extract audio from video files and save it as MP3 using FFmpeg. It covers extracting audio from a single audio track, selecting a specific track from multiple audio streams, and extracting all tracks in one command.
Use ffmpeg -i input.mp4 -c:a libmp3lame -q:a 4 output.mp3 to extract audio with variable bitrate.
Use ffmpeg -i input.mp4 -c:a libmp3lame -b:a 320k -map 0:2 output.mp3 to select the second audio track (stream index 2).
Use multiple -map options: ffmpeg -i input.mp4 -map 0:1 -c:a libmp3lame -q:a 4 first.mp3 -map 0:2 -c:a libmp3lame -q:a 4 second.mp3 to extract both tracks in one command.
FFmpeg provides a simple yet powerful way to extract audio from video files, supporting both single and multiple audio tracks with options for bitrate and quality.
"Title accurately describes the content; the video delivers exactly what it promises."
What command extracts audio from a video file using FFmpeg with variable bitrate?
ffmpeg -i input.mp4 -c:a libmp3lame -q:a 4 output.mp3
00:36
What does the -q:a option control in FFmpeg?
It sets the variable bitrate quality (lower is better).
01:00
How do you select the second audio track from a video file with multiple audio streams?
Use -map 0:2 (assuming stream index 2 is the second audio track).
02:47
What does the first number in -map 0:2 represent?
It indicates the input file index (0 for the first input file).
03:00
What is the maximum constant bitrate for MP3 in FFmpeg?
320 kbps.
02:39
How can you extract both audio tracks from a video into separate MP3 files in one command?
Use multiple -map options: ffmpeg -i input.mp4 -map 0:1 -c:a libmp3lame -q:a 4 first.mp3 -map 0:2 -c:a libmp3lame -q:a 4 second.mp3
04:36
Basic extraction command
Core technique for extracting audio with variable bitrate.
00:36Using -map to select streams
Key concept for handling multiple audio tracks.
02:47Extracting multiple tracks in one command
Efficient method for batch extraction.
04:36[00:00] okay so this is how to extract audio
[00:01] from a video file and save it as an mp3
[00:04] using ffmpeg so I've got these two video
[00:07] files here and let's just play waves so
[00:10] MPV waves so you can see it's got a
[00:17] single audio track on it and let's just
[00:20] confirm that with ffmpeg so ffmpeg - I
[00:25] waves and you can see that it has one
[00:29] audio stream which is this one here so
[00:34] in order to extract that and save as an
[00:36] mp3 all we need to do is type in ffmpeg
[00:39] - I the name of our video files as waves
[00:43] and then our audio codec so - see code
[00:48] on a and we're going to use lib mp3 lame
[00:51] and now we need to decide whether we
[00:54] want a constant bitrate file or a
[00:56] variable bitrate file so in this case
[00:58] I'm just going to pick variable bitrate
[01:00] so - Q :
[01:03] a and let's go somewhere in the middle
[01:05] of the road so let's pick four and now
[01:09] all we need to do is provide an output
[01:11] file name so let's call it waves - sound
[01:14] dot mp3 and hit enter and we're done so
[01:18] if we just LS you can see that we now
[01:21] have an mp3 file and let's just play it
[01:23] with MPV
[01:31] so that's the audio extracted from our
[01:34] waves video file so what if we wanted to
[01:37] extract an audio track from a video file
[01:39] that's got multiple audio tracks so I've
[01:42] got this video cars here so let's play
[01:44] it so the first track is this weird tune
[01:52] and the second track is just another
[01:55] music track so let's quit that and let's
[01:59] just look at that with ffmpeg so ffmpeg
[02:02] - I cars so you can see that we have
[02:05] these two audio streams so all we need
[02:09] to do is modify our previous command a
[02:11] tiny bit so that we can select the audio
[02:14] track that we want to encode so let's
[02:17] just use ffmpeg to do that so ffmpeg - I
[02:22] cars and then same set up our audio
[02:25] codec so - C : a and it's going to be
[02:29] live mp3 lame and this time we're going
[02:33] to go for a constant bitrate so - B : a
[02:37] and let's set it to 320 K which is the
[02:39] highest that we can set so that's 32
[02:42] kilobytes per second so now what we need
[02:44] to do is select one of our audio tracks
[02:47] so we can do that using map so if we
[02:50] type in - map and for our second audio
[02:53] track it would be zero : - now let me
[02:57] just explain map for a second so this
[03:00] first number here and by the way all of
[03:02] these numbers start from zero in their
[03:04] scale so this first number here
[03:07] indicates the first file input - ffmpeg
[03:10] which is this file here if we had have
[03:12] actually put in another file in fact we
[03:16] can actually just do that so you can see
[03:17] so if we just use another - I waves dot
[03:26] mp4 so now we've got another input file
[03:29] so if we wanted to select an audio
[03:31] stream from this input file we would
[03:34] then set that to one so let's just go to
[03:37] the end so we'd set that to one and
[03:39] there is no second audio track within
[03:42] that file so this wouldn't work
[03:44] so we'd actually have to set it to one
[03:45] but let's just change it back to two and
[03:47] this back to zero so the first number
[03:50] indicates which file so we're selecting
[03:53] cars and the second number indicates
[03:56] which stream so zero in our caused or
[03:59] mp4 file is actually the video stream
[04:02] one is our first audio track and two is
[04:05] our second audio track so we're
[04:07] selecting the second audio track so all
[04:10] we need to do now is provide an output
[04:12] file name so let's just call it cars
[04:15] - second dot mp3 and let's hit enter
[04:20] and we're done so if we just LS and
[04:23] let's play it so NPV cars
[04:26] - second you can see that it's the
[04:31] second track play so what if we wanted
[04:36] to extract both of the audio tracks from
[04:38] that file and save them into separate
[04:40] mp3 files well we could actually do that
[04:43] in just one command line so let's just
[04:45] remove that file first so RM cars
[04:48] - second so that's gone now and if we
[04:53] just modify our previous command so
[04:55] let's just make some space and get rid
[04:56] of this because we don't need that
[04:58] anyway and all we need to do is another
[05:03] map so - map and it's the first file so
[05:07] 0 : and the first audio stream which is
[05:12] one in this particular case and just
[05:17] provide an output file name so let's
[05:19] call it cars and it's actually the first
[05:21] audio track so let's just call it first
[05:23] dot mp3
[05:29] and that's it so if we just LS now we've
[05:31] got two new mp3 files and if we play
[05:34] them so let's MPV cause - first
[05:39] [Music]
[05:41] there's the first audio track and let's
[05:44] just play the second there's the second
[05:50] audio track and that's all there is to
[05:54] it so I hope you found that useful if
[05:56] you did don't forget to subscribe and
[05:58] thanks for watching goodbye
[06:10] [Music]
⚡ Saved you time reading this? Transcribe any YouTube video for free — no signup needed.