I'm trying to composite 2 videos into one (audio too) and save as a file. Say, show a source video on the left half of the final video and the ohter source on the right. Any encoding is fine. Not with DirectShow.
I suspected IMFVideoMixerControl may be related to this but unfortunately I'm too new to MF to detemine the right step to take in order to achieve this. If you could give me some guidance or if any example available on the web, please let me know. Thank you for your help.
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.
Microsoft Media Foundation is the next generation multimedia platform for Windows that enables developers, consumers, and content providers to embrace the new wave of premium content with enhanced robustness, unparalleled quality, and seamless interoperability.
DirectShow (sometimes abbreviated as DS or DShow), codename Quartz, is a multimedia framework and API produced by Microsoft for software developers to perform various operations with media files or streams. It is the replacement for Microsoft's earlier Video for Windows technology.
Media Foundation provides a Media Session object that can be used to set up the topologies, and facilitate a data flow, without the application doing it explicitly. It exists in the control layer, and exposes a Topology loader object.
IMFVideoMixerControl is used for rendering video. You're on the right track looking at the SourceReader.
Here's what I would do:
IMFSourceReader for each video source.IMFSinkWriter and configure it with a frame width equal to the sum of the source reader frame widths.
IMFSourceReader::GetCurrentMediaType to get the source media types.MFGetAttributeSize with GUID MF_MT_FRAME_SIZE to get the frame dimensions for each source type.MFCreateMediaType and use IMFMediaType::CopyAllItems to copy attributes from the source to sink media types.MFSetAttributeSize with GUID MF_MT_FRAME_SIZE to set the sink type's increased frame dimensions.IMFSinkWriter::AddStream to create a video stream identical to the source type, except for the width attributeIMFSample, attaching a new IMFMediaBuffer with the increased frame width.MFCopyImage to copy each of the source buffers to the corresponding side of the allocated media buffer.IMFSinkWriter::WriteSample to write your IMFSample to the file sink.See this sample for some basic SourceReader/SinkWriter processing, although this example uses a video capture source instead of a file. You can create a file SourceReader using MFCreateSourceReaderFromURL instead of MFCreateSourceReaderFromMediaSource.
Edit: I realized that you asked about audio, too. My answer only addresses compositing the video streams.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With