I'm trying to re-encode video streams from a Matroska file to save space, while keeping all the subtitles as-is, using ffmpeg. I want to write a generic command that works without me having to specify exact stream numbers. Now I can't figure out how to let ffmpeg pick its default video stream and default audio stream and then all subtitles.
The current input file I'm working with has these streams, but other files will have different streams.
[lavf] stream 0: video (mpeg2video), -vid 0
[lavf] stream 1: audio (ac3), -aid 0, -alang eng, Surround 5.1
[lavf] stream 2: audio (ac3), -aid 1, -alang fre, Surround 5.1
[lavf] stream 3: audio (ac3), -aid 2, -alang ita, Surround 5.1
[lavf] stream 4: audio (ac3), -aid 3, -alang spa, Surround 5.1
[lavf] stream 5: audio (ac3), -aid 4, -alang eng, Stereo
[lavf] stream 6: subtitle (dvdsub), -sid 0, -slang eng
[lavf] stream 7: subtitle (dvdsub), -sid 1, -slang fre
[lavf] stream 8: subtitle (dvdsub), -sid 2, -slang ita
[lavf] stream 9: subtitle (dvdsub), -sid 3, -slang spa
[lavf] stream 10: subtitle (dvdsub), -sid 4, -slang ara
[lavf] stream 11: subtitle (dvdsub), -sid 5, -slang dan
[lavf] stream 12: subtitle (dvdsub), -sid 6, -slang dut
[lavf] stream 13: subtitle (dvdsub), -sid 7, -slang fin
[lavf] stream 14: subtitle (dvdsub), -sid 8, -slang ice
[lavf] stream 15: subtitle (dvdsub), -sid 9, -slang nor
[lavf] stream 16: subtitle (dvdsub), -sid 10, -slang por
[lavf] stream 17: subtitle (dvdsub), -sid 11, -slang swe
[lavf] stream 18: subtitle (dvdsub), -sid 12, -slang fre
[lavf] stream 19: subtitle (dvdsub), -sid 13, -slang ita
[lavf] stream 20: subtitle (dvdsub), -sid 14, -slang spa
Commands I have tried:
ffmpeg -i IN.mkv -c:v libx264 -threads 4 -speed 1 -f matroska OUT.mkv
Result: One video stream, one audio stream, no subtitle streams.
ffmpeg -i IN.mkv -c:v libx264 -threads 4 -speed 1 -f matroska -c:s copy OUT.mkv
Result: One video stream, one audio stream, one subtitle stream.
ffmpeg -i IN.mkv -c:v libx264 -threads 4 -speed 1 -f matroska -map 0 OUT.mkv
Result: All video, all audio, all subtitles.
ffmpeg -i IN.mkv -c:v libx264 -threads 4 -speed 1 -f matroska -c:s copy -map 0:s OUT.mkv
Result: No video, no audio, all subtitles.
As far as I can tell from the manual, -c:s copy
is supposed to copy all the streams, not just the default one, but it won't. Perhaps it's a bug?
To clarify, what I'm after is the result: one video, one audio and all subtitles.