8

I've got an video file with two audiostreams:

Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 960x540, 58 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
Metadata:
  creation_time   : 2012-07-21 06:10:08
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 164 kb/s
Metadata:
  creation_time   : 2012-07-21 06:10:08
Stream #0:2(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 640 kb/s
Metadata:
  creation_time   : 2012-07-21 06:10:08

Is there a way to disable only one of them? What I actually need is to get a such file:

Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 960x540, 58 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 180k tbc
Metadata:
  creation_time   : 2012-07-21 06:10:08
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 164 kb/s
Metadata:
  creation_time   : 2012-07-21 06:10:08

Thanks

1

2 Answers 2

17

Stream selection

By default ffmpeg stream selection will only map one stream per stream type based upon the following criteria:

  • video – the stream with the highest resolution
  • audio – the stream with the most channels
  • subtitles – the first subtitle stream

In the case where several streams of the same type rate equally the stream with the lowest index is chosen.

Using the -map option will override this behavior as shown below.

Example 1: Explicit mapping

Tell ffmpeg exactly what streams you want by referring to the input stream indexes:

ffmpeg -i input -map 0:1 -map 0:2 -c copy output
  • -c copy will stream copy (re-mux) each mapped stream instead of re-encoding.

Or use stream specifiers:

ffmpeg -i input -map 0:v -map 0:a:0 -c copy output
  • Using the stream specifiers is more flexible because you don't have to know the exact stream index, and it can help prevent accidental mappings such as attempting to map video to an audio-only format

  • -map 0:v will map all video streams from input 0 (ffmpeg starts counting from 0, so 0 is the first input, and the only input in your case).

  • -map 0:a:0 will map the first audio stream from input 0.

Example 2: Negative mapping

Tell ffmpeg to map everything, then choose what to exclude:

ffmpeg -i input -map 0 -map -0:a:1 -c copy output
  • -map 0 will map all streams from input 0.

  • -map -0:a:1 will exclude the second audio stream from input 0.

1

You can use the stream specifiers to select a stream type and a particular stream. More info here...

http://ffmpeg.org/ffmpeg.html#Stream-specifiers-1

1
  • -a <n> is not a valid stream specifier.
    – slhck
    Dec 6, 2014 at 9:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .