gpt4 book ai didi

xna - 如何编码 XNA DirectShow 可以正常播放的 .wmv 文件?

转载 作者:行者123 更新时间:2023-12-04 23:04:26 24 4
gpt4 key购买 nike

我正在使用 XNA DirectShow 从文件中流式传输视频,而不是将其加载到我的项目中(顺便说一下,我完全了解 XNA MediaPlayer 类)。它可以毫无问题地播放示例视频。当我尝试从我使用 ffmpeg 的一系列 PNG 文件制作自己的 .wmv 时,视频播放但全是蓝色(应该大部分是黄色)。像素格式错误?编解码器错误?我当然不是这些水域的专家。

示例视频显然是 VC-1 WMV3,我认为我无法复制它?我应该使用什么编码/编解码器/文件格式?

还!如果透明视频背景是可能的,那就太棒了。是吗?

最佳答案

好的,我已经解决了 - 我只是切换了 DirectShow 创建其输出纹理时分配的像素顺序。在 VideoPlayer 类中,我将 UpdateBuffer 更改为:

 private void UpdateBuffer()
{
int waitTime = avgTimePerFrame != 0 ? (int)((float)avgTimePerFrame / 10000) : 20;

int samplePosRGBA = 0;
int samplePosRGB24 = 0;

while (true)
{
for (int y = 0, y2 = videoHeight - 1; y < videoHeight; y++, y2--)
{
for (int x = 0; x < videoWidth; x++)
{
samplePosRGBA = (((y2 * videoWidth) + x) * 4);
samplePosRGB24 = ((y * videoWidth) + x) * 3;

//make transparent if pixel matches a certain colour
if (WhiteTransparent && bgrData[samplePosRGB24 + 2] > 200 && bgrData[samplePosRGB24 + 1] > 200 && bgrData[samplePosRGB24 + 0] > 200)
{
//transparent pixel
videoFrameBytes[samplePosRGBA + 0] = 0;
videoFrameBytes[samplePosRGBA + 1] = 0;
videoFrameBytes[samplePosRGBA + 2] = 0;
videoFrameBytes[samplePosRGBA + 3] = 0;
}
else
{
//modified pixel format order - switch the 2,1,0 on the right for other formats..
videoFrameBytes[samplePosRGBA + 0] = bgrData[samplePosRGB24 + 2];
videoFrameBytes[samplePosRGBA + 1] = bgrData[samplePosRGB24 + 1];
videoFrameBytes[samplePosRGBA + 2] = bgrData[samplePosRGB24 + 0];
videoFrameBytes[samplePosRGBA + 3] = alphaTransparency;
}
}
}

frameAvailable = false;
while (!frameAvailable)
{ Thread.Sleep(waitTime); }
}
}

如果我添加到类中的 bool 值 - WhiteTransparent 为真,它还会在最终图像中将任何白色区域显示为透明。我知道粗鲁,但它对我有用。如果不需要,只需使用 else 语句中的行。

关于xna - 如何编码 XNA DirectShow 可以正常播放的 .wmv 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17171125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com