Example #1
0
        private IBaseFilter ConfigAsf(ICaptureGraphBuilder2 capGraph,
                                      string szOutputFileName,
                                      CaptureOptions.VideoCompression quality)
        {
            IFileSinkFilter pTmpSink  = null;
            IBaseFilter     asfWriter = null;

            int hr = capGraph.SetOutputFileName(MediaSubType.Asf, szOutputFileName, out asfWriter, out pTmpSink);

            Marshal.ThrowExceptionForHR(hr);

            try
            {
                IConfigAsfWriter lConfig = (IConfigAsfWriter)asfWriter;

                string profileData;
                int    bitRate;
                switch (quality)
                {
                case CaptureOptions.VideoCompression.MinimalSize:
                    bitRate = (int)(1000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                case CaptureOptions.VideoCompression.Optimal:
                    bitRate = (int)(2000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                case CaptureOptions.VideoCompression.BestQuality:
                    bitRate = (int)(4000000.0 * (_inFrameWidth * _inFrameHeight * _FPS) / (720 * 1280 * 25));
                    break;

                default:
                    throw new ApplicationException("Internal error: unknown type of the required video codec");
                }

                //Getting XML with profile.
                using (var reader = new StreamReader(Path.Combine(Directories.GetConfigDirectory(), "Encoder.prx")))
                {
                    profileData = reader.ReadToEnd();
                }
                profileData = profileData.Replace("__FRAME_WIDTH__", _inFrameWidth.ToString());
                profileData = profileData.Replace("__FRAME_HEIGHT__", _inFrameHeight.ToString());
                profileData = profileData.Replace("__BIT_RATE__", bitRate.ToString());

                // Get manager
                IWMProfileManager profileManager;
                WMUtils.WMCreateProfileManager(out profileManager);

                // Create profile
                IWMProfile profile;
                profileManager.LoadProfileByData(profileData, out profile);
                lConfig.ConfigureFilterUsingProfile(profile);
            }
            finally
            {
                Marshal.ReleaseComObject(pTmpSink);
            }

            return(asfWriter);
        }
Example #2
0
        public DxPlay(ImageHandler handler,
                      string fileName,
                      CaptureOptions.VideoCompression quality,
                      int inFrameWidth, int inFrameHeight, int FPS)
        {
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            try
            {
                _inFrameWidth  = inFrameWidth;
                _inFrameHeight = inFrameHeight;
                _FPS           = FPS;
                m_ImageHandler = handler;

                // Set up the graph
                SetupGraph(fileName, quality);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Example #3
0
        public VideoSaver(IFileNamingTemplate fileNaming,
                          CaptureOptions.VideoSize frameSize,
                          CaptureOptions.VideoFPS FPS,
                          CaptureOptions.VideoCompression compression)
        {
            KeyValuePair <int, int> size = CaptureOptions.ToValue(frameSize);

            _fileNaming  = fileNaming;
            _frameWidth  = size.Key;
            _frameHeight = size.Value;
            _FPS         = CaptureOptions.ToValue(FPS);
            _compression = compression;

            _buffer = null;
            _dxPlay = null;
        }
Example #4
0
        /// <summary>
        /// Build the filter graph
        /// </summary>
        private void SetupGraph(string fileName, CaptureOptions.VideoCompression quality)
        {
            int hr;

            // Get the graphbuilder object
            m_FilterGraph = (IFilterGraph2) new FilterGraph();

            // Get a ICaptureGraphBuilder2 to help build the graph
            ICaptureGraphBuilder2 icgb2 = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            try
            {
                // Link the ICaptureGraphBuilder2 to the IFilterGraph2
                hr = icgb2.SetFiltergraph(m_FilterGraph);
                DsError.ThrowExceptionForHR(hr);

#if DEBUG
                // Allows you to view the graph with GraphEdit File/Connect
                m_DsRot = new DsROTEntry(m_FilterGraph);
#endif

                // Our data source
                IBaseFilter ipsb = (IBaseFilter) new GenericSampleSourceFilter();

                try
                {
                    // Get the pin from the filter so we can configure it
                    IPin ipin = DsFindPin.ByDirection(ipsb, PinDirection.Output, 0);

                    try
                    {
                        // Configure the pin using the provided BitmapInfo
                        ConfigurePusher((IGenericSampleConfig)ipin);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(ipin);
                    }

                    // Add the filter to the graph
                    hr = m_FilterGraph.AddFilter(ipsb, "GenericSampleSourceFilter");
                    Marshal.ThrowExceptionForHR(hr);

                    // Create a filter for the output avi file
                    var asfWriter = ConfigAsf(icgb2, fileName, quality);

                    // Connect everything together
                    hr = icgb2.RenderStream(null, null, ipsb, null, asfWriter);
                    DsError.ThrowExceptionForHR(hr);
                }
                finally
                {
                    Marshal.ReleaseComObject(ipsb);
                }

                // Grab some other interfaces
                m_mediaCtrl = m_FilterGraph as IMediaControl;
            }
            finally
            {
                Marshal.ReleaseComObject(icgb2);
            }
        }