
They should all be specified before specifying outputs using the -i option. Also, notice that I’ve extracted the codec settings in a separate line (this might not work if there is some stream meta-data that override this order). In order to make the dubbed track the default one, I’ve placed it prior to the original one. You can even have both of the audio tracks if you want: Create a new file with the video taken from the high quality video and the audio from dubbed one.


Which could be useful if we used other containers that support more than one format. That was easy! We can be more explicit about our audio encoder:įfmpeg -i input.mp4 -map 0:1 -c:a libmp3lame output.mp3 We will convert our stream into an mp3 while extracting it: If you have an ancient mp3-player that you cherish, the better aac codec might not be suitable.
#Ffmpegx extract audio mp4
If you want something more player-friendly, you should probably use mp4 (or m4a, which is the exact same thing (?), but makes some devices happy). Now, the choice of the output file extension is important.aac is closer to being raw data than it is to being a container format (?). So, we set the audio codec to copy to prevent FFmpeg from automatically transcoding the stream. Every time you perform the encoding, you are modifying the stream a little (or maybe a lot). Since our codec is lossy, decoding a stream and re-encoding it will most probably result in a slightly different stream. So, if we just did:įFmpeg will decode the input stream, encode it into aac again then write it to the output file. Then, it transcodes the input into that format. FFmpeg normally tries to deduce the desired file format from the output file extension. To extract the audio stream:įfmpeg -i input.mp4 -map 0:1 -c:a copy output.aac Notice the audio codec ( aac) and the bitrate ( 71 kb/s).

Our example file contains two streams, 0:0 (input file 0, stream number 0, which is video) and 0:1 (the audio stream we are about to extract). First, we discover the streams available and their order:įfmpeg version 2.8.8-0ubuntu0.16.04.1 Copyright (c) 2000-2016 the FFmpeg developers One common scenario is extracting audio from a video.
