Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 10 down vote accepted

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.

share|improve this answer
    
Looks like --atracks option does not exist anymore, instead one should use either --audio-tracks or --video-tracks. –  malat Jan 31 at 13:15

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
share|improve this answer
    
This strangely gives me the error: "At least one output file must be specified" –  StackedCrooked Dec 1 '09 at 21:44
    
try using a full path, ie: C:\path\to\output.mkv (I assume you're on windows by the media player reference) –  John T Dec 1 '09 at 22:02
    
@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 Dec 2 '09 at 21:46

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.

share|improve this answer

protected by Sathya Mar 30 at 6:42

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.