Remux to MKV but add all streams using FFmpeg

2020-07-10 08:17发布

I'm trying to automate FFmpeg to remux all video files in a given directory to MKV. I'm currently using

ffmpeg -i $INPUT -c copy $OUTPUT.mkv

However, some streams are skipped that way - for example, if there are 2 audio streams only 1 goes to the output file.

How do I specify that all streams from the input must be copied to the output?

Since I'm trying to automate FFmpeg, it would be best if the command does not change for each file, i.e. manually specifying all the streams with -map would require me to first parse every file. I would do this if I need to, but if there is a better solution I'd prefer that.

标签: ffmpeg
1条回答
萌系小妹纸
2楼-- · 2020-07-10 08:48

How do I specify that all streams from the input must be copied to the output?

The -map option can do this, with the shortcut -map 0.

For example:

ffmpeg -i input.mkv -c copy -map 0:0 -map 0:2 output.mkv

to copy the stream 0:0 and 0:2 to output.mkv.

ffmpeg -i input.mkv -c copy -map 0 output.mkv

to copy all input streams from input 0 (input.mkv) to the output (even if there are multiple video, audio or subtitle streams).

The -map value corresponds to the input number (0 is the first input, 1 is the second input, etc): If you add an additional input (-> input 1), and also want to copy all of the contents, then you will need to add -map 1.

You can use ffprobe to analyse files and see which stream is mapped where. Try -fflags +genpts if you get an unknown timestamp error. For a detailed tutorial, see the FFmpeg Wiki page on the -map option.

查看更多
登录 后发表回答