Exemplo n.º 1
0
 public VideoCompressorQualityInfo(VideoCompressorQualityInfo vcqi) : 
     this(vcqi.MediaSubType, vcqi.BitRate, vcqi.KeyFrameRate, vcqi.Quality){}
Exemplo n.º 2
0
        private void ConfigureWMEncoder(VideoCompressorQualityInfo vcqi)
        {
            //
            // Note: Configure compressor before setting private data
            //
            IPropertyBag iPB = (IPropertyBag)filter;
            object o = 1; // 1 == Live, can be obtained from IWMCodecProps.GetCodecProp(WM9PropList.g_wszWMVCComplexityExLive)
            iPB.Write(WM9PropList.g_wszWMVCComplexityEx, ref o);  

            if(vcqi.KeyFrameRate != VideoCompressorQualityInfo.KeyFrameRateDefault)
            {
                o = vcqi.KeyFrameRate;
                iPB.Write(WM9PropList.g_wszWMVCKeyframeDistance, ref o);
            }

            //                // More configuration possibilities
            //                o = 0;
            //                iPB.Write(WM9PropList.g_wszWMVCComplexityMode, ref o);
            //                
            //                o = 0;
            //                iPB.Write(WM9PropList.g_wszWMVCCrisp, ref o);
            //
            //                o = "MP";
            //                iPB.Write(WM9PropList.g_wszWMVCDecoderComplexityRequested, ref o);
            //
            //                o = 10000;
            //                iPB.Write(WM9PropList.g_wszWMVCVideoWindow, ref o);
            //
            //                o = true;
            //                iPB.Write(WM9PropList.g_wszWMVCVBREnabled, ref o);


            //
            // Set Private Data
            //
            IWMCodecPrivateData iPD = (IWMCodecPrivateData)filter;
            iPD.SetPartialOutputType(ref mt);

            uint cbData = 0;
            iPD.GetPrivateData(IntPtr.Zero, ref cbData);

            if(cbData != 0)
            {
                int vihSize = Marshal.SizeOf(vih);

                // Allocate space for video info header + private data
                IntPtr vipd = Marshal.AllocCoTaskMem(vihSize + (int)cbData);

                // Copy vih into place
                Marshal.StructureToPtr(vih, vipd, false);

                // Fill in private data
                iPD.GetPrivateData(new IntPtr(vipd.ToInt32() + vihSize), ref cbData);

                // Reset it
                MediaType.Free(ref mt); // Clean it up, so we can reuse it
                mt.pbFormat = vipd;
                mt.cbFormat = (uint)vihSize + cbData;
            }
        }
Exemplo n.º 3
0
        private void ConfigureCompressor(VideoCompressorQualityInfo vcqi)
        {
            // This method is called after the compressor is connected to the
            // source filter, so that the media types and format blocks contain
            // useable information.
            _AMMediaType[] mts;
            object[] fbs;
            GetMediaTypes(out mts, out fbs);

            for(int i = 0; i < mts.Length; i++)
            {
                if(mts[i].subtype == vcqi.MediaSubType)
                {
                    mt = mts[i];
                    vih = (VIDEOINFOHEADER)fbs[i];
                    break;
                }
            }

            if (mt.subtype != vcqi.MediaSubType) {
                //If we are using non-standard codecs, there may not be a match.  
                //PRI2: Some compressors will likely need to be configured using their own custom tools or dialogs, or will require special case subclasses.
                return;
            }

            Debug.Assert(mt.subtype == vcqi.MediaSubType);

            // Configure the bit rate - .Net makes a copy of fb
            vih.BitRate = vcqi.BitRate;

            // Update the structure in memory with what we have
            mt = MediaType.Construct(mt, vih);

            // Allow compressor specific configuration
            // e.g. WM9+ requires extra configuration, others may as well
            CompressorSpecificConfiguration(vcqi);

            // Use the structure in the compressor - this will free the format
            // block when it is done.
            try {
                //This was observed to fail for some non-standard compressors.
                SetMediaType(ref mt);
            }
            catch (Exception ex) {
                Trace.WriteLine("Failed to set video compressor MediaType: " + ex.ToString());
            }

            // Check for other video compression settings
            IAMVideoCompression iVC = OutputPin as IAMVideoCompression;
            if(iVC != null)
            {
                // WMV9 and WMVAdv don't work well if you modify them this way
                if (FriendlyName != "WMVideo8 Encoder DMO" && 
                    FriendlyName != "WMVideo9 Encoder DMO")
                {
                    try {
                        iVC.put_KeyFrameRate(vcqi.KeyFrameRate);
                        iVC.put_Quality(vcqi.Quality);
                    }
                    catch(Exception ex) {
                        Trace.WriteLine("Failed to set video compressor quality: " + ex.ToString());
                    }
                }
            }

            CompressorDiagnostics("After setting media type");
        }
Exemplo n.º 4
0
        private void CompressorSpecificConfiguration(VideoCompressorQualityInfo vcqi)
        {
            // ------------------------------------------------------------------------------------
            // Very specific to the WM9+ codec
            // Must come after setting the VideoInfo properties in order to get the "correct" private data
            // ------------------------------------------------------------------------------------
            if (FriendlyName == "WMVideo8 Encoder DMO" || 
                FriendlyName == "WMVideo9 Encoder DMO")
            {
                ConfigureWMEncoder(vcqi);
            }

            //
            // Add your compressor specific configuration needs here
            //
        }
Exemplo n.º 5
0
        private void ConfigureCompressor(VideoCompressorQualityInfo vcqi)
        {
            // This method is called after the compressor is connected to the
            // source filter, so that the media types and format blocks contain
            // useable information.
            _AMMediaType[] mts;
            object[] fbs;
            GetMediaTypes(out mts, out fbs);

            for(int i = 0; i < mts.Length; i++)
            {
                if(mts[i].subtype == vcqi.MediaSubType)
                {
                    mt = mts[i];
                    vih = (VIDEOINFOHEADER)fbs[i];
                    break;
                }
            }

            Debug.Assert(mt.subtype == vcqi.MediaSubType);

            // Configure the bit rate - .Net makes a copy of fb
            vih.BitRate = vcqi.BitRate;

            // Update the structure in memory with what we have
            mt = MediaType.Construct(mt, vih);

            // Allow compressor specific configuration
            // e.g. WM9+ requires extra configuration, others may as well
            CompressorSpecificConfiguration(vcqi);

            // Use the structure in the compressor - this will free the format
            // block when it is done
            SetMediaType(ref mt);

            // Check for other video compression settings
            IAMVideoCompression iVC = OutputPin as IAMVideoCompression;
            if(iVC != null)
            {
                // WMV9 and WMVAdv don't work well if you modify them this way
                if (FriendlyName != "WMVideo8 Encoder DMO" &&
                    FriendlyName != "WMVideo9 Encoder DMO")
                {
                    iVC.put_KeyFrameRate(vcqi.KeyFrameRate);
                    iVC.put_Quality(vcqi.Quality);
                }
            }

            CompressorDiagnostics("After setting media type");
        }