当前位置: 代码迷 >> 多媒体/流媒体开发 >> C# DirectShow 如何实现画中画?求指教
  详细解决方案

C# DirectShow 如何实现画中画?求指教

热度:9788   发布时间:2013-02-26 00:00:00.0
C# DirectShow 怎么实现画中画?求指教。
DirectShow 怎么实现画中画啊。

------解决方案--------------------------------------------------------
一个小tuto用vmr实现pip
我没试,lz试试吧
------解决方案--------------------------------------------------------
Picture-In-a-Picture sample in C# PDF Print E-mail

In this tutorial, we'll see that it is easy to play two video streams at the same time with DirectShow and C#. To accomplish this, we'll introduce two new interfaces supported by the standard Video Mixing Renderer filter. Once again, the code can be found in a zip file.

This tutorial will implement a simple version of the Pip sample of the SDK. We create a custom library that includes the interfaces that we need for this exercise. The content of the idl file is provided in the file named "pip.idl". There is nothing special about this idl and the way we generate our assembly. (You can look at this tutorial for more information about creating a custom library or you can use the open-source DirectShowLib).

We declare variables for the usual interfaces:

IGraphBuilder gb = null;
IMediaControl mc = null;
IMediaEventEx me = null;
IMediaSeeking ms = null;
IBasicVideo bv = null;
IVideoWindow vw = null;
IVMRFilterConfig fc = null;
IVMRMixerControl vmc = null;

 

Only the last two variables deserve some explanation. The Picture-In-a-Picture sample plays two videos, one covers the whole client area and the other is alpha-blended and positioned (in our sample) in the upper left corner. The IVMRFilterConfig interface lets us set the numbers of videos (it can be more than two) we want to play. It also allows us to select the VMR mode. We haven't succeeded in correctly using the VMR in "windowless" mode but we have used the "renderless" mode in the custom allocator/presenter of the last tutorial. So in this tutorial, we'll use the "windowed" mode. When using this mode, the interaction between DirectShow and Windows is the same as what we have used so far (for example, we are using the IMediaEventEx and IVideoWindow interfaces to control Windows messaging and placement). The IVMRMixerControl interface supported by the Video Mixing Renderer filter is used to set the position of the second video and its transparency. Now we'll look at the COM objects that we need:

//CLSID_FilterGraph (take from uuids.h DirectX include)
Guid FgGuid = new Guid( "e436ebb3-524f-11ce-9f53-0020af0ba770" );
//CLSID_VideoMixingRenderer (take from uuids.h DirectX include)
Guid VmrGuid = new Guid( "B87BEB7B-8D29-423f-AE4D-6582C10175AC" );

 

We need a Filter Graph object and a Video Mixer Renderer. So we define their guids and we'll call Activator.CreateInstance to create the objects (as we have done before). After that we add the VMR filter to the graph:

// create the vmr object and add to the filter graph
t = Type.GetTypeFromCLSID( VmrGuid );
vmr = Activator.CreateInstance( t );
gb.AddFilter( (IBaseFilter)vmr, "Video Mixing Renderer" );

 

Then, we grab the IVMRFilterConfig interface from the VMR object and sets its rendering mode and number of streams.

// configure the vmr for two streams
fc = (IVMRFilterConfig)vmr;
//VMRMode_Windowed = 0x00000001
fc.SetRenderingMode( 0x00000001 );
fc.SetNumberOfStreams( 2 );

 

Because the two videos might be made of different formats, we use Intelligent Connect to add the needed filters to our graph.

// build the rest of the graph
gb.RenderFile( fName1, null );
gb.RenderFile( fName2, null );

 

After setting the window size, style and owner, we describe the settings for the second video. This uses a struct (imported when we have created our interop assembly) _NORMALIZEDRECT that sets the usual coordinates with "normalized" values i.e. between 0.0f and 1.0f. The second video will appear in the upper left corner so its coordinates are defined as follows:
  相关解决方案