Search code examples
ffmpegandroid-ffmpegffmpeg-phppyffmpegsharpffmpeg

ffmpeg aloop filter not working correctlly


I am trying to run FFmpeg Command as follow

-i "v1.mov" -i "0.mp3" -filter_complex "[0:v]trim=0:204,setpts=PTS-STARTPTS[TrimmedVideo];[0:a]atrim=0:204,asetpts=PTS-STARTPTS[TrimmedAudio];[TrimmedVideo]scale=848:360[BackgroundOutput];[1:a]atrim=0:20,asetpts=PTS-STARTPTS,volume=0.37,aloop=1:size=1*48000,adelay=0|0[AudioTrim0];[TrimmedAudio][AudioTrim0]amix=inputs=2:duration=first:dropout_transition=2,volume=2[AudioMixOut];[BackgroundOutput][AudioMixOut]concat=n=1:v=1:a=1[OutputVideo][OutputAudio]" -map [OutputVideo] -map [OutputAudio] -c:v libx264 -c:a aac -b:a 256k -preset ultrafast "ouput.mp4"

in this, I used aloop to loop audio to fill in the video but that audio is not repeating, it played once then stoped


Solution

  • So I found that that problem is in Size Parameter that must be multiplied with the duration of trimmed audio but I used 1x4800 instead of 20x48000 and it solved the problem and final command becomes

    -i "v1.mov" -i "0.mp3" -filter_complex "[0:v]trim=0:204,setpts=PTS-STARTPTS[TrimmedVideo];[0:a]atrim=0:204,asetpts=PTS-STARTPTS[TrimmedAudio];[TrimmedVideo]scale=848:360[BackgroundOutput];[1:a]atrim=0:20,asetpts=PTS-STARTPTS,volume=0.37,aloop=1:size=20*48000,adelay=0|0[AudioTrim0];[TrimmedAudio][AudioTrim0]amix=inputs=2:duration=first:dropout_transition=2,volume=2[AudioMixOut];[BackgroundOutput][AudioMixOut]concat=n=1:v=1:a=1[OutputVideo][OutputAudio]" -map [OutputVideo] -map [OutputAudio] -c:v libx264 -c:a aac -b:a 256k -preset ultrafast "ouput.mp4"