I am trying to create a pip video from two separate sources while keeping the audio from both clips and delaying the pip video x number of seconds. I have successfully done it but sometimes the pip video is delayed/offset the correct time but the audio from the same clip starts immediately at the beginning. if it was consistent, I could debug it further but half the time it offsets properly, other times it doesn't.
I have tried converting both videos beforehand to various formats to try and eliminate a file/codec issue.

Can someone point me in the right direction?
Here is my command that works part of the time.
I am a novice using ffmpeg so this has been a challenge getting this far.

ffmpeg.exe -y -i "path to main video.mp4" -itsoffset 104 -i "path to pip video.mp4" -filter_complex "[1]scale=iw0.3333:ih0.3333 [pip]; [0][pip] overlay=main_w-overlay_w-5:main_h-overlay_h-5[v];[1:a]adelay=104000|104000[a1];[0:a][a1]amerge[a]" -map "[v]" -map "[a]" -ac 2 -ar 44100 -vcodec libx264 -acodec aac ".\Output video.mp4"

Thanks in advance

  • if you're using itsoffset, use aresample=async=1:first_pts=0 for audio, not adelay.
    – Gyan
    Jan 21 at 4:11
  • I took another look at adelay and altered it and it seemed to work fine but I also switched my itsoffset to tpad based on another suggestion. Thanks for the tip, I will give the aresample a look. Here is the current command as of right now. ffmpeg.exe -y -i "main.mp4" -i "pip.mp4" -filter_complex "[1]format=yuva420p,tpad=start_duration=70.5:color=black@0,scale=iw*0.3333:ih*0.3333 [pip]; [0][pip] overlay=main_w-overlay_w-5:main_h/2-overlay_h/2[v];[1:a]adelay=70500:all=true[a1];[0:a][a1]amerge[a]" -map "[v]" -map "[a]" -ac 2 -ar 44100 -vcodec libx264 -acodec aac ".\\Output.mp4"
    – Leetmouse
    Jan 21 at 21:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.