0

I have multiple MKV files with video encoded a la HEVC/H.265. I want to, using the Windows command line, make a new MKV file, stripping out all but specific subtitle tracks and audio tracks, on a file-by-file basis, as I have no need to retain multiple foreign language sound tracks and subtitle tracks.

Let's say I used ffprobe to find what streams are in a given MKV file. Further, I want to keep the first and third audio tracks, and the 24th and 25th subtitle tracks, from said file. I used https://stackoverflow.com/questions/63302454/map-metadata-stream-by-filter-in-ffmpeg as a reference.

I have tried to do that with

ffmpeg -i INPUTFILE.MKV -map 0:0 -map 1:1 -map 1:3 -map 1:a:24 -map 1:a:25 OUTPUTFILE.MKV

which fails. How should I write the command?

0

In the syntax -map 1:a:24, 1 stands for the input file index. Counting starts from 0, so 1 refers to the 2nd input file but the command only has one input. a stands for stream type, and in this case, it's audio - v is for video, s for subtitles, d for data. 24 represents the 25th (0-indexed, remember) audio track. If your command has one input file with three video, three audio and three subtitle streams in the following order: V A S A V S V A S, then the 2nd video will be -map 0:v:1 You can reference it using absolute index by using -map 0:4. With absolute indexing, there's no stream type specifier.

Assuming the stream numbering in your description is correct, use

ffmpeg -i IN.MKV -map 0:0 -map 0:a:0 -map 0:a:2 -map 0:s:23 -map 0:s:24 -c copy OUT.MKV

Note that if -c copy is omitted, all streams will be re-encoded - not what you want normally.

| improve this answer | |

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.