Michael Chourdakis
Michael Chourdakis

Reputation: 11158

MediaFoundation capture video while previewing

This says:

A capture device is represented in Media Foundation by a media source object, which exposes the IMFMediaSource interface. In most cases, the application will not use this interface directly, but will use a higher-level API such as the Source Reader to control the capture device.

When I have an IMFMediaSource I can use MFCreateSourceReaderFromMediaSource and create the source reader. However this function fails with MF_E_MULTIPLE_SUBSCRIBERS when I'm also previewing the video I want to capture, which is what I 'd want.

hr = MFCreateSourceReaderFromMediaSource(t.source, 0, &t.rdr); // Fails if I'm previewing, suceeeds when I'm not.

Is there a way to aquire a SourceReader in order to capture video I'm already previewing?

I'm previewing with the Media Session.

Or, if this is not possible, how do I use the IMFMediaSource directly without a source reader? Much like what the embedded Camera application does.

Thanks a lot.

Upvotes: 0

Views: 435

Answers (1)

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

MF_E_MULTIPLE_SUBSCRIBERS part is touched by another question: you cannot have the source managed by Media Session and additionally work with it otherwise.

If you need both you need to either use a tee in that media session and use two legs of the tee to preview and capture.

Alternatively, manage the source yourself and use a custom-developed proxy in the media session to accept data from the source.

Or, if this is not possible, how do I use the IMFMediaSource directly without a source reader? Much like what the embedded Camera application does.

Or just get rid of Media Session, read from media source directly and use the data outside of Media Foundation.

The use pattern is rather straightforward (and repeats what media session or source reader would do on your behalf): create presentation descriptor, set it up, subscrive to events, start, receive samples. This API is fully documented.

Upvotes: 2

Related Questions