How to flip a video frame/source?

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

Scott Heimendinger

  • Posts: 3
  • Joined: Mon Dec 18, 2017 6:58 pm

How to flip a video frame/source?

PostThu Jan 04, 2018 10:52 pm

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));


or
Code: Select all
m_d3DDevice.Transform.World.RotateX(180);


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!
Offline

Cameron Nichols

Blackmagic Design

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

Re: How to flip a video frame/source?

PostMon Jan 08, 2018 11:07 pm

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.

Regards
Cameron
Offline

Scott Heimendinger

  • Posts: 3
  • Joined: Mon Dec 18, 2017 6:58 pm

Re: How to flip a video frame/source?

PostFri Jan 26, 2018 8:55 pm

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()
        {


            try
            {
                m_d3DDevice.BeginScene();

                tagRECT rect;
                if(Flip)
                {
                    rect.top = 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;
                }
                else
                {
                    rect.bottom = m_d3DDevice.Viewport.Y;
                    rect.right = m_d3DDevice.Viewport.X;
                    rect.top = m_d3DDevice.Viewport.Y + m_d3DDevice.Viewport.Height;
                    rect.left = m_d3DDevice.Viewport.X + m_d3DDevice.Viewport.Width;
                }
               
....//the rest of the method

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 2 guests