18

How to remove only one track (not all) from video file container (.vob or .mkv) using ffmpeg?

I know I can just copy video (-c:v copy -an) and specific audio track from container into two separated files and then join them.

But is there an easier way? Can I just remove specific audio track from container? ffmpeg command?

35

The most efficient method is to use negative mapping in the -map option to exclude specific stream(s) while keeping all other streams.

Remove a specific audio stream

ffmpeg -i input -map 0 -map -0:a:2 -c copy output
  • -map 0 selects all streams from the input.
  • -map -0:a:2 then deselects audio stream 3. The stream index starts counting from 0, so audio stream 10 would be 0:a:9.

Remove all audio streams

ffmpeg -i input -map 0 -map -0:a -c copy output
  • -map 0 selects all streams from the input.
  • -map -0:a then deselects all audio streams from the input.

Removing other stream types

If you want to remove other stream types you can use the appropriate stream specifier.

  • v - video, such as -map -0:v
  • a - audio, such as -map -0:a (as shown above)
  • s - subtitles, such as -map -0:s
  • d - data, such as -map -0:d
  • Wow, i didn't know about the negative mapping functionality, awesome! – v010dya Jul 2 '16 at 16:58
  • 2
    Instead of -0:a:1 , to delte the other audio can use -0:a:0 – axsvl77 Feb 14 '18 at 17:40
  • 1
    To delete all audio (and keep video, data, etc.): ffmpeg -i input -map 0 -map -0:a -c copy output Similarly, to delete all video: ffmpeg -i input -map 0 -map -0:v -c copy output – verbamour Mar 29 at 14:46
3

You are looking for -map.

I have changed to using avconv, but it should be about the same.

Let's say you have a file called "input.vob" with one video and two audio tracks; and you want to have "output.vob" with the video and the last audio.

You would do:

avconv -i input.vob -map 0:0 -c:v copy -map 0:2 -c:a copy output.vob

You should notice that:

  1. I did not copy -map 0:1
  2. I did not need to do -an, because there are audio tracks. However, if there are no audio tracks at all, you may need to use such an attribute.
  3. Sometimes the streams are not numbered in the way i've described, for example audio can come before video.
  4. If there are subtitle streams there, you need to figure out how to deal with them as well.

You cannot work on files "in place", you need to save into a different file.

P.S. You may want to ask such questions on video.stackexchange.com next time.

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.