Page 1 of 1

How to flip a video frame/source?

PostPosted: Thu Jan 04, 2018 10:52 pm
by Scott Heimendinger
What's the best way to flip (vertically, for example) my video source?

Specifically, in the CapturePreviewCSharp project, I'd like to flip the video feed that's rendered to the PreviewWindow. It wasn't immediately obvious where I can apply this transform. I tried applying the transform to the m_d3DDevice using the below, but it never made an impact:

Inside PreviewWindow.cs: Render()
Code: Select all
m_d3DDevice.SetTransform(Direct3D.TransformType.Projection, Matrix.RotationX(180));

Code: Select all

Neither throw an error, but neither flip the image either.

I also looked at flipping the incoming IDeckLinkVideoFrame inside IDeckLinkScreenPreviewCallback.DrawFrame, but it wasn't clear how to flip a video frame.

Any guidance is greatly appreciated!

Re: How to flip a video frame/source?

PostPosted: Mon Jan 08, 2018 11:07 pm
by Cameron Nichols
Hi Scott,

The IDeckLinkDX9ScreenPreviewHelper has it's own transform function implemented, so it will override attempt to call SetTransform externally. However, it is possible to rotate the preview by 180 degrees (in case camera is mounted up-side-down), by swapping left/right and top/bottom coordinates of the viewport rectangle.

For flipping, the solution will be to either:
1) Iterate through frame lines and manually swap lines (CPU intensive).
2) Implement own DirectX or OpenGL helper to perform own custom transforms.


Re: How to flip a video frame/source?

PostPosted: Fri Jan 26, 2018 8:55 pm
by Scott Heimendinger
Thanks very much! For anyone facing the same issue, here's the code that worked for me:

in PreviewWindow.cs:
Code: Select all
public bool Flip;

void Render()


                tagRECT rect;
           = m_d3DDevice.Viewport.Y;
                    rect.left = m_d3DDevice.Viewport.X;
                    rect.bottom = m_d3DDevice.Viewport.Y + m_d3DDevice.Viewport.Height;
                    rect.right = m_d3DDevice.Viewport.X + m_d3DDevice.Viewport.Width;
                    rect.bottom = m_d3DDevice.Viewport.Y;
                    rect.right = m_d3DDevice.Viewport.X;
           = m_d3DDevice.Viewport.Y + m_d3DDevice.Viewport.Height;
                    rect.left = m_d3DDevice.Viewport.X + m_d3DDevice.Viewport.Width;
....//the rest of the method