Пример #1
0
        public int StartCapture(string pwszFileName, Guid subType)
        {
            var hr = 0;

            lock (LockSync)
            {
                if (PReader == null)
                {
                    return(hr);
                }
                // Create the sink writer
                if (Succeeded(hr))
                {
                    hr = MFExtern.MFCreateSinkWriterFromURL(pwszFileName, null, null, out PWriter);
                }

                // Set up the encoding parameters.
                if (Succeeded(hr))
                {
                    var param = new EncodingParameters {
                        Subtype = subType
                    };
                    hr = ConfigureCapture(param);
                }

                if (Succeeded(hr))
                {
                    BFirstSample = true;
                    LlBaseTime   = 0;
                }
            }

            return(hr);
        }
Пример #2
0
        private static int ConfigureEncoder(EncodingParameters eparams, IMFMediaType pType, IMFSinkWriter pWriter,
                                            out int pdwStreamIndex)
        {
            IMFMediaType pType2;

            var hr = MFExtern.MFCreateMediaType(out pType2);

            if (Succeeded(hr))
            {
                hr = pType2.SetGUID(MFAttributesClsid.MF_MT_MAJOR_TYPE, MFMediaType.Video);
            }

            if (Succeeded(hr))
            {
                hr = pType2.SetGUID(MFAttributesClsid.MF_MT_SUBTYPE, eparams.Subtype);
            }

            if (Succeeded(hr))
            {
                hr = pType2.SetUINT32(MFAttributesClsid.MF_MT_AVG_BITRATE, eparams.Bitrate);
            }

            if (Succeeded(hr))
            {
                hr = CopyAttribute(pType, pType2, MFAttributesClsid.MF_MT_FRAME_SIZE);
            }

            if (Succeeded(hr))
            {
                hr = CopyAttribute(pType, pType2, MFAttributesClsid.MF_MT_FRAME_RATE);
            }

            if (Succeeded(hr))
            {
                hr = CopyAttribute(pType, pType2, MFAttributesClsid.MF_MT_PIXEL_ASPECT_RATIO);
            }

            if (Succeeded(hr))
            {
                hr = CopyAttribute(pType, pType2, MFAttributesClsid.MF_MT_INTERLACE_MODE);
            }

            pdwStreamIndex = 0;
            if (Succeeded(hr))
            {
                hr = pWriter.AddStream(pType2, out pdwStreamIndex);
            }

            SafeRelease(pType2);

            return(hr);
        }
Пример #3
0
        private int ConfigureCapture(EncodingParameters eparam)
        {
            IMFMediaType pType = null;

            //var hr = ConfigureSourceReader(PReader);

            var hr = PReader.GetCurrentMediaType((int)MF_SOURCE_READER.FirstVideoStream, out pType);
            int w, h;

            MfGetAttributeSize(pType, out w, out h);
            eparam.Bitrate = w * h * 20;

            var sinkStream = 0;

            if (Succeeded(hr))
            {
                hr = ConfigureEncoder(eparam, pType, PWriter, out sinkStream);
            }

            if (Succeeded(hr))
            {
                // Register the color converter DSP for this process, in the video
                // processor category. This will enable the sink writer to enumerate
                // the color converter when the sink writer attempts to match the
                // media types.

                hr = MFExtern.MFTRegisterLocalByCLSID(
                    typeof(CColorConvertDMO).GUID,
                    MFTransformCategory.MFT_CATEGORY_VIDEO_PROCESSOR,
                    "",
                    MFT_EnumFlag.SyncMFT,
                    0,
                    null,
                    0,
                    null
                    );
            }

            if (Succeeded(hr))
            {
                hr = PWriter.SetInputMediaType(sinkStream, pType, null);
            }

            if (Succeeded(hr))
            {
                hr = PWriter.BeginWriting();
            }

            SafeRelease(pType);

            return(hr);
        }