Page 1 of 1

Getting Video Output in C# Through SDK - Trying IDeckLinkDX9

PostPosted: Fri Sep 02, 2016 3:37 pm
by AndrewSinger

I'm still trying to get a preview video stream in C#, but am in the same place with the DirectX PreviewHelper (IDeckLinkDX9ScreenPreviewHelper) as I am with the GL Helper (viewtopic.php?f=12&t=51423&sid=a7550db6d8f9f8ae3712923afa9f67bb#p297128).

I've got a DX9 sample together (using SharpDX), but it just shows a black window. The sample for that is below.

Interestingly, however, if I draw a white triangle on the dx scene, then it will show both the target rect and the triangle with a color that's currently in the feed (image attached) which will change as the source changes, though is still only a single color from the feed. Can attach code for that too, in case it's helpful.

Would be very appreciative of any pointers on this path or to see any functional video output from the card through C# (the DirectShow example crashes the system it's run on, so that path unfortunately isn't open). If it just won't work in C# though, knowing that would help me too.


Code: Select all
class simpleBMDXTest : IDeckLinkInputCallback, IDeckLinkScreenPreviewCallback
        private IDeckLink m_deckLink;
        private IDeckLinkInput m_deckLinkInput;
        private Device device;
        private RenderForm form;
        private Direct3D direct3D;
        public static IDeckLinkDX9ScreenPreviewHelper m_DeckLinkDX9ScreenPreviewHelper;

        private int frameCount = 0;
        private bool dxInitialized;

        public unsafe simpleBMDXTest()

            PresentParameters pp = new PresentParameters()
                BackBufferFormat = Format.Unknown,
                BackBufferCount = 2,
                Windowed = true,
                SwapEffect = SwapEffect.Discard,
                PresentationInterval = PresentInterval.Default

            m_DeckLinkDX9ScreenPreviewHelper = new CDeckLinkDX9ScreenPreviewHelper();

            direct3D = new Direct3D();
            form = new RenderForm("BlackMagic DX9 Render Test Form");
            form.Size = new Size(650, 650);

            device = new Device(direct3D, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded, pp);
            device.Viewport = new RawViewport() { Height = 650, Width = 650, X = 0, Y = 0 };

            var ptr = device.NativePointer;

            var tagRect = new tagRECT()
                top = 10,
                left = 10,
                right = 400,
                bottom = 400

            RenderLoop.Run(form, () =>




        private void InitializeBlackMagicDevice()
            IDeckLink m_deckLink;
            IDeckLinkIterator deckLinkIterator = new CDeckLinkIterator();
            deckLinkIterator.Next(out m_deckLink);

            m_deckLinkInput = (IDeckLinkInput)m_deckLink;

            m_deckLinkInput.EnableVideoInput(_BMDDisplayMode.bmdModeHD720p5994, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault);

        void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)


        void IDeckLinkInputCallback.VideoInputFrameArrived(IDeckLinkVideoInputFrame video, IDeckLinkAudioInputPacket audio)

        void IDeckLinkInputCallback.VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents e, IDeckLinkDisplayMode m, _BMDDetectedVideoInputFormatFlags f)


Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostPosted: Tue Sep 06, 2016 4:31 pm
by Carlos Filipe
Hi Andrew,
I'm using VS 2010 and I choose aForge 2.2.5 library, it's working fine...
Well, using VB.Net but is the same thing as C#
However, only a few HDMI input formats are working, like:
- 576i25 (720x576 - PAL i)
- 576p50 (720x576 - PAL)
- 720p50 (1280x720)
- 1080i25 (1920x1080 i)

I made a broadcasting software with scrolling messages and banners
If you need it I can send it to you, it's an evaluation version but you can see the picture, only a message on the screen comes with this version.

Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostPosted: Mon Feb 20, 2017 3:35 pm
by vijay.meganathan
Do you have sample solution?

Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostPosted: Wed Mar 15, 2017 6:29 pm
by Philippe Beau
Dear All,

Do you arrive to have working with aForge 2.2.5 ? VideoCapture is not working with VS 2015/2017 and aForge 2.2.5. But working with aForge 2.2.4 :(

Any idea ?



Re: Getting Video Output in C# Through SDK - Trying IDeckLin

PostPosted: Sun Oct 08, 2017 10:01 am
by Salem Jabri
Hi Andrew.
I am having the same problem.
No video being displayed.
Did you find a solution?
Code: Select all
using System;
using System.Drawing;
using System.Windows.Forms;
using DeckLinkAPI;
using Direct3D = Microsoft.DirectX.Direct3D;

namespace CapturePreviewCSharp
    public partial class PreviewWindow : Control, IDeckLinkScreenPreviewCallback
        private IDeckLinkDX9ScreenPreviewHelper m_previewHelper;
        private string                          m_timeCodeString;

        private Direct3D.Device                 m_d3DDevice;
        private Direct3D.Font                   m_d3DFont;
        tagRECT rect;
        public PreviewWindow()
            m_previewHelper = new CDeckLinkDX9ScreenPreviewHelper();

        public void InitD3D()
            var d3dpp = new Direct3D.PresentParameters();
            d3dpp.BackBufferFormat = Direct3D.Format.Unknown;                   
            d3dpp.BackBufferCount = 2;
            d3dpp.Windowed = true;
            d3dpp.SwapEffect = Direct3D.SwapEffect.Discard;
            d3dpp.DeviceWindow = this;
            d3dpp.PresentationInterval = Direct3D.PresentInterval.Default;

            m_d3DDevice = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.HardwareVertexProcessing | Direct3D.CreateFlags.MultiThreaded, d3dpp);

            m_d3DDevice.DeviceReset += device_DeviceReset;
            device_DeviceReset(m_d3DDevice, null);



        void device_DeviceReset(object sender, EventArgs e)
            System.Drawing.Font systemfont = new System.Drawing.Font(FontFamily.GenericMonospace, 14f, FontStyle.Regular);
            m_d3DFont = new Microsoft.DirectX.Direct3D.Font(m_d3DDevice, systemfont);

        protected override void OnPaint(PaintEventArgs e)

        void Render()
            m_d3DDevice.Clear(Direct3D.ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);

            rect = new tagRECT();
   = 0;
            rect.left = 0;
            rect.bottom = 1080;
            rect.right = 1920;


            m_previewHelper.Render(ref rect);


            // Draw the timecode top-center with a slight drop-shadow
            Rectangle rc = m_d3DFont.MeasureString(null, m_timeCodeString, Direct3D.DrawTextFormat.Center, Color.Black);
            int x = (m_d3DDevice.Viewport.Width / 2) - (rc.Width / 2);
            int y = 10;
            m_d3DFont.DrawText(null, m_timeCodeString, x + 1, y + 1, Color.Black);
            m_d3DFont.DrawText(null, m_timeCodeString, x, y, Color.White);



        void SetTimecode(IDeckLinkVideoFrame videoFrame)
            IDeckLinkTimecode timecode;

            m_timeCodeString = "00:00:00:00";

            videoFrame.GetTimecode(_BMDTimecodeFormat.bmdTimecodeRP188Any, out timecode);

            if (timecode != null)
                timecode.GetString(out m_timeCodeString);

        void IDeckLinkScreenPreviewCallback.DrawFrame(IDeckLinkVideoFrame theFrame)
            // First, pass the frame to the DeckLink screen preview helper

            // Then draw the frame to the scene