Answers.Body: <p>I figured it out, I just needed to add <code>-video_pts reference</code> to change the timestamp source. I also needed to add <code>-itsoffset -0.4</code> to remove the constant delay between the video and audio.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-11T20:52:20.933Z
Answers.LastActivityDate: 2022-11-11T20:52:20.933Z
Answers.UserDisplayName: sling jones
Body: <p>I'm using ffmpeg to record NTSC analog video on Linux Fedora 36 using a Blackmagic Intensity Pro 4K for video and a Scarlett 2i2 for audio. I'm using a TBC to avoid dropped frames and to ensure a constant S-Video Y/C framerate on the analog end.</p>
  <p>The problem I'm running into is that on playback the audio will start out relatively in sync with the video at the beginning of the captured file but will eventually run ahead of the video eventually becoming many seconds off.</p>
  <p>Nothing I do seems to change this or change the degree to which it happens. The audio and video stay in sync throughout the entire video as I'm monitoring the source so I don't understand how they can diverge so much once encoded into a digital file?</p>
  <p>Here is the command I am using:</p>
  <pre><code>ffmpeg -hwaccel cuda -fflags +igndts -format_code ntsc -f decklink -raw_format auto -vsync passthrough -rtbufsize 1500M -thread_queue_size 512 -i 'Intensity Pro 4K' -f pulse -rtbufsize 500M -thread_queue_size 512 -i 'Scarlett 2i2 Camera Analog Stereo' -c copy -map 0:1 -map 1:0 &quot;/tmp/ffmpeg-raw/file-raw.avi&quot;
  </code></pre>
  <p>here's the ffprobe output from one of my files:</p>
  <pre><code>Input #0, avi, from 'test2-raw.avi':
    Metadata:
      software        : Lavf59.33.100
    Duration: 00:11:42.87, start: 0.000000, bitrate: 169341 kb/s
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 720x486, 167801 kb/s, 59.94 fps, 59.94 tbr, 59.94 tbn
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 2 channels, s16, 1536 kb/s
  </code></pre>
  <p>As you can see in my code snippet, I've been throwing things at the wall for a bit. I've tried different rtbufsizes, adding -copyts, and going through the different -vsync options. I've tried it with and without hardware acceleration ( I do have a NVIDIA card), +igdts did get rid of a warning but did not help with the sync, as did changing the thread queue sizes.</p>
  <p>OBS can do this, why can't I?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-11-02T04:26:59.400Z
Comments.Text: Don't save to AVI - use MKV or NUT.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-11-04T15:24:42.173Z
Comments.Text: Tried MKV and NUT and both have the same issue.
Comments.UserDisplayName: sling jones
Tags: <ffmpeg><video-recording><video-capture><blackmagic><analog>
Title: ffmpeg recording audio / video sync issues
UserDisplayName: sling jones
ThreadText: # ffmpeg recording audio / video sync issues
  
  (Asked by: username_0 on 2022-11-02)
  
  I'm using ffmpeg to record NTSC analog video on Linux Fedora 36 using a Blackmagic Intensity Pro 4K for video and a Scarlett 2i2 for audio. I'm using a TBC to avoid dropped frames and to ensure a constant S-Video Y/C framerate on the analog end.
  
  The problem I'm running into is that on playback the audio will start out relatively in sync with the video at the beginning of the captured file but will eventually run ahead of the video eventually becoming many seconds off.
  
  Nothing I do seems to change this or change the degree to which it happens. The audio and video stay in sync throughout the entire video as I'm monitoring the source so I don't understand how they can diverge so much once encoded into a digital file?
  
  Here is the command I am using:
  
  ```
  ffmpeg -hwaccel cuda -fflags +igndts -format_code ntsc -f decklink -raw_format auto -vsync passthrough -rtbufsize 1500M -thread_queue_size 512 -i 'Intensity Pro 4K' -f pulse -rtbufsize 500M -thread_queue_size 512 -i 'Scarlett 2i2 Camera Analog Stereo' -c copy -map 0:1 -map 1:0 "/tmp/ffmpeg-raw/file-raw.avi"
  
  ```
  
  here's the ffprobe output from one of my files:
  
  ```
  Input #0, avi, from 'test2-raw.avi':
    Metadata:
      software        : Lavf59.33.100
    Duration: 00:11:42.87, start: 0.000000, bitrate: 169341 kb/s
    Stream #0:0: Video: rawvideo (UYVY / 0x59565955), uyvy422, 720x486, 167801 kb/s, 59.94 fps, 59.94 tbr, 59.94 tbn
    Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, 2 channels, s16, 1536 kb/s
  
  ```
  
  As you can see in my code snippet, I've been throwing things at the wall for a bit. I've tried different rtbufsizes, adding -copyts, and going through the different -vsync options. I've tried it with and without hardware acceleration ( I do have a NVIDIA card), +igdts did get rid of a warning but did not help with the sync, as did changing the thread queue sizes.
  
  OBS can do this, why can't I?
  
  **Tags:** ffmpeg, video-recording, video-capture, blackmagic, analog
  
  > **Comments:**
  > **username_1**: Don't save to AVI - use MKV or NUT.  
  > **username_0**: Tried MKV and NUT and both have the same issue.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-11-11. Score: 0 | Accepted answer
  
  I figured it out, I just needed to add `-video_pts reference` to change the timestamp source. I also needed to add `-itsoffset -0.4` to remove the constant delay between the video and audio.
  
  
  ---
  
  