adding repeated background audio with ffmpeg [clos

2019-02-01 11:57发布

问题:

With ffmpeg, I see how to add music file as background for a video, but the problem is how to make the audio loop/repeat. Is there a way out?

回答1:

ffmpeg has the promising -loop_input flag, but it doesn't support audio inputs yet.

I'd recommend sox and the -shortest option for ffmpeg as a solution.

sox -i short_audio.mp3 looped_audio.mp3 repeat 1000 # adjust count as necessary
ffmpeg -i input_video.mp4 -i looped_audio.mp3 -shortest output_video.mp4

The sox command will loop the input, and the ffmpeg command will use it for the audio, but stop when it runs out of video to process.



回答2:

A bit late, but I just run into the same problem and managed to do it by using ffmpeg and concatenate filter. Here is an example of how to loop it three times:

ffmpeg -i audio.wav -filter_complex "[0:a]afifo[a0];[0:a]afifo[a1];[0:a]afifo[a2];[a0][a1][a2]concat=n=3:v=0:a=1[a]" -map "[a]" out.wav


标签: audio ffmpeg