Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 465
Dipesh Avatar asked Jan 18 '13 23:01

Dipesh


2 Answers

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.

like image 136
Lore Avatar answered Sep 22 '22 18:09

Lore


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!

like image 44
d33pika Avatar answered Sep 19 '22 18:09

d33pika