I want to replace the second audio stream (0:2) in a video file that has two audio streams and give it a label if possible. How would I go about this? All the ffmpeg commands I found won't let me keep the second audio stream.
How to replace an audio stream in a video file with multiple audio streams
audioffmpegstreaming
Best Answer
Use the
-map
option to choose your streams. Default stream selection will only choose one of each stream type, so that is why-map
has to be used.Replace second audio stream
0:v
– The0
refers to the first input which isvideo.mkv
. Thev
means "select video stream type".0:a:0
– The0
refers to the first input which isvideo.mkv
. Thea
means "select audio stream type". The last0
refers to the first audio stream from this input. If only0:a
is used, then all video streams would be mapped.1:a
– The1
refers to the second input which isaudio.mp3
. Thea
means "select audio stream type".-codec copy
will stream copy (re-mux) instead of encode. If you need a specific audio codec, you should specify-c:v copy
(to keep the video) and then, for example,-c:a libmp3lame
to re-encode the audio stream to MP3.-shortest
will end the output when the shortest input ends.Combine two audio streams into one
amerge
filter is used here, so the audio can not be stream copied in this example.