简体   繁体   English

媒体基金会的视频合成

[英]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: 这就是我要做的事情:

  1. Create one IMFSourceReader for each video source. 为每个视频源创建一个IMFSourceReader
  2. Create an IMFSinkWriter and configure it with a frame width equal to the sum of the source reader frame widths. 创建IMFSinkWriter并将其配置为帧宽等于源读取器帧宽度的总和。
    1. Use IMFSourceReader::GetCurrentMediaType to get the source media types. 使用IMFSourceReader::GetCurrentMediaType获取源媒体类型。
    2. Use MFGetAttributeSize with GUID MF_MT_FRAME_SIZE to get the frame dimensions for each source type. 使用MFGetAttributeSize与GUID MF_MT_FRAME_SIZE以获得每个源类型的帧尺寸。
    3. Create a media type for the SinkWriter with MFCreateMediaType and use IMFMediaType::CopyAllItems to copy attributes from the source to sink media types. 对于与SinkWriter创建一个媒体类型MFCreateMediaType和使用IMFMediaType::CopyAllItems从源的属性复制下沉的媒体类型。
    4. Use MFSetAttributeSize with GUID MF_MT_FRAME_SIZE to set the sink type's increased frame dimensions. 使用MFSetAttributeSize与GUID MF_MT_FRAME_SIZE设置下沉式的增加框架尺寸。
    5. Use IMFSinkWriter::AddStream to create a video stream identical to the source type, except for the width attribute 使用IMFSinkWriter::AddStream创建与源类型相同的视频流,width属性除外
  3. Call IMFSourceReader::ReadSample for each source, giving you one IMFSample for each source. 为每个源调用IMFSourceReader :: ReadSample,为每个源提供一个IMFSample。
  4. Allocate a new IMFSample , attaching a new IMFMediaBuffer with the increased frame width. 分配新的IMFSample ,附加具有增加的帧宽度的新IMFMediaBuffer
  5. Use MFCopyImage to copy each of the source buffers to the corresponding side of the allocated media buffer. 使用MFCopyImage将每个源缓冲区复制到分配的媒体缓冲区的相应端。
  6. Use 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.

相关问题 Media Foundation捕获的视频是垂直镜像的 - Video captured by Media Foundation is vertical mirrorred 使用Media Foundation进行无缝视频播放 - Seamless Video Playback Using Media Foundation Media Foundation 设置视频隔行和解码 - Media Foundation set video interlacing and decode 如何更改Media Foundation Transform输出帧(视频)的大小? - How to change Media Foundation Transform output frame(video) size? 向Media Foundation Interfaces视频屏幕添加按钮的正确方法是什么 - What is the right way to add buttons to the Media Foundation Interfaces video screen UWP 硬件视频解码 - DirectX12 vs Media Foundation - UWP Hardware Video Decoding - DirectX12 vs Media Foundation Windows Media Foundation中的视频捕获可以用于屏幕捕获吗? - Can Video capture in windows media foundation used for screen capturing? C ++中的Media Foundation全景图(equirectangular)视频播放 - Media Foundation panorama (equirectangular) video playback in C++ Media Foundation使用PROPVARIANT结构设置视频捕获帧速率 - Media Foundation set video capture frame rate using PROPVARIANT structure 使用DirectX视频加速(DXVA)实施媒体基础转换(MFT) - Implementing a Media Foundation Transform (MFT) with DirectX Video Acceleration (DXVA)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM