4

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
  • What is the problem with the command you currently have? I suspect you need a -map 0:a? -map 0:s? -map 0:v before your -c:v, but apart from that it looks okay to me. – Mokubai Dec 2 '17 at 22:51
  • Right now it only gets the first audio and first subtitle string. I will attempt with the map option. I read about it, but I couldn't quite understand how to use it. Would it look like this then? ffmpeg -i "01.mkv" -map 0:a? -map 0:s? -map 0:v -c:v copy -c:a ac3 -c:s copy "test.mkv" – Jason Murray Dec 2 '17 at 22:54
  • Look at the answers here if you haven’t already. – Giacomo1968 Dec 2 '17 at 22:56
  • Yes, give that a shot. I'm still getting to grips with ffmpeg myself, but 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. – Mokubai Dec 2 '17 at 23:05
  • Just encoded my test file and it seems to have worked perfectly! Thanks! Now to do the part I have no idea about, which is to write a bash script. But that is for another question. Thanks again! – Jason Murray Dec 2 '17 at 23:07
8

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
  • 4
    A map expression of the form -map x? tells ffmpeg to select all streams matching x but not throw an error if no matching streams are found. Just -map x will select all matching streams. – Gyan Dec 3 '17 at 4:34
2

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?).

Type Matches
v Video
V Video except attached pictures, video thumbnails, cover arts
a Audio
s Subtitles
d Data
t Attachments

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.