Body: <p>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.<br>
  I have tried converting both videos beforehand to various formats to try and eliminate a file/codec issue.</p>
  <p>Can someone point me in the right direction?<br>
  Here is my command that works part of the time.<br>
  I am a novice using ffmpeg so this has been a challenge getting this far.</p>
  <p>ffmpeg.exe -y -i &quot;path to main video.mp4&quot; -itsoffset 104 -i &quot;path to pip video.mp4&quot; -filter_complex &quot;[1]scale=iw<em>0.3333:ih</em>0.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]&quot; -map &quot;[v]&quot; -map &quot;[a]&quot; -ac 2 -ar 44100 -vcodec libx264 -acodec aac &quot;.\Output video.mp4&quot;</p>
  <p>Thanks in advance</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-21T04:11:35.007Z
Comments.Text: if you're using `itsoffset`, use `aresample=async=1:first_pts=0` for audio, not adelay.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-21T21:13:34.867Z
Comments.Text: 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"`
Comments.UserDisplayName: Leetmouse
Tags: <ffmpeg>
Title: audio not offset with video in PIP using ffmpeg
UserDisplayName: Leetmouse
ThreadText: # audio not offset with video in PIP using ffmpeg
  
  (Asked by: username_0 on 2024-01-20)
  
  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=iw*0.3333:ih*0.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
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: if you're using `itsoffset`, use `aresample=async=1:first_pts=0` for audio, not adelay.  
  > **username_0**: 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"`  
  
  ---
  
  ## 0 answers
  
  