How to Map Only the Second Audio Track in FFmpeg
This article provides a straightforward guide on how to use FFmpeg to select and extract only the second audio track from a media file. You will learn the exact command-line syntax, understand how FFmpeg indexes audio streams, and see practical examples of saving the second audio track as a standalone audio file or multiplexing it with the original video while discarding other audio tracks.
In FFmpeg, stream selection is handled using the -map
option. FFmpeg indexes inputs and streams starting from zero. Therefore:
* 0 represents the first input file. * a
represents audio streams. * 1 represents the second stream
of that type (since indexing starts at 0 for the first
stream).
Using this indexing system, the second audio track of the first input
file is represented as 0:a:1.
Extract Only the Second Audio Track to a New Audio File
To extract only the second audio track and save it as an independent audio file (e.g., MP3, AAC, or WAV) without re-encoding, use the following command:
ffmpeg -i input.mp4 -map 0:a:1 -c:a copy output.mp3Command breakdown: * -i input.mp4:
Specifies the input video or audio file. * -map 0:a:1:
Instructs FFmpeg to only select the second audio track from the first
input file. * -c:a copy: Copies the audio stream directly
without re-encoding, preserving the original quality and processing the
file instantly. * output.mp3: The name of the output audio
file.
Keep the Video and Map Only the Second Audio Track
If you want to output a video file that contains the original video track but only the second audio track (discarding the first audio track), use this command:
ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:1 -c copy output.mp4Command breakdown: * -map 0:v:0:
Selects the first video stream of the input file. *
-map 0:a:1: Selects only the second audio stream. *
-c copy: Copies both the video and audio streams directly
without re-encoding.