使用SinkWriter编码视频时更改h.264质量 [英] Change h.264 quality when using SinkWriter to encode video

查看:183
本文介绍了使用SinkWriter编码视频时更改h.264质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Microsoft Media Foundation编码H.264视频文件.

I am using Microsoft Media Foundation to encode a H.264 video file.

我正在使用SinkWriter创建视频文件.输入是缓冲区(MFVideoFormat_RGB32),在其中绘制帧,而输出是MFVideoFormat_H264.

I am using the SinkWriter to create the video file. The input is a buffer (MFVideoFormat_RGB32) where I draw the frames and the output is a MFVideoFormat_H264.

编码有效,并创建了一个包含我的帧的视频文件.但我想为该视频文件设置质量.更具体地说,我要设置 CODECAPI_AVEncCommonQuality 属性.

The encoding works and it creates a video file with my frames in it. But I want to set the quality for that video file. More specifically, I want to set the CODECAPI_AVEncCommonQuality property on the H.264 encoder.

为了获取H.264编码器的句柄,我致电

In order to get a handle to the H.264 encoder, I call GetServiceForStream on the SinkWriter. Then I set the CODECAPI_AVEncCommonQuality property.

问题是我的财产变更被忽略了.如文档中所述:

The problem is that my property change is ignored. As stated in the documentation:

要在Windows 7中设置此参数,请在调用IMFTransform :: SetOutputType之前设置属性.设置输出类型后,编码器将忽略更改.

To set this parameter in Windows 7, set the property before calling IMFTransform::SetOutputType. The encoder ignores changes after the output type is set.

问题是我没有手动创建H.264编码器.我在SinkWriter上设置输入和输出类型,然后SinkWriter自动创建H.264编码器.创建编码器后,它将立即调用IMFTransform::SetOutputType方法,并且我无法再更改CODECAPI_AVEncCommonQuality属性.该文档还说,在Windows 8中不会忽略属性更改,但是我需要在Windows 7上运行此更改.

The problem is that I don't create the H.264 encoder manually. I set the input and the output type on the SinkWriter, and the SinkWriter creates the H.264 encoder automatically. As soon as it creates the encoder, it calls the IMFTransform::SetOutputType method, and I can't change the CODECAPI_AVEncCommonQuality property anymore. The documentation also says that the property change isn't ignored in Windows 8, but I need this to run on Windows 7.

您知道在Windows 7上使用SinkWriter时如何更改编码文件的质量吗?

Do you know how I can change the quality for the encoded file while using SinkWriter on Windows 7?

PS:有人问过在msdn论坛上有同样的问题,他似乎没有得到答案.

PS: Someone asked the same question on the msdn forums, and he didn't seem to get an answer.

推荐答案

正如文档所述,您只能在设置输出类型后才能更改CODECAPI_AVEncCommonQuality属性,而SinkWriter会在设置输出类型之前就可以进行设置把手放在编码器上.

As the documentation says, you just can't change the CODECAPI_AVEncCommonQuality property after the output type is set, and the SinkWriter sets the output type before you can get a hand on the encoder.

为了绕过此问题,我设法创建了一个类工厂并将其注册到Media Foundation中,以便SinkWriter使用它来创建新的编码器.在我的班级工厂中,我创建了一个新的H264编码器,并设置了想要的任何属性,然后再将其传递给SinkWriter.

In order to bypass this problem I managed to create a class factory and register it in Media Foundation, so that the SinkWriter uses it to create a new encoder. In my class factory, I create a new H264 encoder and set whatever properties I want before passing it on to the SinkWriter.

我已经在MSDN论坛上(此处为

I have written in more detail the steps I took to create this class factory on the MSDN forums, here: http://social.msdn.microsoft.com/Forums/en-US/mediafoundationdevelopment/thread/6da521e9-7bb3-4b79-a2b6-b31509224638

那是我可以在Windows 7上解决问题的唯一方法.

That was the only way I could get around my problem on Windows 7.

这篇关于使用SinkWriter编码视频时更改h.264质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆