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.mp4Opens the named video file as the input
-map 0:0declares that we want stream 0 (the video stream) from input 0 included in the output.
-c:v copyEnsures the video stream is simply copied, and not re-encoded. This avoids any quality losses that come with re-encoding. The
:vmeans we are defining the video codec(s).
-afcoming up next is an "audio filter" declaration:
- using the
panaudio filter, create a
stereoaudio stream, by copying the left and right input channels (
c0+c1) to the left output channel (
c0<) and the right output channel (
-map 0:1just 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 aacUse the
aaccodec for audio
video-out.mkvthe output filename. ffmpeg also infers the container format (mkv for Matroska) from the filename.
Add new comment