0

According to my previous post i have tried to use sampleGrabber which will grab frames from video file and then it calls call back function:

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);

call back function

   public int SampleCB ( double sampleTime, IMediaSample mediaSample )
   {
    //WHAT TO DO HERE.
   }
  1. What do I do in the call back function to add overlay on each frame and then whole video will get store with overlay text?

  2. Is there any way to add overlay text when video is recording?

Community
  • 1
  • 1
Amogh
  • 4,453
  • 11
  • 45
  • 106

1 Answers1

0

The best way to add a text-overlay during the recording is to implement a DMO or a DirectShow Transform-Filter. I would prefer the DMO, because it is simpler and you can reuse it later in MediaFoundation.

You set RGB24 or RGB32 as Input-type for the DMO/Filter and then you can draw with GDI what you want on each frame.

In the Graph it looks this way: VideoSource -> DMO -> ASF Writer.

CPlusSharp
  • 881
  • 5
  • 15
  • i woukd like to go with DMO any sample code you have? i am using [this] (http://stackoverflow.com/questions/10847477/text-overlay-when-video-is-recording-using-directshow-and-c-sharp) code for recording? at least give the steps?Thanks for your reply.. – Amogh Jun 05 '12 at 08:36
  • There is a sample for a Video-Dmo in the DirectShowNet Samples: the DMOFlip [link](http://directshownet.sourceforge.net/about.html). This should be a good starting point, because this sample also contains a help-file how to write a dmo. – CPlusSharp Jun 05 '12 at 09:19
  • sir i am not able to do it.can you please go through my code [link] (http://stackoverflow.com/questions/10847477/text-overlay-when-video-is-recording-using-directshow-and-c-sharp) and tell me what to add there? – Amogh Jun 05 '12 at 11:36