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.
The
-map
option can do this, with the shortcut-map 0
.For example:
to copy the stream 0:0 and 0:2 to 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 anunknown timestamp
error. For a detailed tutorial, see the FFmpeg Wiki page on the-map
option.