在Directshow中使用硬解码一般通过DXVA技术,这是微软针对Windows系统定义的硬件加速解码的一个标准接口,目前很多显卡厂商已经实现了。通过DXVA接口,我们以一种统一的接口形式访问各种显卡的硬件加速(解码)功能,还可以通过API接口设置参数来控制解码的一些流程。但这篇博文不是给大家讲怎么用DXVA API来解码视频,而是介绍另外一种简单的方法:通过LAV Video Decoder。这是一个Directshow解码器插件,是开源的LAV Filters里面的一个子插件。
LAVVideo即支持软解码,也支持硬解码(封装了DXVA接口),并且Filter提供接口给外部设置解码器的一些参数。下载LAV Filters的二进制文件包,里面有个developer_info目录,进去找到LAVVideoSettings.h,这个头文件声明了LAVVideo Decode Filter实现的接口。这个类的声明如下:
// LAV Video configuration interface
[uuid("FA40D6E9-4D38-4761-ADD2-71A9EC5FD32F")]
interface ILAVVideoSettings : public IUnknown
{
// Switch to Runtime Config mode. This will reset all settings to default, and no changes to the settings will be saved
// You can use this to programmatically configure LAV Video without interfering with the users settings in the registry.
// Subsequent calls to this function will reset all settings back to defaults, even if the mode does not change.
//
// Note that calling this function during playback is not supported and may exhibit undocumented behaviour.
// For smooth operations, it must be called before LAV Video is connected to other filters.
STDMETHOD(SetRuntimeConfig)(BOOL bRuntimeConfig) = 0;
// Configure which codecs are enabled
// If vCodec is invalid (possibly a version difference), Get will return FALSE, and Set E_FAIL.
STDMETHOD_(BOOL,GetFormatConfiguration)(LAVVideoCodec vCodec) = 0;
STDMETHOD(SetFormatConfiguration)(LAVVideoCodec vCodec, BOOL bEnabled) = 0;
// Set the number of threads to use for Multi-Threaded decoding (where available)
// 0 = Auto De