Decklink SDK 12.1 / OpenCV

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

Andy Coulthurst

  • Posts: 272
  • Joined: Thu Apr 21, 2016 12:04 pm

Decklink SDK 12.1 / OpenCV

PostThu Sep 30, 2021 2:09 pm

I'm trying to get a few examples running , however it seems some of them have not been updated for SDK 12.1.

Specifically the "Advanced Video Playback and Capture" as well as the "OpenCV examples."

I can get the OpenCV face tracking app to compile ( after changing the HAAR classifier for opencv-4.5.3 ) , and changing the location of the Classifier XML files ( otherwise there is just an unhelpful exception ... ).
I've changed the input mode to 1080p50 for my source signal.

I am using a Quad 2 , and have the InputLoopThrough and the OpenGL examples working.
BUT the OpenCV example appears to capture a single frame and perform face tracking on that single frame. The identified face rectangle is sent to the output SDI - but frame capture stalls.
I don't see a ScheduledFrameCallback event almost as though the output playback hasn't been scheduled.

Any help fixing the OpenCV example would be greatly received. As well as updating the capture example to 12.1.
Last edited by Andy Coulthurst on Sat Oct 02, 2021 6:46 pm, edited 1 time in total.
Offline

Andy Coulthurst

  • Posts: 272
  • Joined: Thu Apr 21, 2016 12:04 pm

Re: Decklink SDK 12.1

PostFri Oct 01, 2021 8:18 am

Replying to myself

So - the OpenCV example seems to have at least one problem it looks like it may be missing the call to enable Output Callbacks

Code: Select all
        if (FAILED(m_deckLinkInput->SetCallback(this)))
                throw std::runtime_error("Could not set callback on input");
        if (FAILED(m_deckLinkOutput->SetScheduledFrameCompletionCallback(this))) // missing ?
                throw std::runtime_error("Could not set callback on output");  // missing ?
        if (FAILED(m_deckLinkInput->StartStreams()))
                throw std::runtime_error("Could not StartStreams");


At least now the "ScheduledFrameCompleted" callback gets executed.
Next problem - pre-roll runs - then we get an sigfault when the callback tries to execute
Code: Select all
     completedFrame->Release();


After the Output has released all the queued output frames.
Offline

Andy Coulthurst

  • Posts: 272
  • Joined: Thu Apr 21, 2016 12:04 pm

Re: Decklink SDK 12.1

PostFri Oct 01, 2021 10:49 am

Okay - the final problem with this app is the case when the input video stream is not bmdFormat8BitYUV.

In that instance - the "Capture::VideoInputFormatChanged" callback is executed - and this blindly stops the streams , changes the format and restarts the streams. BUT because the input format still won't match ( because the code forces the format to be bmdFormat8BitYUV ) - this will get called endlessly.

Solution is to check that if the format change is JUST a colour space change - then ignore it.

Code: Select all
HRESULT Capture::VideoInputFormatChanged(BMDVideoInputFormatChangedEvents e, IDeckLinkDisplayMode* newDisplayMode, BMDDetectedVideoInputFormatFlags f)
{
        const BMDDisplayMode newBMDDisplayMode     = newDisplayMode->GetDisplayMode();
        const BMDPixelFormat pixelFormat           = bmdFormat8BitYUV; // convert input format to bmdFormat8BitYUV
if (e!=bmdVideoInputColorspaceChanged) // ignore changes in colorspace - because we *want* to change the colorspace to bmdFormat8BitYUV
                                        // if the input is not bmdFormat8BitYUV we'll keep getting change notifications and thus we'll keep stopping/restarting
                                        // the streams
        {
        printf("Format changed\n");
                std::lock_guard<std::mutex> lock(m_deckLinkInputMutex);
                CHECK_API(m_deckLinkInput->StopStreams());
                CHECK_API(m_deckLinkInput->EnableVideoInput(newBMDDisplayMode, pixelFormat, bmdVideoInputEnableFormatDetection));
                CHECK_API(m_deckLinkInput->StartStreams());
        }
        return S_OK;
}


Also - I removed the
Code: Select all
     completedFrame->Release();


And because I'm using HD video rather than 4K - I needed to change the size of some on screen fonts.
I would suggest the code needs some more fixes , auto scaling/positioning of the font size and helpful error messages / checks. I'd even suggest getting rid of the whole cmake junk as it just confuses issues.

Anyway - for me I now have a good working example as I suspect it was intended.

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 5 guests