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:08Is 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:08Thanks
12 Answers
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 copywill 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 outputUsing 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:vwill map all video streams from input 0 (ffmpegstarts counting from 0, so 0 is the first input, and the only input in your case).-map 0:a:0will 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 0will map all streams from input 0.-map -0:a:1will exclude the second audio stream from input 0.
You can use the stream specifiers to select a stream type and a particular stream. More info here...
1