DeckLink 4K SDI W7 SDK10.9.5 .Net ConvertFrame Access Violat

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

Lorenzo Pachio

  • Posts: 4
  • Joined: Mon Oct 30, 2017 12:33 pm

DeckLink 4K SDI W7 SDK10.9.5 .Net ConvertFrame Access Violat

PostMon Oct 30, 2017 6:17 pm

Hello,

I am just getting started in the magic [black] world of the blackmagic SDK.
I am trying to embed a live Video input using the native SDK (no directshow).
I am using a Decklink 4K SDI, driver 10.9.5, on Windows 7.
I started from the CapturePreviewCSharp sample project.

My plan was:
- get the Frame using the C# sample out of the box;

- convert from YUV -> RGB in the VideoInputFrameArrived callback
Code: Select all
void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame videoFrame, IDeckLinkAudioInputPacket audioPacket)
        {
            if (videoFrame != null)
            {
                bool inputSignal = videoFrame.GetFlags().HasFlag(_BMDFrameFlags.bmdFrameHasNoInputSource);
                if (inputSignal != m_validInputSignal)
                {
                    m_validInputSignal = inputSignal;
                    InputSignalChanged(m_validInputSignal);
                }

                IDeckLinkMutableVideoFrame dst;
                m_deckLinkOutput.CreateVideoFrame(videoFrame.GetWidth(), videoFrame.GetHeight(),                 
                videoFrame.GetRowBytes(), _BMDPixelFormat.bmdFormat8BitRGBA, _BMDFrameFlags.bmdFrameFlagDefault, out dst);
                IDeckLinkVideoConversion frameConverter = new CDeckLinkVideoConversion();
                frameConverter.ConvertFrame(videoFrame, dst);

Unfortunately I am getting an access violation when I call the frameConverter.ConvertFrame(videoFrame, dst); I check the size of the 2 frames is the same and I couldn't find any info on the net.


- convert to Bitmap; I was thinking to use the following code, but I didn't get this far yet as I get the exception in the previous point:
Code: Select all
IntPtr pointer;
dst.GetBytes(out pointer);
Bitmap bmp = new Bitmap(dst.GetWidth(), dst.GetHeight(), 0, System.Drawing.Imaging.PixelFormat.Format32bppRgb, pointer);

If this is not the way to do it please let me know

- Raise an event with the Bitmap as argument that gets handled in another project (WPF) where the UI lives.

If anybody on the forum can please advise on both the exception and on the IFrameDeckLinkVideoFrame to Bitmap conversion it would be great!

Thanks in advance
PaCO
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: DeckLink 4K SDI W7 SDK10.9.5 .Net ConvertFrame Access Vi

PostTue Oct 31, 2017 7:24 am

Hi Lorenzo,

I did notice one issue in the code, where you are calling CreateVideoFrame(). It is possible that you are not setting rowBytes correct for bmdFormat8BitRGBA Pixel Format (4-bytes per pixel), and as such there is insufficient buffer for ConvertFrame(). Instead try:

Code: Select all
m_deckLinkOutput.CreateVideoFrame(videoFrame.GetWidth(), videoFrame.GetHeight(), (videoFrame.GetWidth() * 4), _BMDPixelFormat.bmdFormat8BitARGB, _BMDFrameFlags.bmdFrameFlagDefault, out dst);


For the Bitmap constructor, I would be setting the 3rd parameter (stride) to dst.GetRowBytes() and the PixelFormat to be Format32bppArgb to match dst pixel format (_BMDPixelFormat.bmdFormat8BitARGB).

Kind Regards
Cameron Nichols
Offline

Lorenzo Pachio

  • Posts: 4
  • Joined: Mon Oct 30, 2017 12:33 pm

Re: DeckLink 4K SDI W7 SDK10.9.5 .Net ConvertFrame Access Vi

PostWed Nov 01, 2017 1:15 pm

Hey Cameron,

your help is really appreciated; thanks to your suggestion I am now able to get frame after frame succesfully as Bitmaps. The only problem is that each bitmap have the colors off, I attached google homepage as a sample of the problem. After running the conversion code (the same posted before with your fix) I get the following details per each frame:
DST Width -> 1920, Height -> 1080, RowBytes -> 7680, PixelFormat -> bmdFormat8BitARGB
the pixelformat looks promising to me. Did I miss something in the conversion or did I forget a step?

Again, I am at the beginning with the SDK so apologies if the answer is straightforward.

Thanks for the help
Lorenzo
Attachments
ColorsOff.JPG
Google Page sample color after conversion
ColorsOff.JPG (32.19 KiB) Viewed 2237 times
Offline

Cameron Nichols

Blackmagic Design

  • Posts: 442
  • Joined: Mon Sep 04, 2017 4:05 am

Re: DeckLink 4K SDI W7 SDK10.9.5 .Net ConvertFrame Access Vi

PostThu Nov 02, 2017 4:45 am

Hi Lorenzo,

It appears that your BGRA pixels are swapped - So Blue <--> Alpha (fixed at 255), Red <--> Green. This is due to the endianess difference between bmdFormat8BitARGB and PixelFormat.

To resolve - convert frame to bmdFormat8BitBGRA pixel format instead.

Kind Regards
Cameron Nichols
Offline

Lorenzo Pachio

  • Posts: 4
  • Joined: Mon Oct 30, 2017 12:33 pm

Re: DeckLink 4K SDI W7 SDK10.9.5 .Net ConvertFrame Access Vi

PostThu Nov 02, 2017 7:39 am

Thanks again Cameron,

I knew was something in the conversion! Working like a charm now!
I am a new blackmagic client and enthusiast, well done shipping the SDK with such a great portfolio of sample projects!

Thanks
Lorenzo

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 14 guests