Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

c++ - Directshow Preview Only and Capture & Preview with a single Graph

I have a Directshow application that needs to preview a webcam video, and when user clicks 'Record' it needs to start capturing the video to a file.

To that end I created a single Capture Graph, with PREVIEW pin connected to a RENDER filter and CAPTURE pin connected to a AVI_MUX filter that saves to a file.

It looks something like this:

                        /[PREVIEW PIN]-->[VIDEO_RENDERER]--->[SCREEN]
[VIDEO CAPTURE FILTER] /
                       
                        [CAPTURE PIN]--->[AVI_MUX]--->[FILE WRITER]

When I call Run() on the graph the video shows on screen and gets saved to the file correctly.

My question is, how can I only run the PREVIEW PIN section of the graph without the CAPTURE_PIN section.

My initial idea was to manually start/stop respective filters, but then I looked at Microsoft's Directshow amcap sample, and they actually create two separate graphs. One for preview and one for capture. If the user wants to preview video, they destroy capture graph and create preview graph. And if the user wants to record video, they destroy preview graph and create capture graph.

That seems kind of wasteful, especially since a single graph already contains both PREVIEW and CAPTURE pins. What is the right approach here?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Filter graph can change state as a whole, you cannot run its part individually and separately.

The easiest solution is to build preview graph separately, and when you need to start recording, stop/close preview graph and rebuild new capture graph. This certainly would involve a certain delay in response to "start recording" command.

Another option is to use multiple graphs, share data between the two, in code or using "bridging", and start/stop graphs separately.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...