使用Directshow和C#录制视频时的文字叠加

时间:2012-06-01 09:09:30

标签: c# text overlay directshow directshow.net

通过使用DirectShowLib我可以使用ASF写入来录制视频这里是开始录制的代码

 try
        {
            IBaseFilter capFilter = null;
            IBaseFilter asfWriter = null;
            IFileSinkFilter pTmpSink = null;
            ICaptureGraphBuilder2 captureGraph = null;               
            GetVideoDevice();
            if (availableVideoInputDevices.Count > 0)
            {
                //
                //init capture graph
                //
                graphBuilder = (IFilterGraph2)new FilterGraph();
                captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
                //
                //sets filter object from graph
                //
                captureGraph.SetFiltergraph(graphBuilder);
                //
                //which device will use graph setting
                //
                graphBuilder.AddSourceFilterForMoniker(AvailableVideoInputDevices.First().Mon, null, AvailableVideoInputDevices.First().Name, out capFilter);
                captureDeviceName = AvailableVideoInputDevices.First().Name;                    
                //
                //check saving path is exsist or not;if not then create
                //
                if (!Directory.Exists(ConstantHelper.RootDirectoryName + "\\Assets\\Video\\"))
                {
                    Directory.CreateDirectory(ConstantHelper.RootDirectoryName + "\\Assets\\Video\\");
                }
                #region WMV                   
                //
                //sets output file name,and file type
                //
                captureGraph.SetOutputFileName(MediaSubType.Asf, ConstantHelper.RootDirectoryName + "\\Assets\\Video\\" + videoFilename + ".wmv", out asfWriter, out pTmpSink);                    
                //
                //configure which video setting is used by graph
                //                
                IConfigAsfWriter lConfig = asfWriter as IConfigAsfWriter;
                Guid asfFilter = new Guid("8C45B4C7-4AEB-4f78-A5EC-88420B9DADEF");
                lConfig.ConfigureFilterUsingProfileGuid(asfFilter);
                #endregion
                //
                //render the stram to output file using graph setting
                //
                captureGraph.RenderStream(null, null, capFilter, null, asfWriter);
                m_mediaCtrl = graphBuilder as IMediaControl;
                m_mediaCtrl.Run();
                isVideoRecordingStarted = true;
                VideoStarted(m_mediaCtrl, null);

现在我想在视频重新编码时在视频上添加文字叠加,并且使用DirectshowLib这是可行的吗?

例如,当视频录制开始时,视频应该以文本覆盖进行录制。

2 个答案:

答案 0 :(得分:0)

我在我的软件中以SampleGrabber过滤器插入到图形中的方式进行,并且在图片到达时,我将其转换为Bitmap对象,然后使用Graphics

答案 1 :(得分:0)

查看DirectShow.Net示例中的DMO和DxLogo示例,以执行您所需的操作。 DanielMošmondor解释你可以在DxSnap示例中找到...

http://directshownet.sourceforge.net/