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
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:
-map 0:1
-an
, because there are audio tracks. However, if there are no audio tracks at all, you may need to use such an attribute.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.
You just solved my av1 muxing issue, which requires -map 0 to include the subtitle font from original-video.mkv.
ffmpeg.exe -i original-video.mkv -i svt-av1.ivf -map 0 -map -0:v:0 -map 1:v:0 -c copy output.mkv
-map 0
selects everything, including the subtitle font which is, erroneously, in the wrong stream of the input file. -map -0:v:0
remove all video. -map 1:v:0
re-adds video from second input, which is the re-encoded AV1 of original-video.mkv.
The most efficient method is to use negative mapping in the -map
option to exclude specific stream(s) ("tracks") while keeping all other streams.
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
.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.Keep everything except audio streams #3 and #6:
ffmpeg -i input -map 0 -map -0:a:3 -map -0:a:6 -c copy output
ffmpeg -i input -map 0 -map -0:s -map -0:d -c copy output
This example does not need to use any negative mapping.
ffmpeg -i input -map 0:v -map 0:a -c copy output
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
t
- attachments, such as -map -0:t
Using a stereo input and channelsplit filter. Example to get the right channel only and output a mono audio file:
ffmpeg -i stereo.wav -filter_complex "[0:a]channelsplit=channel_layout=stereo:channels=FR[right]" -map "[right]" front_right.wav
channel_layout
is the channel layout of the input stream. The default is stereo
.
channels
lists the channels to be extracted as separate output streams. The default is all
which extracts each input channel as a separate, individual stream.
See ffmpeg -layouts
for a list of accepted channel layouts (for channel_layout
option) and channel names (for channels
option).
See FFmpeg Wiki: Audio Channels for more examples.