Using ffmpeg on how do I copy the video and multiple subtitle streams in an MKV and reencode multiple audio streams into AC3?

I have a video file in MKV format. I like the quality of the video, but I dislike having the audio in FLAC format since I decided it takes up too much space.

It is a dual audio file—it’s an anime with Japanese and English audio—and it has several subtitle streams inside as well.

This is the command I use:

ffmpeg -i "01.mkv" -c:v copy -c:a ac3 -c:s copy "test.mkv"

However it only gets the first audio and first subtitle string. I need help with the map option for multiple streams.

6

3 Answers

I believe you need to specify the mapping of the audio and subtitle streams to ensure that all of them are copied through rather than the first. To do so you need to add -map 0:a? -map 0:s? -map 0:v before your -c:v

This should make your command

ffmpeg -i "01.mkv" -map 0:a? -map 0:s? -map 0:v -c:v copy -c:a ac3 -c:s copy "test.mkv"

The map command is used to tell it that you definitely want those things to be pulled through to the output. -map 0:a:1 would specify only to copy audio stream number 1, while -map 0:a? should effectively wildcard it and copy them all.

1

Add -map 0 after the input, which includes in the output all streams of all types:

ffmpeg -i "01.mkv" -map 0 -c:v copy -c:a ac3 -c:s copy "test.mkv"

You can also tell the map command to include only some stream types.

-map 0:a would copy all audio streams and -map 0:a:1 would copy only the first audio stream.

If you have input that may or may not have a stream of that type, append ? at the end (i.e. -map 0:a?).

TypeMatches
vVideo
VVideo except attached pictures, video thumbnails, cover arts
aAudio
sSubtitles
dData
tAttachments
2

Just use "-map 0 -scodec copy" instead of having to specify the [v]ideo, [a]udio, and [s]ubtitles manually with all these options. Works for me.

From the documentation:

For example, to map ALL streams from the first input file to output

ffmpeg -i INPUT -map 0 output

The command I use to convert H.265 videos to H.264 (while leaving the audio and subtitles alone) is:

ffmpeg -i source.mkv -vcodec h264 -acodec copy -scodec copy -map 0 output.mkv

Try it!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like