Having trouble understanding ffmpeg -map command

ffmpegvideo conversion

I'm trying to copy video/audio from an mkv container to mp4. When I run ffmpeg -i input.mkv -c:v copy -c:a copy output.mp4 I'm given no video with polish audio. There's only one video stream, stream #0:0. Stream #0:1 is polish audio, #0:2 english, and #0:3 – #0:5 are subtitles.

I read this https://trac.ffmpeg.org/wiki/How%20to%20use%20-map%20option but don't understand it really. Why is -map 0:1 written twice in example 1? What does -c:s do? What would a command to copy #0:0 to video and #0:2 to audio look like?

Best Answer

  • -map <inputNo>:<streamNo> tells ffmpeg to take stream streamNo from the input inputNo and to add it to the output, where <inputNo> starts with 0.

    Sometimes, you may want to take the same input stream twice (such as -map 0:1 -map 0:1 in the example) because you can encode each with different codecs/parameters. In the example, the output contains the same audio stream twice, one in MP3 and the other in AAC.

    By default (i.e. with no -map command at all), one video, one audio, and one subtitle stream from the inputs are taken. If you want to map all the streams from one input, use -map <inputNo>.

    That you don't get video with your command can only mean one thing : your video track is encoded with a codec that can be muxed in MKV, but not in MP4. So it is discarded automatically. Can you post a log of ffmpeg -i input.mkv so that we can check which codecs the tracks are encoded with ?

    Finally, -c:s is used for subtitle codec (while -c:a is for audio and -c:v for video)

  • Related Question