I have an initially undefined number of input mono audio files (.wav) that I want to merge into a single stereo output audio file (.mp3), so that one of the input files goes into left channel, and all the remaining input files are joined into the right channel.
I have seen https://trac.ffmpeg.org/wiki/AudioChannelManipulation#a2monostereo of how to do it for 2 input files only, not sure how it should be changed when dealing with 2+ input files though?
At the end of the day I want to do it using the ffmpeg-python library. Right now I have this which is working fine for 2 ffmpeg_inputs:
(
ffmpeg.filter(
ffmpeg_inputs,
filter_name="join",
inputs=len(ffmpeg_inputs),
channel_layout="stereo",
)
.output(tmp_output_file.name)
.run(overwrite_output=True)
)
but as soon as more than 2 ffmpeg_inputs are passed, the extra ones do not end up in the output file. Guess it needs some fancy mapping, similar to the raw ffmpeg command above.
You can first create an input streams.
inputs = [ffmpeg.input(f) for f in input_files]
Mix all but the first into one right-channel stream
right_mix = ffmpeg.filter([inp.audio for inp in inputs[1:]], 'amix', inputs=len(inputs)-1, normalize=0)
Then, Join left (first file) and right (mixed)
stereo = ffmpeg.filter([inputs[0].audio, right_mix], 'join', inputs=2, channel_layout='stereo')
output
(ffmpeg.output(stereo, output_file).run(overwrite_output=True))
This combines the first input as the left channel and mixes all remaining inputs into the right channel. Hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With