How to disable non-1st Audio Streams/Tracks in FFmpeg for mp4 files
Asked Answered
D

3

9

My end goal is to create a single FFmpeg command that will convert my h264.DTS.mkv files to a format that is compatible with my AppleTV, whilst preserving the original quality.

I'm almost there, however I have not been able to figure out how to disable streams/tracks.

So far I have got:

ffmpeg -i FILE \
 -y -strict experimental \
 -map 0:0 -map 0:1 -map 0:1 -map 0:1 -map 0:2 \
 -c:0 copy -c:1 aac -ac:a 2 -c:2 ac3 -ac:a 6 -c:3 copy -c:4 mov_text \
 OUTPUT

This produces an output file that looks like:

  1. H264 video track (enabled) [copied from original]
  2. AAC 2 channel audio track (enabled)
  3. AC3 6 channel audio track (enabled)
  4. DTS 6 channel audio track (enabled) [copied from original]
  5. subtitle track (enabled)

The problem is I need it to look like:

  1. 1 H264 video track (copied from original) (enabled)
  2. 1 AAC 2 channel audio track (enabled)
  3. 1 AC3 6 channel audio track (disabled)
  4. 1 DTS 6 channel audio track (copied from original) (disabled)
  5. 1 subtitle track (enabled)

Hence I need to know how I can disable the non-1st Audio Streams/Tracks.

From what I have read, this is part of the track header atom at the location "tkhd.flags". But I have not been able to figure out how to set this via command line arguments.

Any help would be greatly appreciated.

Dekaliter answered 18/1, 2013 at 23:17 Comment(0)
P
8

Hello Dipesh this will solve your problem.

The Problem

What you seek to accomplish is to flag which audio stream will be default, while negating this flag on all undesired audio streams. This solution will be similar when attempting to select which (if any) subtitle track will be default and/or possibly forced.

The Generic Solution

FFmpeg will automatically flag all streams to default without user intervention. Therefore we first need to flag all streams -default and then flagdefault the one desired as default. Let us use an audio stream for the example.

-disposition:a -default -disposition:a:0 default

The result of the statement above flags all audio streams -default and the first audio stream to default.

Details on its use can be found in the FFmpeg Documentation under 5.4 Main options.

The Specific Solution

ffmpeg -i FILE \
 -y -strict experimental \
 -map 0:0 -map 0:1 -map 0:1 -map 0:1 -map 0:2 \
 -c:0 copy -c:1 aac -ac:a 2 -c:2 ac3 -ac:a 6 -c:3 copy -c:4 mov_text \
 -disposition:a -default -disposition:a:0 default \
 OUTPUT

In the solution -disposition:a -default flags all audio streams in the output file to not default. While -disposition:a:0 default flags the first audio stream in the output file to default.

Postwar answered 16/12, 2016 at 17:23 Comment(0)
O
2

Did you check this: http://ffmpeg.org/trac/ffmpeg/wiki/How%20to%20use%20-map%20option Just don't copy the streams that you do not need to the output.

ffmpeg -i FILE \
 -y -strict experimental \
 -map 0:0 -map 0:1 -map 0:4 \
 -c:0 copy -c:1 aac -ac:a 2 -c:4 mov_text \
 OUTPUT

I hope I got yout question correctly!

Owing answered 21/1, 2013 at 9:40 Comment(2)
I think you have misunderstood, I need all the above listed output streams however, with some of the audio streams disabled.In a mp4 container, one of the possible stream headers is "disabled". A disabled stream is still playable, however a player will not play it by default, it requires the user to switch to that stream. One example use for this stream is different language audio tracks in a stream. In my case I am using this functionality to have multiple quality audio streams.Dekaliter
Which audio stream does the player play by default? Does it not pick the first one? In that case, is that not what you want?Owing
W
0

Disable audio track does not mean remove it completely.

see the picture

enter image description here

Wrongdoer answered 9/5, 2016 at 4:31 Comment(1)
What is the picture supposed to show (Since it is in Russian) and how does this answer the question?Transition

© 2022 - 2024 — McMap. All rights reserved.