Пример #1
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");
        }
Пример #2
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");
        }
Пример #3
0
        private void UpdateVideoSettings()
        {
            _AMMediaType mt;
            object formatBlock;
            vc.CaptureGraph.Source.GetMediaType(out mt, out formatBlock);

            VIDEOINFOHEADER vih = new VIDEOINFOHEADER();
            bool unknownFormat = false;

            if (formatBlock is VIDEOINFOHEADER) {
                vih = (VIDEOINFOHEADER)formatBlock;
            }
            else if (formatBlock is DVINFO) { 
                DVCaptureGraph dvcg = vc.CaptureGraph as DVCaptureGraph;
                if (dvcg != null) {
                    dvcg.GetVideoMediaType(out mt, out formatBlock);
                    if (formatBlock is VIDEOINFOHEADER) {
                        vih = (VIDEOINFOHEADER)formatBlock;
                    }
                    else {
                        unknownFormat = true;
                    }
                }
                else {
                    unknownFormat = true;
                }
            }
            else {
                unknownFormat = true;
            }

            if (unknownFormat) {
                lblCurrentSettings.Text += "Unknown Video Format";
                return;
            }

            BITMAPINFOHEADER bmih = vih.BitmapInfo;

            if (lblCurrentSettings.Text == String.Empty) {
                lblCurrentSettings.Text = Strings.VideoStream;
            }
            else {
                lblCurrentSettings.Text += "\r\n\r\n" + Strings.VideoStream;
            }

            lblCurrentSettings.Text += string.Format(CultureInfo.CurrentCulture, "\r\n" +
                Strings.AdvancedVideoSettingsStatus, TAB, bmih.Width, bmih.Height,
                vih.FrameRate.ToString("F2", CultureInfo.InvariantCulture), MediaType.SubType.GuidToString(mt.subtype),
                bmih.BitCount, (uint)(bmih.Width * bmih.Height * bmih.BitCount * vih.FrameRate) / 1000);
        }