[0:00] okay so this is how to extract audio [0:01] from a video file and save it as an mp3 [0:04] using ffmpeg so I've got these two video [0:07] files here and let's just play waves so [0:10] MPV waves so you can see it's got a [0:17] single audio track on it and let's just [0:20] confirm that with ffmpeg so ffmpeg - I [0:25] waves and you can see that it has one [0:29] audio stream which is this one here so [0:34] in order to extract that and save as an [0:36] mp3 all we need to do is type in ffmpeg [0:39] - I the name of our video files as waves [0:43] and then our audio codec so - see code [0:48] on a and we're going to use lib mp3 lame [0:51] and now we need to decide whether we [0:54] want a constant bitrate file or a [0:56] variable bitrate file so in this case [0:58] I'm just going to pick variable bitrate [1:00] so - Q : [1:03] a and let's go somewhere in the middle [1:05] of the road so let's pick four and now [1:09] all we need to do is provide an output [1:11] file name so let's call it waves - sound [1:14] dot mp3 and hit enter and we're done so [1:18] if we just LS you can see that we now [1:21] have an mp3 file and let's just play it [1:23] with MPV [1:31] so that's the audio extracted from our [1:34] waves video file so what if we wanted to [1:37] extract an audio track from a video file [1:39] that's got multiple audio tracks so I've [1:42] got this video cars here so let's play [1:44] it so the first track is this weird tune [1:52] and the second track is just another [1:55] music track so let's quit that and let's [1:59] just look at that with ffmpeg so ffmpeg [2:02] - I cars so you can see that we have [2:05] these two audio streams so all we need [2:09] to do is modify our previous command a [2:11] tiny bit so that we can select the audio [2:14] track that we want to encode so let's [2:17] just use ffmpeg to do that so ffmpeg - I [2:22] cars and then same set up our audio [2:25] codec so - C : a and it's going to be [2:29] live mp3 lame and this time we're going [2:33] to go for a constant bitrate so - B : a [2:37] and let's set it to 320 K which is the [2:39] highest that we can set so that's 32 [2:42] kilobytes per second so now what we need [2:44] to do is select one of our audio tracks [2:47] so we can do that using map so if we [2:50] type in - map and for our second audio [2:53] track it would be zero : - now let me [2:57] just explain map for a second so this [3:00] first number here and by the way all of [3:02] these numbers start from zero in their [3:04] scale so this first number here [3:07] indicates the first file input - ffmpeg [3:10] which is this file here if we had have [3:12] actually put in another file in fact we [3:16] can actually just do that so you can see [3:17] so if we just use another - I waves dot [3:26] mp4 so now we've got another input file [3:29] so if we wanted to select an audio [3:31] stream from this input file we would [3:34] then set that to one so let's just go to [3:37] the end so we'd set that to one and [3:39] there is no second audio track within [3:42] that file so this wouldn't work [3:44] so we'd actually have to set it to one [3:45] but let's just change it back to two and [3:47] this back to zero so the first number [3:50] indicates which file so we're selecting [3:53] cars and the second number indicates [3:56] which stream so zero in our caused or [3:59] mp4 file is actually the video stream [4:02] one is our first audio track and two is [4:05] our second audio track so we're [4:07] selecting the second audio track so all [4:10] we need to do now is provide an output [4:12] file name so let's just call it cars [4:15] - second dot mp3 and let's hit enter [4:20] and we're done so if we just LS and [4:23] let's play it so NPV cars [4:26] - second you can see that it's the [4:31] second track play so what if we wanted [4:36] to extract both of the audio tracks from [4:38] that file and save them into separate [4:40] mp3 files well we could actually do that [4:43] in just one command line so let's just [4:45] remove that file first so RM cars [4:48] - second so that's gone now and if we [4:53] just modify our previous command so [4:55] let's just make some space and get rid [4:56] of this because we don't need that [4:58] anyway and all we need to do is another [5:03] map so - map and it's the first file so [5:07] 0 : and the first audio stream which is [5:12] one in this particular case and just [5:17] provide an output file name so let's [5:19] call it cars and it's actually the first [5:21] audio track so let's just call it first [5:23] dot mp3 [5:29] and that's it so if we just LS now we've [5:31] got two new mp3 files and if we play [5:34] them so let's MPV cause - first [5:39] [Music] [5:41] there's the first audio track and let's [5:44] just play the second there's the second [5:50] audio track and that's all there is to [5:54] it so I hope you found that useful if [5:56] you did don't forget to subscribe and [5:58] thanks for watching goodbye [6:10] [Music]