[英]Video composition with Media Foundation
I'm trying to composite 2 videos into one (audio too) and save as a file. 我正在尝试将2个视频合成为一个(音频也是如此)并保存为文件。 Say, show a source video on the left half of the final video and the ohter source on the right.
比如,在最终视频的左半部分显示源视频,在右边显示ohter源。 Any encoding is fine.
任何编码都没问题。 Not with DirectShow.
不是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. 我怀疑IMFVideoMixerControl可能与此有关,但遗憾的是我对MF来说太新了,无法确定正确的步骤以实现这一目标。 If you could give me some guidance or if any example available on the web, please let me know.
如果您可以给我一些指导或网上有任何示例,请告诉我。 Thank you for your help.
谢谢您的帮助。
IMFVideoMixerControl
is used for rendering video. IMFVideoMixerControl
用于渲染视频。 You're on the right track looking at the SourceReader. 您正在寻找SourceReader的正确轨道。
Here's what I would do: 这就是我要做的事情:
IMFSourceReader
for each video source. IMFSourceReader
。 IMFSinkWriter
and configure it with a frame width equal to the sum of the source reader frame widths. IMFSinkWriter
并将其配置为帧宽等于源读取器帧宽度的总和。
IMFSourceReader::GetCurrentMediaType
to get the source media types. IMFSourceReader::GetCurrentMediaType
获取源媒体类型。 MFGetAttributeSize
with GUID MF_MT_FRAME_SIZE
to get the frame dimensions for each source type. MFGetAttributeSize
与GUID MF_MT_FRAME_SIZE
以获得每个源类型的帧尺寸。 MFCreateMediaType
and use IMFMediaType::CopyAllItems
to copy attributes from the source to sink media types. MFCreateMediaType
和使用IMFMediaType::CopyAllItems
从源的属性复制下沉的媒体类型。 MFSetAttributeSize
with GUID MF_MT_FRAME_SIZE
to set the sink type's increased frame dimensions. MFSetAttributeSize
与GUID MF_MT_FRAME_SIZE
设置下沉式的增加框架尺寸。 IMFSinkWriter::AddStream
to create a video stream identical to the source type, except for the width attribute IMFSinkWriter::AddStream
创建与源类型相同的视频流,width属性除外 IMFSample
, attaching a new IMFMediaBuffer
with the increased frame width. IMFSample
,附加具有增加的帧宽度的新IMFMediaBuffer
。 MFCopyImage
to copy each of the source buffers to the corresponding side of the allocated media buffer. MFCopyImage
将每个源缓冲区复制到分配的媒体缓冲区的相应端。 IMFSinkWriter::WriteSample
to write your IMFSample
to the file sink. IMFSinkWriter::WriteSample
你写IMFSample
到文件接收器。 See this sample for some basic SourceReader/SinkWriter processing, although this example uses a video capture source instead of a file. 请参阅此示例以获取一些基本的SourceReader / SinkWriter处理,尽管此示例使用视频捕获源而不是文件。 You can create a file SourceReader using
MFCreateSourceReaderFromURL
instead of MFCreateSourceReaderFromMediaSource
. 您可以使用
MFCreateSourceReaderFromURL
而不是MFCreateSourceReaderFromMediaSource
创建文件SourceReader。
Edit: I realized that you asked about audio, too. 编辑:我意识到你也问过音频。 My answer only addresses compositing the video streams.
我的回答只涉及合成视频流。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.