20
DirectShow

DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Embed Size (px)

Citation preview

Page 1: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

DirectShow

Page 2: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Introduction to DirectShow

• playback or capture video and audio streams

• Support format• Advanced System Format (ASF)• Motion Picture Experts Group (MPEG)• Audio-Video Interleaved (AVI)• MPEG Audio Layer-3 (MP3)• WAV sound files

Page 3: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Introduction to DirectShow

• automatically detects video and audio acceleration hardware

• Simplifies• Media playback, format conversion, capture

task• Provides access to the underlying stream

control architecture• you can create your own component to

support new format

Page 4: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Introduction to DirectShow

• Applications you can write• DVD player, video editing APs, • AVI to ASF converter, MP3 players• Digital video capture

• Techniques• Component Object Model (COM)• If you want to extend DirectShow, you need und

erstand COM

Page 5: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Supports Formats in DirectShowFile Types

Windows Media Audio (WMA) Windows Media® Video (WMV)*

Advanced Systems Format (ASF)*

MPEG

AVI QuickTime (version 2 and lower)

WAV AIFF

AU SND

MIDI

* Need Windows Media® Format SDK

Page 6: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Supports Formats in DirectShow

Compression formats

ISO MPEG-4 video version 1.0* WMA*, WMV*, MP3

Microsoft MPEG-4 version 3* Sipro Labs ACELP*

Digital Video (DV) MPEG-1 (decompression only)

MJPEG Cinepak

MPEG2 decoder is not support by DirectShow

Page 7: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

DirectShow 與其他 DirectX 元件的關係

Page 8: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

DirectShow FAQ

• What OS does DirectShow support?• Win98, Win2000, WinME, WinXP

• Do I need to know COM knowledge?• How to instantiate them• Access the interface they expose• Manage reference count

• (Filter designer requires more )

• Is there a DirectShow Hardware Compatibility List (HCL) ? • Using DirectDraw & DirectSound hardware, if they available• Or using GDI video & waveOut* audio

Page 9: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

DirectShow FAQ

• What language can I use ?• DirectShow is designed for C++• VB access subset of the API• Script based DVD or TV AP

• Will it accessible through managed code? • no current plans, the CLR is not recommended for

performance reasons

• How does DirectShow relate to Microsoft® ActiveMovie®? • the original name for DirectShow

Page 10: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

DirectShow FAQ

• Information• MSDN DirectX Developer Center

• http://go.microsoft.com/fwlink/?LinkId=10138• MSDN Audio & Video node

• http://go.microsoft.com/fwlink/?LinkId=19380• Mail list

• http://discuss.microsoft.com/archives/DIRECTXAV.htm

• Use Net• microsoft.public.win32.programmer.directx.video

Page 11: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

FAQ

• Books• Programming Microsoft® DirectShow

® for Digital Video and Television

• DirectShow: Core Media Technology in Windows XP Empowers You to Create Custom Audio/Video Processing Components

Page 12: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

FAQ

• How do I build my application?

Header file Required For

Dshow.h All DirectShow APs

Header File

Library Files

Library file Description

Strmiids.lib Exports

• the Class ID (CLSIDs)

• Interface ID (IIDs)

Quartz.lib Exports the AMGetErrorText function, 若沒用 ,可以不 link

Page 13: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

FAQ

• Detect whether DirectShow is installed?

IGraphBuilder *pGraph; HRESULT hr = CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **) &pGraph);

Page 14: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Introduction to DirectShow Application Programming

Page 15: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Filter & Filter Graphs

• Filter is a component and building block• receive input and produce output

FilterDecode MPEG-1

MPEG-1 encodedstream

Frame1

Frame2

Frame3

Page 16: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Filter Graph

• APs performs task by connecting chains of filters together

• A set of connected filters is called a filter graph

a filter graph for playing an AVI file

Page 17: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

Writing a DirectShow Application

• Three tasks must be performed

建立 Filter Graph Manager利用 Filter Graph Manager建立 filter graph

利用 Filter Graph Manager控制 filter graph

1 2 3

When processing is completed, the application releases the Filter Graph Manager and all of the filters

Page 18: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

IMediaControl *pControl; hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);

IMediaEvent *pEvent; hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);

Controller: starting and stopping the graph

Event Interface: getting event from the graph filter

Simple Model

hr = pGraph->RenderFile(L"C:\\Example.avi", NULL);

RenderFile create a graph filter that can play the specified file.

一定是 NULLL"mms://live.media.hinet.net/Radio_UFO-NEWS98?RADIOWEBB7CA5B35-4E8E-4E5B-9918-BF7F1ABDA555"

播放 news98 廣播電台串流

Page 19: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

hr = pControl->Run();

Controller: run1. Data moves through the filters2. Rendered as video and audio3. Playback occurs on a

separate thread

Run()

Page 20: DirectShow. Introduction to DirectShow playback or capture video and audio streams Support format Advanced System Format (ASF) Motion Picture Experts

延伸閱讀

• Using COM• 內容

• 想瞭解 COM 的基本原理• 如何建立 COM object• 如何使用 COM interface• 管理 COM 物件的 lifetime• 使用 C 存取 COM 物件• 使用 Macros 呼叫 DirectX COM Method

DirectX SDK