0

根据我之前的帖子,我尝试使用 sampleGrabber 从视频文件中抓取帧,然后调用回调函数:

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. 录制视频时有没有办法添加覆盖文本?

4

1 回答 1

0

在录制期间添加文本覆盖的最佳方法是实现DMODirectShow Transform-Filter。我更喜欢 DMO,因为它更简单,您可以稍后在 MediaFoundation 中重用它。

您将 RGB24 或 RGB32 设置为 DMO/Filter 的输入类型,然后您可以使用 GDI 在每一帧上绘制您想要的内容。

在图中,它看起来是这样的:VideoSource -> DMO -> ASF Writer.

于 2012-06-05T08:17:54.790 回答