Help with saving capture to file in C#

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

Jeffrey Paxton

  • Posts: 1
  • Joined: Mon May 11, 2020 5:16 pm
  • Location: Huntersville, NC
  • Real Name: Jeffrey Paxton

Help with saving capture to file in C#

PostMon May 11, 2020 5:36 pm

Hello all,
We have purchased a DeckLink Quad 2 PCIe card. We are trying to capture from 2 cameras simultaneously, and output each camera to it's own file. I have spent hours perusing the forum for examples of this to no avail.
The problem I am hung up on is the call to
Code: Select all
sinkWriter.SetInputMediaType(VideoStreamIndex, mediaTypeIn, null);
fails with an Hresult of MF_E_INVALIDMEDIATYPE no matter what MFMediaType I try to set for the MF_MT_SUBTYPE.

Any sample code or links would be greatly appreciated. The following code is my ConfigureVideoEncoder method:
Code: Select all
private void ConfigureVideoEncoder(IDeckLinkDisplayMode displayMode, _BMDPixelFormat inputPixelFormat)
            HResult hr = HResult.S_OK;
            displayMode.GetFrameRate(out long frameDuration, out long frameTimeScale);
            MFExtern.MFCreateMediaType(out IMFMediaType mediaTypeOut);

            hr = mediaTypeOut.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
            hr = mediaTypeOut.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, MFMediaType.H264);
            hr = mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_AVG_BITRATE, kVideoEncodedBitRate);
            hr = mediaTypeOut.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (int)MFVideoInterlaceMode.Progressive);
            hr = MFExtern.MFCreateAttributes(out sinkWriterAttributes, 1);
            hr = MFExtern.MFSetAttributeSize(sinkWriterAttributes, MFAttributesClsid.MF_MT_FRAME_SIZE, displayMode.GetWidth(), displayMode.GetHeight());
            hr = MFExtern.MFSetAttributeRatio(sinkWriterAttributes, MFAttributesClsid.MF_MT_FRAME_RATE, (int)frameTimeScale, (int)frameDuration);
            hr = MFExtern.MFSetAttributeRatio(sinkWriterAttributes, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);

            sinkWriter.AddStream(mediaTypeOut, out VideoStreamIndex);
            var getType = sinkWriter.GetType();
            // set the input media type
            hr = MFExtern.MFCreateMediaType(out IMFMediaType mediaTypeIn);
            hr = mediaTypeIn.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
            hr = mediaTypeIn.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, MFMediaType.UYVY);
            hr = mediaTypeIn.SetUINT32(MFAttributesClsid.MF_MT_INTERLACE_MODE, (int)MFVideoInterlaceMode.FieldInterleavedUpperFirst);
            hr = MFExtern.MFSetAttributeSize(mediaTypeIn, MFAttributesClsid.MF_MT_FRAME_SIZE, displayMode.GetWidth(), displayMode.GetHeight());
            hr = MFExtern.MFSetAttributeRatio(mediaTypeIn, MFAttributesClsid.MF_MT_FRAME_RATE, (int)frameTimeScale, (int)frameDuration);
            hr = MFExtern.MFSetAttributeRatio(mediaTypeIn, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO, 1, 1);

            hr = sinkWriter.SetInputMediaType(VideoStreamIndex, mediaTypeIn, null);

Thanks in advance,
Jeffrey Paxton

Return to Software Developers

Who is online

Users browsing this forum: No registered users and 6 guests