我需要在视频上叠加文字。
我的变化:来源 - > SampleGrabber - >压缩机 - >多路复用器(out_file)
SetOutputFileName并添加来源:
public void Start(object compr)
{
ICaptureGraphBuilder2 gb = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
IBaseFilter mux;
IFileSinkFilter sink;
Guid MEDIASUBTYPE_Avi = new Guid(0xe436eb88, 0x524f, 0x11ce, 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70);
gb.SetOutputFileName(MEDIASUBTYPE_Avi,
out_file, out mux, out sink);
IGraphBuilder gbi;
gb.GetFiltergraph(out gbi).Check();
f_fg = gbi as IFilterGraph2;
IBaseFilter src;
f_fg.AddSourceFilter(path_file, "Source", out src).Check();
添加过滤器SampleGrabber并与Source:
连接 Type comType = Type.GetTypeFromCLSID(new Guid("C1F400A0-3F08-11d3-9F0B-006008039E37"));
ISampleGrabber sampleGrabber = (ISampleGrabber)Activator.CreateInstance(comType);
f_fg.AddFilter((IBaseFilter)sampleGrabber, "samplegrabber").Check();
AMMediaType mediaType = new AMMediaType();
mediaType.majorType = MediaType.Video;
mediaType.subType = MediaSubType.RGB24;
mediaType.formatType = FormatType.VideoInfo;
sampleGrabber.SetMediaType(mediaType);
sampleGrabber.SetCallback(this, 1);
// connect filters src-->SampleGrabber
gbi.ConnectFilters(src, (IBaseFilter)sampleGrabber);
添加过滤器Compressor并启动RenderStream:
IBaseFilter compressor = ((DShowFilterInfo)compr).CreateFilter();
f_fg.AddFilter(compressor, "Compressor").Check();
gb.RenderStream(null, null, (IBaseFilter)sampleGrabber, compressor, mux).Check();
(f_fg as IMediaFilter).SetSyncSource(IntPtr.Zero).Check();
(f_fg as IMediaControl).Run();
}
public int BufferCB(double sampleTime, IntPtr buffer, int bufferLen)
{
return 0;
}
但是视频out_file没有打开(只播放1秒和黑色窗口)。为什么呢?
答案 0 :(得分:0)
上面的代码工作正常......我刚刚在渲染调用后忘了:
I'm the __call() magic method
I'm the __call() magic method