[DirectShow] 001 - Introduction to DirectShow Application Programming

来源:互联网 发布:淘宝app怎么卖二手东西 编辑:程序博客网 时间:2024/06/07 14:42

The building block of DirectShow is a software component called a filter.A filter is a software component that performs some operation on a multimediastream. For example, DirectShow filters can

read files

get video from a video capture device

decode various stream formats, such asMPEG-1 video

pass data to the graphics or sound card

DirectShow的开发模块是被称作Filter的组件,Filter是对多媒体流执行操作的组件。DirectShow Filters 可以读取文件、从视频采集设备获取视频、解码各种格式的数据流、把数据传给显示器或声卡。

Filters receive input and produce output. For example, if a filterdecodes MPEG-1 video, the input is the MPEG-encoded stream and the output is aseries of uncompressed video frames。

Filters接收输入并产生输出。例如,如果一个Filter解码MPEG-1格式的视频,那么输入就是用MPEG格式编码的数据流,输出就是一系列没有经过压缩的视屏帧。

In DirectShow, an application performs any task by connectingchains of filters together, so that the output from one filter becomes theinput for another. A set of connected filters is called a filter graph.For example, the following diagram shows a filter graph for playing an AVIfile.

在DirectShow中,应用程序通过把Filters的连接链连接起来以执行一些任务,所以,一个Filter的输入就是另一个的输入。连接在一起的Filters的集合称作Filter Graph.接下来的图片显示一个播放AVI文件的Filter Graph:

The File Source filter reads the AVI file from the hard disk. TheAVI Splitter filter parses the file into two streams, a compressed video streamand an audio stream. The AVI Decompressor filter decodes the video frames. TheVideo Renderer filter draws the frames to the display, using DirectDraw or GDI.The Default DirectSound Device filter plays the audio stream, usingDirectSound.

File Source filter 从磁盘读取AVI文件。AVI Splitter filter从文件中分离出压缩的视频和音频数据流。AVI Decompressor filter解压视频帧。Video Renderer filter使用DirectDraw或者GDI把数据帧画到显示器上。Default DirectSound Device filter 使用DirectSound播放音频流。

The application does not have to manage all of this data flow.Instead, the filters are controlled by a high-level component called the FilterGraph Manager. The application makes high-level API calls such as"Run" (to move data through the graph) or "Stop" (to stopthe flow of data). If you require more control over the stream operations, youcan access the filters directly through COM interfaces. The Filter GraphManager also passes event notifications to the application.

应用程序不需要管理所有的数据流。Filters被称作Filter Graph Manager的高层组件控制。应用程序调用高级API,例如Run和Stop。如果需要更多控制流的操作,可以通过COM接口直接访问Filters。Filter Graph Manager 还发送通知事件到应用程序。

The Filter Graph Manager serves another purpose as well: Itprovides methods for the application to build the filter graph, by connectingthe filters together. (DirectShow also provides various helper objects thatsimplify this process. These are thoroughly described in the documentation.)

Filter Graph Manager 还有其他的目的:通过把Filters连接在一起来为应用程序开发Filter Graph提供方法,(DirectShow 还提供了一些帮助对象以简化这些处理,在文档中有彻底的描述)

The application creates an instance of the Filter Graph Manager。

The application uses the Filter Graph Manager to build a filtergraph. The exact set of filters in the graph will depend on the application。

The application uses the Filter Graph Manager to control thefilter graph and stream data through the filters. Throughout this process, theapplication will also respond to events from the Filter Graph Manager。

应用程序创建一个Filter Graph Manager的实例。

应用程序使用Filter Graph Manager生成一个Filter Graph。Graph中准确的Filters集合将依赖与应用程序。

应用程序通过Filter Graph Manager控制Filter Graph和穿过Filters之间的数据流。这个过程中,应用程序将对来自Filter Graph Manager的事件作出响应。

 

When processing is completed, the application releases the FilterGraph Manager and all of the filters.

当进程完成时,应用程序释放Filter Graph Manager和所有的Filters。

 

DirectShow is based on COM; the Filter Graph Manager and thefilters are all COM objects. You should have a general understanding of COMclient programming before you begin programming DirectShow. Many books aboutCOM programming are available.

DirectShow 基于COM,Filter Graph Manager和Filters都是COM对象。在开始DirectShow编程之前,必须对COM客户端编程有大概的了解。许多关于COM编程的书都可以。

 

To getstarted with DirectShow, read the article How To Play a File,which presents a simple console application to play a video file. Thesection About DirectShow explainsthe DirectShow architecture in more detail, while the section Using DirectShow examinesthe major scenarios that are supported by DirectShow, such as capture, videoediting, DVD playback, and television.

阅读How To Play a File这篇文章开始DirectShwo的学习,这篇文章演示了一个简单的控制台程序播放视频文件。About DirectShow章节详细的解释DirectShow的体系结构。Using DirectShow章节给出了DirectShow支持的主要代码,例如采集,视频编辑,DVD回放、电视。