I have an MKV file (vidui.mkv) with 6 tracks in it.

Track 1 - video - xvid - 1920x1080
Track 2 - video - xvid - 720x576
Track 3 - audio -  AAC - 1240kbps - English
Track 4 - audio -  AAC - 648kbps - Spanish
Track 5 - audio -  AAC - 648kbps - Commentary 1
Track 6 - audio -  AAC - 648kbps - Commentary 2

I want to convert the above file to a mp4 format with one h264 video and one AC3 audio. Also I want to convert track 1 (video) and track 5(audio).

If I use

ffmpeg.exe -i vidui.mkv -f mp4 -vcodec libx264 -acodec ac3 -crf 20 -sn -n vidui.mp4

it converts the first video track and first audio track, but what I would like it to do is convert track 1 and track 5.

  • 3
    It would be nice to see the command used to generate this track listing. Mar 27 '21 at 4:59

You can use the -map option (full documentation) to select specific input streams and map them to your output.

The most simple map syntax you can use is -map i:s, where i is the input file ID and s is the stream ID, both starting with 0. In your case, that means we select track 0 and 4:

ffmpeg -i vidui.mkv -c:v libx264 -c:a ac3 -crf 20 -map 0:0 -map 0:4 vidui.mp4

If you want to choose video, audio or subtitle tracks specifically, you can also use stream specifiers:

ffmpeg -i vidui.mkv -c:v libx264 -c:a ac3 -crf 20 -map 0:v:0 -map 0:a:1 vidui.mp4

Here, 0:v:0 is the first video stream and 0:a:1 is the second audio stream.

  • 1
    Is there a way to do this dynamically? Say I want to do this only to audio tracks of language X, and have ffmpeg pick this up?
    – Freedo
    Oct 20 '17 at 7:31
  • @Freedo Yes, please see the documentation. For example -map 0:m:language:eng
    – slhck
    Oct 20 '17 at 13:55
  • On a side note, by default not all streams are chosen.
    – x-yuri
    Nov 30 '21 at 6:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.