从帧创建视频

creating a video from frames

本文关键字:视频 创建      更新时间:2023-10-16

在我的Windows通用应用程序中,我正在尝试使用WinRT组件:http://blogs.msdn.com/b/eternalcoding/archive/2013/03/06/developing-a-winrt-component-to-create-a-video-file-using-media-foundation.aspx(基本上是sinkWriter的C++包装器)

以创建带有帧的视频。

我将所有这些代码放在一个C++项目中,我可以毫无问题地从我的 C# 代码调用它。

问题首先出在构造函数上:

HRESULT CVideoGenerator::InitializeSinkWriter(Windows::Storage::Streams::IRandomAccessStream^ stream)

我不确定如何创建流:

    var filename = "exportedVideo.wmv";
    var folder = Windows.Storage.KnownFolders.VideosLibrary;
    StorageFile storageFile = await folder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
    IRandomAccessStream stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite);
    StorageFile file = await StorageFile.GetFileFromPathAsync(App.PhotoModel.Path);
    CVideoGenerator videoGenerator = new CVideoGenerator(1280, 720, stream, 20);

另一件事来自这一行:

hr = sinkWriter->SetInputMediaType(streamIndex, mediaTypeIn, NULL);   
//hr    0xc00d5212 : No suitable transform was found to encode or decode the content.   HRESULT

有什么想法吗?

我使用了这个视频生成器示例,并遇到了同样的问题。我不是媒体基金会的专家,但经过一些研究,我发现问题出在这些方面:

encodingFormat = MFVideoFormat_WMV3;
inputFormat = MFVideoFormat_RGB32;

好吧,我用第二种格式替换了第一种格式,如下所示:

encodingFormat = MFVideoFormat_RGB32;
inputFormat = MFVideoFormat_RGB32;

它似乎一直有效,直到WriteSample方法中的新异常

hr = MFCopyImage(
        pData,                      // Destination buffer.
        cbWidth,                    // Destination stride.
        (BYTE*)videoFrameBuffer,    // First row in source image.
        cbWidth,                    // Source stride.
        cbWidth,                    // Image width in bytes.
        videoHeight                // Image height in pixels.
        );

显然是在内存中写入时访问冲突。还在努力弄清楚!

麦克西姆