Converting audio in a video file to mono
One day I'll wish I saved this tip somewhere I could find it... so here it is.
I had a video file which had a stereo audio stream in it, but there was only audio on the left channel of that stream. I wanted to convert that mono-in-left-channel-only stream to pseudo-mono-in-both-channels (ie, copy the left channel into both the left and right channels.
This is the sort of stuff that ffmpeg does before breakfast. What we are doing is "re-mux"ing (which is to say we re multiplex the video and audio streams together into a new container).
ffmpeg -i input-video.mp4 -map 0:0 -c:v copy -af "pan=stereo|c0<c0+c1|c1<c0+c1" -map 0:1 -c:a aac output-video.mkv
One could easily use any other container format (or audio codec), I just chose mkv and aac because the former is very flexible and the latter is quite compatible.
Breakdown of the options:
-i input-video.mp4
Opens the named video file as the input-map 0:0
declares that we want stream 0 (the video stream) from input 0 included in the output.-c:v copy
Ensures the video stream is simply copied, and not re-encoded. This avoids any quality losses that come with re-encoding. The-c
is thecodec
,:v
means we are defining the video codec(s).-af
coming up next is an "audio filter" declaration:pan=stereo|c0<c0+c1|c1<c0+c1
- using the
pan
audio filter, create astereo
audio stream, by copying the left and right input channels (c0+c1
) to the left output channel (c0<
) and the right output channel (c1<
).
-map 0:1
just like mapping the video stream above, here we instruct it to include stream#1 (the audio stream) from input file 0 and map it to the output.-c:a aac
Use theaac
codec for audiovideo-out.mkv
the output filename. ffmpeg also infers the container format (mkv for Matroska) from the filename.
Add new comment