How to merge two uncertain audio files, which may be mono or stereo, into one stereo file using FFmpeg?
Solution 1:
-
Get duration of each input with
ffprobe
to determine which audio is shortest. - Convert each input to mono with the aformat filter.
- Apply the apad filter to the shorter input.
- Join multiple input streams into one multi-channel stream with the join filter.
Example:
ffmpeg -i input0 -i input1 -filter_complex "[0:a]aformat=channel_layouts=mono:sample_rates=44100,apad[a0];[1:a]aformat=channel_layouts=mono:sample_rates=44100[a1];[a0][a1]join=inputs=2:channel_layout=stereo[a]" -map "[a]" output
Also see FFmpeg Wiki: Audio Channels.