2012-06-05 89 views
0

據我previous post我曾嘗試使用sampleGrabber將抓住從視頻文件的幀,然後調用回調函數:如何使用Directshow和C#進行文本覆蓋視頻錄製?

Type comType = Type.GetTypeFromCLSID(new Guid("e436ebb3-524f-11ce-9f53-0020af0ba770")); 
IGraphBuilder graphBuilder = (IGraphBuilder)Activator.CreateInstance(comType); 

comType = Type.GetTypeFromCLSID(new Guid("C1F400A0-3F08-11d3-9F0B-006008039E37")); 
ISampleGrabber sampleGrabber = (ISampleGrabber)Activator.CreateInstance(comType); 

graphBuilder.AddFilter((IBaseFilter)sampleGrabber, "samplegrabber"); 

AMMediaType mediaType = new AMMediaType(); 
mediaType.majorType = MediaType.Video; 
mediaType.subType = MediaSubType.RGB24; 
mediaType.formatType = FormatType.VideoInfo; 
sampleGrabber.SetMediaType(mediaType); 

int hr = graphBuilder.RenderFile(@"D:\test.wmv", null); 

IMediaEventEx mediaEvent = (IMediaEventEx)graphBuilder; 
IMediaControl mediaControl = (IMediaControl)graphBuilder; 
IVideoWindow videoWindow = (IVideoWindow)graphBuilder; 
IBasicAudio basicAudio = (IBasicAudio)graphBuilder; 

videoWindow.put_AutoShow(OABool.False); 
basicAudio.put_Volume(-10000); 

sampleGrabber.SetOneShot(false); 
sampleGrabber.SetBufferSamples(true); 

//the same object has implemented the ISampleGrabberCB interface. 
//0 sets the callback to the ISampleGrabberCB::SampleCB() method. 
sampleGrabber.SetCallback(this, 0); 

mediaControl.Run(); 

EventCode eventCode; 
mediaEvent.WaitForCompletion(-1, out eventCode); 


Marshal.ReleaseComObject(sampleGrabber); 
Marshal.ReleaseComObject(graphBuilder); 

回調函數

public int SampleCB (double sampleTime, IMediaSample mediaSample) 
    { 
    //WHAT TO DO HERE. 
    } 
  1. 什麼我在回調函數中添加疊加在每一幀,然後整個視頻將獲得疊加文本的商店?

  2. 有什麼辦法來添加視頻時錄製疊加文本?

回答

0

在錄製過程中添加文本疊加,最好的辦法是實現一個DMODirectShow Transform-Filter。我更喜歡DMO,因爲它更簡單,您可以稍後在MediaFoundation中重用它。

您可以設置RGB24或RGB32爲輸入型的DMO /過濾器,然後你可以選擇你想要每一幀用什麼畫GDI。

在圖表,它看起來是這樣的:VideoSource -> DMO -> ASF Writer

+0

我想跟DMO一起去看你有的任何示例代碼嗎?我正在使用[this](http://stackoverflow.com/questions/10847477/text-overlay-when-video-is-recording-using-directshow-and-c-sharp)錄製代碼?至少給出步驟?感謝您的回覆.. – Amogh

+0

在DirectShowNet示例中有一個Video-Dmo示例:DMOFlip [鏈接](http://directshownet.sourceforge.net/about.html)。這應該是一個很好的起點,因爲這個示例還包含一個幫助文件如何編寫一個dmo。 – CPlusSharp

+0

謝謝你這麼多先生,我會通過該示例感謝。 – Amogh

相關問題