How to strip audio streams from an MKV file?

16

9

I've been trying to remove unneeded audio streams from an MKV (Matroska) file. The reason why I want to do this is to avoid having to manually select the wanted stream in Windows Media Player.

The input file gives the following ffmpeg info:

Stream #0.0: Video: mpeg4, yuv420p, 704x396 [PAR 1:1 DAR 16:9], 29.98 tbr, 1k tbn, 29.98 tbc
Stream #0.1(eng): Audio: aac, 24000 Hz, 5.1, s16
Stream #0.2(jpn): Audio: aac, 24000 Hz, 5.1, s16
Stream #0.3(eng): Subtitle: 0x0000
Stream #0.4(eng): Subtitle: 0x0000
Stream #0.5: Attachment: 0x0000
Stream #0.6: Attachment: 0x0000

Since I want streams 0, 1 and 3 (sub), my ffmpeg command looks like this:

ffmpeg -i input.mkv -map 0:0 -map 0:1 -map 0:3 -vcodec copy -acodec libmp3lame -newsubtitle test.mkv

which strangely gives the error:

At least one output file must be specified

Removing the subtitles:

ffmpeg -i input.mkv -map 0:0 -map 0:1 -vcodec copy -acodec libmp3lame test.mkv

gives me this:

Number of stream maps must match number of output streams

I seems I don't really understand how the "map" option works. Would someone help me figure it out?

StackedCrooked

Posted 2009-12-01T19:48:30.003

Reputation: 2 525

Answers

25

If all you want to do is remove a stream, not re-encode, you probably want to do this with the MKVtoolnix package (see videohelp.com's page).

There are a couple of GUIs that may help you (check around on the videohelp link). I'm not sure what the exact mkvmerge commandline might be, but I think something like this would work:

# first, get audio track info so we know which one to keep
mkvmerge -i input.mkv
File 'input.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AAC)
Track ID 3: audio (A_AAC)        <----------- for example, let's keep this one
Track ID 4: audio (A_AAC)

mkvmerge -o output.mkv --atracks 3 input.mkv

That should do the trick (I don't have a file handy for testing, sorry). The --atracks option tells mkvmerge to copy only the listed audio tracks to the new file. If you wanted to keep 2 & 3 but not 4, you could use --atracks 2,3.

mkvmerge has a lot of other options for setting titles, adding a delay to sync audio, etc, so check the manpage for details.

quack quixote

Posted 2009-12-01T19:48:30.003

Reputation: 37 382

5Looks like --atracks option does not exist anymore, instead one should use either --audio-tracks or --video-tracks. – malat – 2015-01-31T13:15:27.653

0

There are really two separate issues here:

  1. In the first command line, the order of parameters may be wrong. I think the -newaudio switch needs to be at the end, after the output file name.

  2. The second command line, "Removing the subtitles", since the input file has subtitles, you need to use the -sn switch to remove them. Otherwise, it seems FFmpeg wants at least one specified in the -map list.

user57355

Posted 2009-12-01T19:48:30.003

Reputation: 1

0

Try -f to force the specified format:

ffmpeg -i input.mkv -map 0:0 -map 0:1 -map 0:3 -vcodec copy -acodec libmp3lame -newsubtitle -f mkv test.mkv

John T

Posted 2009-12-01T19:48:30.003

Reputation: 149 037

This strangely gives me the error: "At least one output file must be specified" – StackedCrooked – 2009-12-01T21:44:01.563

try using a full path, ie: C:\path\to\output.mkv (I assume you're on windows by the media player reference) – John T – 2009-12-01T22:02:28.907

@John T: using the full path (with or without quotes) still gives me the "At least one output file must be specified" error message. – StackedCrooked – 2009-12-02T21:46:58.937

0

In your first command, you didn't specify that test.mkv was your output file. Looks like you need to change that part to be something like ... -c copy test.mkv or specify the codec like ... -c:s copy test.mkv.

And not sure what that -newsubtitle flag is doing in there. But if you have a subtitles file you want to add in, you should be able to do another input flag -i input.srt. See this link for that.

In your second command, I think it looks like you are trying to map the video stream and trying to copy it. So you might want to try removing the -vcodec copy instruction and it should just work. :)

Chef Pharaoh

Posted 2009-12-01T19:48:30.003

Reputation: 161

1

There is no l stream specifier.

– llogan – 2015-06-17T00:15:31.840