1080i50 output frame rate problem

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Ian Sharpe

  • Posts: 3
  • Joined: Thu Oct 27, 2016 10:32 am

1080i50 output frame rate problem

PostTue Nov 22, 2016 5:05 pm

I am outputting 1080i50 UYVY video through a DeckLink Quad 2 and cannot get the correct transmission rate.

The frames look OK individually, just jerky due to slow output. Using what I think are the correct parameters I am logging 80ms between calls to the output callback. I am expecting one interlaced frame per 40 milliseconds (i.e. 1/25 second).

This is true in a big production project from which I distilled a simple test harness to show the key points. This behaves the same way. These are the key steps of my code - error checking and intermediate fluff removed.

Iterate over the DeckLink devices to get the one I want, then...

Code: Select all
deckLinkOutput->EnableVideoOutput(bmdModeHD1080i50, BMDVideoOutputFlags::bmdVideoOutputFlagDefault);

Code: Select all
deckLinkOutput->DoesSupportVideoMode(bmdModeHD1080i50, bmdFormat8BitYUV, BMDVideoOutputFlags::bmdVideoOutputFlagDefault, &supported, &gDisplayMode);

Code: Select all
gDisplayMode->GetFrameRate(&gFrameDuration, &gTimeScale);

Code: Select all
frameDispatchCompleteCallback = new DeckLinkFrameDispatchCompleteCallback(deckLinkOutput, gFrameDuration, gTimeScale);
(DeckLinkFrameDispatchCompleteCallback is derived from IDeckLinkVideoOutputCallback)
Code: Select all
deckLinkOutput->SetScheduledFrameCompletionCallback(frameDispatchCompleteCallback);

Code: Select all
deckLinkOutput->CreateVideoFrame(1920, 1080, 1920 * 2, bmdFormat8BitYUV, bmdFrameFlagDefault, &frame);

Code: Select all
frame->GetBytes(&pBuffer);

Code: Select all
memset(pBuffer, rand(), 1920 * 1080 * 2);

Code: Select all
deckLinkOutput->ScheduleVideoFrame(frame, 0, gFrameDuration, gTimeScale);

Code: Select all
deckLinkOutput->StartScheduledPlayback(0, gTimeScale, 1.0);


Then I loop / sleep while the callback object re-transmits this same frame over and over:

Code: Select all
HRESULT DeckLinkFrameDispatchCompleteCallback::ScheduledFrameCompleted(
   IDeckLinkVideoFrame* completedFrame,
   BMDOutputFrameCompletionResult result
   )
{
   if (! stopRequest)   // A flag variable set when the main loop detects a keypress to halt the program
   {
      ScheduleNextFrame(completedFrame);

      SYSTEMTIME st;
      GetSystemTime(&st);
      cout << st.wMilliseconds << endl; // 80ms between calls
   }
   return S_OK;
}


Code: Select all
HRESULT DeckLinkFrameDispatchCompleteCallback::ScheduleNextFrame(IDeckLinkVideoFrame* videoFrame)
{
   this->frameCount++;   // Init to 0 in constructor
   BMDTimeValue tv = frameCount * this->gFrameDuration;
   HRESULT hr = m_pDeckLinkOutput->ScheduleVideoFrame(videoFrame, tv, this->gFrameDuration, this->gTimeScale);
   // duration & timescale passed into constructor from set-up code.
   // Came from GetFrameRate and are 1000 & 25000   
   return hr;
}


Anyone know what's wrong?
Offline

Ian Sharpe

  • Posts: 3
  • Joined: Thu Oct 27, 2016 10:32 am

Re: 1080i50 output frame rate problem

PostWed Nov 23, 2016 10:54 am

Answering my own question...

It's the number of pre-rolled frames. Must be > 1. Using 3 and initial results are good.
Offline

Nicholas Gill

Blackmagic Design

  • Posts: 169
  • Joined: Mon May 04, 2015 10:28 pm

Re: 1080i50 output frame rate problem

PostWed Dec 14, 2016 3:32 am

Hi Ian,

Glad to see that you were able to resolve the issue.

Just confirming, the number of frames required for preroll varies based on the device in use. Pre-4k architecture devices require a minimum of three frames provided for preroll, while 4k architecture devices (incl. the DeckLink Quad 2) require a minimum of two frames.

In your original case, it would also be possible to diagnose this situation by inspecting the BMDOutputFrameCompletionResult [1] parameter in the ScheduledFrameCompleted [2] callback, which would indicate that the frames provided for playback with insufficient preroll will be completed as late or dropped, as the frames cannot be filled in time for the transfer to the device.

Please note one common issue encountered when using the SDK samples as reference, is prerolling the same frame multiple times. This is suitable in the SDK SignalGenerator / TestPattern sample applications as the content of the video frames is static.

In normal applications, if the same frame is prerolled multiple times, and the frame buffer is modified (e.g. in the context of ScheduledFrameCompleted, before the frame is scheduled for playback), this will lead to tearing artifacts in the output video, as the buffer is modified while being output by the device.

I recommend always prerolling distinct IDeckLinkVideoFrame instances, in order to avoid these issues.

Cheers,

-nick

[1] 2.7.9 Output Frame Completion Results Flags
[2] 2.5.6.1 IDeckLinkVideoOutputCallback::ScheduledFrameCompleted method
Offline

PANNAGENDRA

  • Posts: 5
  • Joined: Mon Jan 22, 2018 4:23 am
  • Real Name: Pannagendra Bhat

Re: 1080i50 output frame rate problem

PostTue Apr 17, 2018 2:16 am

Hi

we are displaying YUV file with dynamic data. Each frame has different data.
Our input has 100 frames. We are reading from PC and diplaying YUV file of 4k resolution 422 10bit.
Do we need to create "distinct IDeckLinkVideoFrame instances, in order to avoid these issues"?
If yes then with default allocator we can create only 35 frames for 4K resolution.
To check the above behaviour, we created the chunk of 35 frame buffers in the same code.
we could iterate only 2 times. In the second iteration after 64th frame the first frame is repeating.
Please let us know your opinion on the same.

If we use custom allocator we can create 100 IDeckLinkVideoFrame instances however after 64th frame first frame data will be repeated.
Please let us know your opinion on this.
Offline

PANNAGENDRA

  • Posts: 5
  • Joined: Mon Jan 22, 2018 4:23 am
  • Real Name: Pannagendra Bhat

Re: 1080i50 output frame rate problem

PostFri Apr 20, 2018 9:20 am

Hi,

Issue we were facing for dynamic data is resolved now.

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 1 guest