Merging video and audio, with audio re-encoding
See this example, taken from this blog entry but updated for newer syntax. It should be something to the effect of:
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4
Here, we assume that the video file does not contain any audio stream yet, and that you want to have the same output format (here, MP4) as the input format.
The above command transcodes the audio, since MP4s cannot carry PCM audio streams. You can use any other desired audio codec if you want. See the FFmpeg Wiki: AAC Encoding Guide for more info.
If your audio or video stream is longer, you can add the -shortest
option so that ffmpeg will stop encoding once one file ends.
Copying the audio without re-encoding
If your output container can handle (almost) any codec – like MKV – then you can simply copy both audio and video streams:
ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv
Replacing audio stream
If your input video already contains audio, and you want to replace it, you need to tell ffmpeg which audio stream to take:
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 output.mp4
The -map
option makes ffmpeg only use the first video stream from the first input and the first audio stream from the second input for the output file.
Using ffmpeg there are several methods that I know of to go from stereo to two individual mono files, or two mono streams in one file:
stereo to 2 mono outputs
ffmpeg -i stereo.wav -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wav
pan
audio filter
ffmpeg -i stereo.wav -filter_complex \
"[0:0]pan=1|c0=c0[left]; \
[0:0]pan=1|c0=c1[right]" \
-map "[left]" left.wav -map "[right]" right.wav
stereo to 2 mono streams
This will create one output file that has two individual mono streams:
ffmpeg -i input.m4a -filter_complex channelsplit out.mka
Also see
Best Answer
The way to "mixdown" from stereo to mono in any supported file in ffmpeg is like so:
The "-ac 1" bit instructs ffmpeg to output just 1 audio channel, i.e. mono. By default, this operation will preserve your file format but will revert your bitrate to the ffmpeg default of 64kbs. If you want a higher bitrate, you can do:
...replacing 192k with your preferred bitrate.
Note that your install of ffmpeg must support your particular GSM codec in order for this to work properly. I know some GSM encoded audio is supported in ffmpeg through libgsm but I have never dealt with GSM files myself. I have successfuly converted other types of files (MP3) to mono without a hitch, however.