【问题标题】:How to do video recording with Text overlay using Directshow and C#?如何使用 Directshow 和 C# 使用文本覆盖进行视频录制?
【发布时间】:2012-06-05 06:16:31
【问题描述】:

根据我的previous post,我尝试使用 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. 有没有办法在视频录制时添加叠加文字?

【问题讨论】:

    标签: c# directshow directshow.net


    【解决方案1】:

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

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

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

    【讨论】:

    • 我想和 DMO 一起去,你有任何示例代码吗?我正在使用 [this] (stackoverflow.com/questions/10847477/…) 代码进行录制?至少给出步骤?感谢您的回复..
    • DirectShowNet 示例中有一个 Video-Dmo 示例:DMOFlip link。这应该是一个很好的起点,因为这个示例还包含一个如何编写 dmo 的帮助文件。
    • 先生,我做不到。请您查看我的代码 [链接] (stackoverflow.com/questions/10847477/…) 并告诉我要添加什么?
    猜你喜欢
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    相关资源
    最近更新 更多