<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    Hi,<br>
    <br>
    My advice is to buy a more premium capture card for what you are
    trying to achieve.<br>
    Clocks drift over time and you will see this as the next issue.<br>
    <br>
    You should get NV12 or YV12 and raw PCM audio direct from a premium
    capture card, ready for encode.<br>
    Timestamps will be provided by hardware in sync and will not drift.<br>
    <br>
    Try a Datapath VisionLC capture card instead of paying for a
    developer. It's SDK has an example for saving video files to disk.<br>
    <br>
    <br>
    <div class="moz-cite-prefix">On 20/08/2022 21:55, Reynolds Kosloskey
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:a733cf28-df86-2fd4-47bf-33a52d2d50ce@kosloskey.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <blockquote type="cite"
        cite="mid:4b9b73c0-05f9-47ab-be6c-3c691ba12f4d@email.android.com">
        <div dir="auto">
          <div>
            <div class="gmail_extra">On 19 Aug 2022 19:22, Reynolds
              Kosloskey <a class="moz-txt-link-rfc2396E"
                href="mailto:reynolds@kosloskey.com"
                moz-do-not-send="true"><reynolds@kosloskey.com></a>
              wrote:<br type="attribution">
              <div class="gmail_quote">
                <blockquote class="quote" style="margin:0 0 0
                  .8ex;border-left:1px #ccc solid;padding-left:1ex">
                  <div>
                    <p>Hello all!</p>
                    <p>I am working on a hobby project that does the
                      following:</p>
                    <ul>
                      <li>captures video frames from a capture card</li>
                      <li>captures audio from same capture card</li>
                      <li>decodes audio (video is already raw frame
                        data)<br>
                      </li>
                      <li>encodes that video and audio into a new file</li>
                    </ul>
                    <p>My problems:</p>
                    <ul>
                      <li>Resulting audio and video are heavily out of
                        sync<br>
                      </li>
                      <li>Resulting file is not playable if recording
                        for longer than X seconds</li>
                    </ul>
                    <p>I am willing to pay for assistance in finding out
                      why these issues happen, and to help educate me on
                      the fixes in the process.</p>
                    <p>If anyone is interested, please reach out to me
                      with rate requirements.</p>
                  </div>
                </blockquote>
              </div>
            </div>
          </div>
        </div>
      </blockquote>
      <div class="moz-cite-prefix">On 8/20/2022 2:59 AM, <a
          class="moz-txt-link-abbreviated moz-txt-link-freetext"
          href="mailto:richard.lince@bluebox.video"
          moz-do-not-send="true">richard.lince@bluebox.video</a> wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:4b9b73c0-05f9-47ab-be6c-3c691ba12f4d@email.android.com">
        <meta http-equiv="content-type" content="text/html;
          charset=UTF-8">
        <div dir="auto">
          <div>Hi, is the AV out of sync by a constant or does it drift
            further over time?</div>
        </div>
      </blockquote>
      <p>The A/V starts out of sync, I do not know if it would drift
        further out of sync over time because I can only successfully
        get small lengths of video to encode to playable files so far.<br>
      </p>
      <blockquote type="cite"
        cite="mid:4b9b73c0-05f9-47ab-be6c-3c691ba12f4d@email.android.com">
        <div dir="auto">
          <div>
            <div>What information do you have on your timestamps?<br>
            </div>
          </div>
        </div>
      </blockquote>
      Coming up with a proper methodology for setting timestamps is
      likely one of the keys to a solution.  It would likely be easier
      to see how the timestamps are being affected by looking at the
      code, which I have attached.<br>
      <blockquote type="cite"
        cite="mid:4b9b73c0-05f9-47ab-be6c-3c691ba12f4d@email.android.com">
        <div dir="auto">
          <div>
            <div>
              <div dir="auto">What format is the audio on the wire for
                you to have to decode it?</div>
            </div>
          </div>
        </div>
      </blockquote>
      <p>The audio on the wire is EAC3.  I do not technically have to
        decode it.  The reason I did is that I did not know how to
        package the raw stream into the new file.  So what I do is
        decode it such that I would then have raw audio frames to
        encode.</p>
      <p>---</p>
      <p>The program  basics:</p>
      <p>A Magewell Capture card receives audio and video via an HDMI
        port.  The Magewell SDK is used to expose the video and audio. 
        The video is exposed as raw frames, the audio is received as a
        raw stream.</p>
      <p>The video presents the easier problem.  I use a time_base of
        1/1000 second (millisecond).  I convert the frame to YUV, then
        encode it with a pts equal to the number of milliseconds since
        the start of encoding.</p>
      <p>With the audio, I feed audio data to the decoder until it
        "locks" on a codec.  Once a codec is detected, I use that to set
        the output codec number of channels.  I then use <b>av_packet_rescale_ts</b>
        to adjust the time stamp.</p>
      <p>Because the audio decoder calls callbacks to get new audio
        data, as opposed to me feeding it directly as data is available,
        I use a circular (ring) buffer to hold the data when it arrives,
        then peel off data from that buffer on the decoder callbacks.</p>
      <p>Unless one has the Magewell hardware and SDK, they cannot
        actually debug and test this stuff.  I appreciate any feedback
        (I am not strong on C++), but as I said earlier, happy to pay
        for assistance with this.</p>
      <p><b>---source code attached----</b><br>
      </p>
      <p>--Reynolds<br>
      </p>
    </blockquote>
    <br>
    <div class="moz-signature"><font size="2" face="calibri"
        color="black">
        Best Regards,<br>
        Richard Lince,<br>
        Founder & Managing Director<br>
        <br>
        <a href="https://www.bluebox.video">bluebox.video</a> <br>
        +44(0)7841665146<br>
      </font><br>
      <img alt="logo" src="cid:part1.aUynM0ai.59m1Hf7w@bluebox.video"></div>
  </body>
</html>