/// <summary> /// By default, we use the WMVideo9 Encoder DMO, WMV1 media type /// /// We support 3 basic default bit rates for video /// 100 Kbps for video < 320 x 240 /// 300 Kbps for video >e; 320 x 240 && < 640 x 480 /// 1 Mbps for video >e; 640 x 480 /// </summary> private void DefaultVideoCompressorSettings() { // Read camera's current media type _AMMediaType mt; object fb; cg.Source.GetMediaType(out mt, out fb); int bmpRes = 640 * 480; if (fb is VIDEOINFOHEADER) { VIDEOINFOHEADER vih = (VIDEOINFOHEADER)fb; bmpRes = vih.BitmapInfo.Height * vih.BitmapInfo.Width; } else if (fb is DVINFO) { DVCaptureGraph dvcg = cg as DVCaptureGraph; if (dvcg != null) { dvcg.GetVideoMediaType(out mt, out fb); if (fb is VIDEOINFOHEADER) { VIDEOINFOHEADER vih = (VIDEOINFOHEADER)fb; bmpRes = vih.BitmapInfo.Height * vih.BitmapInfo.Width; } } } else { Debug.Fail(string.Format(CultureInfo.CurrentCulture, "We were expecting a DVINFO or VIDEOINFOHEADER format block, not a {0}", MediaType.FormatType.GuidToString(mt.formattype))); return; } // Construct the compressor settings VideoCompressorQualityInfo vcqi = DefaultQualityInfo(); if (bmpRes < 320 * 240) { vcqi.BitRate = 100000; } else if (bmpRes < 640 * 480) { vcqi.BitRate = 300000; } else { vcqi.BitRate = 1000000; } // Set the Video Compressor's Quality vcg.VideoCompressor.QualityInfo = vcqi; }
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); }