Media Foundation——媒体类型(1)
Media Foundaton对象的属性和特性
每一个对象上的数据,都可通过“属性(Attributes)”和“特性(Properties)”来设置、描述。属性和特性相似但不同。
在Media Foundation中使用属性(Attributes)
属性(Attributes)= key +value
Key
是个GUID
Value
是个变量。变量的类型局限于:
ü UInt32
ü UInt64
ü 64-bit浮点数
ü GUID
ü 以NULL结尾的宽字符类型(wide-character)字符串
ü 字节数组
ü IUnknown指针
以上类型被包含在MF_ATTRIBUTE_TYPE枚举类型中:
typedef enum _MF_ATTRIBUTE_TYPE {
MF_ATTRIBUTE_UINT32 = VT_UI4,
MF_ATTRIBUTE_UINT64 = VT_UI8,
MF_ATTRIBUTE_DOUBLE = VT_R8,
MF_ATTRIBUTE_GUID = VT_CLSID,
MF_ATTRIBUTE_STRING = VT_LPWSTR,
MF_ATTRIBUTE_BLOB = VT_VECTOR | VT_UI1,
MF_ATTRIBUTE_IUNKNOWN = VT_UNKNOWN
} MF_ATTRIBUTE_TYPE;
属性(Attributes)的说明
通过IMFAttributes接口定义属性组,这个接口是类型安全的。例如,设置32位的整形,可调用:IMFAttributes::SetUINT32。
属性(Attributes)中的key是唯一的,如果设置了两个相同key的属性(Attributes),则只有后一个有效。
通常IMFAttributes类型的指针会作为应用程序中某函数的参数,应用程序负责创建属性集,创建一个空属性集可用MFCreateAttribute。
HRESULT MFCreateAttributes(
__out IMFAttributes **ppMFAttributes,
__in UINT32 cInitialSize //存储的属性的初始元素数
);
举例
例子一
创建一个新属性集(Attributes),属性集名字为MY_ATTRIBUTE
extern const GUID MY_ATTRIBUTE;
HRESULT ShowCreateAttributeStore(IMFAttributes **ppAttributes)
{
IMFAttributes *pAttributes = NULL;
const UINT32 cElements = 10; // 初始为10个元素
// Create the empty attribute store.
HRESULT hr = MFCreateAttributes(&pAttributes, cElements);
//给key为MY_ATTRIBUTE的属性设置value.,value是字符串类型
if (SUCCEEDED(hr))
{
hr = pAttributes->SetString(
MY_ATTRIBUTE,
L"This is a string value"
);
}
// Return the IMFAttributes pointer to the caller.
if (SUCCEEDED(hr))
{
*ppAttributes = pAttributes;
(*ppAttributes)->AddRef();//注意:增加引用
}
SAFE_RELEASE(pAttributes);
return hr;
}
例子二
获取设置的属性的value
HRESULT ShowGetAttributes()
{
IMFAttributes *pAttributes = NULL;
WCHAR *pwszValue = NULL;
UINT32 cchLength = 0;
// Create the attribute store.
HRESULT hr = ShowCreateAttributeStore(&pAttributes);
// Get the attribute.
if (SUCCEEDED(hr))
{
hr = pAttributes->GetAllocatedString(
MY_ATTRIBUTE,//key
&pwszValue,//获取key对应的value,value是字符串类型
&cchLength//获取key对应的value的长度
);
}
CoTaskMemFree(pwszValue);
SAFE_RELEASE(pAttributes);
return hr;
}
属性序列化
可通过两种方式对存储的属性序列化:
ü 将属性集写入字节数组
ü 将属性集通过IStream写入流(Stream)
如果属性的value是IUnknown类型,即对应类型枚举值中的MF_ATTRIBUTE_IUNKNOWN,将不能被序列化。
Operation |
Byte Array |
IStream |
Save |
MFGetAttributesAsBlob |
MFSerializeAttributesToStream |
Load |
MFInitAttributesFromBlob |
MFDeserializeAttributesFromStream |
HRESULT MFGetAttributesAsBlob(
__in IMFAttributes *pAttributes,
__out UINT8 *pBuf,//存储属性数据的数组
__in UINT cbBufSize//pBuf数组的字节长度
);
HRESULT MFSerializeAttributesToStream(
IMFAttributes *pAttr,
DWORD dwOptions,//如果被设置为MF_ATTRIBUTE_SERIALIZE_UNKNOWN_BYREF ,根据pstm的情况,决定如何序列化
IStream *pStm//存储流的指针
);
在Media Foundation中使用特性(Properties)
一个特性也是一个key/value对。
Key是PROPERTYKEY结构体,该结构体由“GUID+DWORD型的值”组成
typedef struct {
GUID fmtid;
DWORD pid;//可设置从2往上的值,0、1被系统保留
} PROPERTYKEY;
设置和获取一个Media Foundation的对象的特性(Properties),要用到IPropertyStore接口。IPropertyStore接口中定义了一些方法:
Commit |
Saves a property change. |
GetAt |
Gets a property key from an item's array of properties. |
GetCount |
Gets the number of properties attached to the file. |
GetValue |
Gets data for a specific property. |
SetValue |
Sets a new property value, or replaces or removes an existing value. |
媒体类型(Media Type)
简介
媒体类型通过IMFMediaType接口描述,IMFMediaType继承自IMFAttribute,所以Media Type就是一些属性(Attribute)
IMFMediaType定义了的方法
Method |
Description |
FreeRepresentation |
Frees memory that was allocated by the GetRepresentation method. |
GetMajorType |
Retrieves the major type of the format. |
GetRepresentation |
Retrieves an alternative representation of the media type.目前只能将Media Foundation中的media type转换为Directshow中的AM_MEDIA_TYPE |
IsCompressedFormat |
Queries whether the media type is a compressed format. |
IsEqual |
Compares two media types and determines whether they are identical. |
优点
Directshow、DMO里面都有媒体类型,Media Foundation中的媒体类型相比它们有以下优点,优点源于Media Foundation的媒体类型是属性(Attribute):
1. 可以省略那些不清楚的音视频参数。而Directshow、DMO的媒体类型的各个字段都必须被填写,而造成写错。
2. 扩展安全。以前的媒体类型都基于结构体(structure),如WAVEFORMATEXTENSIBLE是从WAVEFORMATEX扩展而来,指向结构体的指针指来指去就可能会造成异常发生。
MFCreateMediaType用于创建媒体类型(Media Type)。
媒体类型及子类型
主类型
GUID |
Description |
MFMediaType_Audio |
Audio. |
MFMediaType_Video |
Video. |
MFMediaType_Protected |
Protected media. |
MFMediaType_SAMI |
Synchronized Accessible Media Interchange (SAMI) captions. |
MFMediaType_Script |
Script stream. |
MFMediaType_Image |
Image stream. |
MFMediaType_HTML |
HTML stream. |
MFMediaType_Binary |
Binary stream. |
MFMediaType_FileTransfer |
A stream that contains data files. |
子类型
Creating Subtype GUIDs from FOURCCs and D3DFORMAT Values
These GUIDs have the form XXXXXXXX-0000-0010-8000-00AA00389B71
, where XXXXXXXX
is the 4-byte FOURCC code or D3DFORMAT value. 根据Fourcc来生成GUID!
If a video format has an associated FOURCC or D3DFORMAT value, you can create the corresponding subtype GUID as follows: Start with the constant MFVideoFormat_Base and replace the first DWORD of the GUID with the video FOURCC or the D3DFORMAT value. You can use the DEFINE_MEDIATYPE_GUID Macro for this purpose.
void DEFINE_MEDIATYPE_GUID(
name,
format
);
举例:
#include <initguid.h>
// Declares a GUID named MFVideoFormat_ABCD_Format.
DEFINE_MEDIATYPE_GUID( MFVideoFormat_ABCD_Format, FCC('ABCD') );
Note :Directshow也可以用这种方式生成GUID,但是不压缩的RGB格式除外。但是Media Foundation中的不压缩RGB格式可以用这种方式生成。
Audio Subtype
GUID
The following audio subtype GUIDs are defined. To specify the subtype, set the MF_MT_SUBTYPE attribute on the media type.
GUID |
Description |
MFAudioFormat_Dolby_AC3_SPDIF |
Dolby AC-3 audio over Sony/Philips Digital Interface (S/PDIF). |
MFAudioFormat_DRM |
Uncompressed but encrypted audio data used with secure audio path. |
MFAudioFormat_DTS |
Digital Theater Systems (DTS) audio. |
MFAudioFormat_Float |
Uncompressed IEEE floating-point audio. |
MFAudioFormat_MP3 |
MPEG Audio Layer-3 (MP3). |
MFAudioFormat_MPEG |
MPEG-1 audio payload. |
MFAudioFormat_MSP1 |
Windows Media Audio 9 Voice codec. |
MFAudioFormat_PCM |
Uncompressed PCM audio. |
MFAudioFormat_WMASPDIF |
Windows Media Audio 9 Professional codec over S/PDIF. |
MFAudioFormat_WMAudio_Lossless |
Windows Media Audio 9 Lossless codec or Windows Media Audio 9.1 codec. |
MFAudioFormat_WMAudioV8 |
Windows Media Audio 8 codec, Windows Media Audio 9 codec, or Windows Media Audio 9.1 codec. |
MFAudioFormat_WMAudioV9 |
Windows Media Audio 9 Professional codec or Windows Media Audio 9.1 Professional codec. |
创建音频的subtype,要用MFAudioFormat_Base开头,再加上fourcc。这是规范写法。
创建不压缩的音频Media Type
下面这些属性是必须设置的:
Attribute |
Description |
MF_MT_MAJOR_TYPE |
Major type. Set to MFMediaType_Audio. |
MF_MT_SUBTYPE |
Subtype. See Audio Subtype GUIDs. |
MF_MT_AUDIO_NUM_CHANNELS |
Number of audio channels |
MF_MT_AUDIO_SAMPLES_PER_SECOND |
Number of audio samples per second |
MF_MT_AUDIO_BLOCK_ALIGNMENT |
Block alignment 音频中最小的处理单位。 例如PCM,该值应为:声道数*每个sample的字节数 |
MF_MT_AUDIO_AVG_BYTES_PER_SECOND |
Average number of bytes per second 码率 |
MF_MT_AUDIO_BITS_PER_SAMPLE |
Number of bits per audio sample 采样位数 |
MF_MT_ALL_SAMPLES_INDEPENDENT |
Specifies whether each audio sample is independent. Set to TRUE for MFAudioFormat_PCM and MFAudioFormat_Float formats. 设置每个音频sample是否是时间相关。 |
Video Subtype
GUID
创建音频的subtype,要用MFVideoFormat_Base开头,再加上fourcc。这是规范写法。
不压缩的RGB格式
GUID |
Description |
MFVideoFormat_ARGB32 |
RGB, 32 bits per pixel (bpp) with alpha channel. |
MFVideoFormat_RGB24 |
RGB, 24 bpp. |
MFVideoFormat_RGB32 |
RGB, 32 bpp. |
MFVideoFormat_RGB555 |
RGB 555, 16 bpp. (Same memory layout as D3DFMT_X1R5G5B5.) |
MFVideoFormat_RGB565 |
RGB 565, 16 bpp. (Same memory layout as D3DFMT_R5G6B5.) |
Note 这些子类型和以前的不同,比如和Directshow中的子类型
YUV Formats: 8-Bit and Palettized
GUID |
Format |
Sampling |
Packed or planar |
Bits per channel |
MFVideoFormat_AI44 |
AI44 |
4:4:4 |
Packed |
Palettized |
MFVideoFormat_AYUV |
AYUV |
4:4:4 |
Packed |
8 |
MFVideoFormat_NV11 |
NV11 |
4:1:1 |
Planar |
8 |
MFVideoFormat_NV12 |
NV12 |
4:2:0 |
Planar |
8 |
MFVideoFormat_UYVY |
UYVY |
4:2:2 |
Packed |
8 |
MFVideoFormat_YUY2 |
YUY2 |
4:2:2 |
Packed |
8 |
MFVideoFormat_YV12 |
YV12 |
4:2:0 |
Planar |
8 |
Most of these formats are described in detail in the following MSDN article: Video Rendering with 8-Bit YUV Formats. Two others are described here:
· AI44 is a palettized YUV format with 8 bits per sample. Each sample contains an index in the 4 most significant bits (MSBs) and an alpha value in the 4 least significant bits (LSBs). The index refers to an array of YUV palette entries, which must be defined in the media type for the format.
· NV11 is a 4:1:1 planar format with 12 bits per pixel. The Y samples appear first in memory. The Y plane is followed by an array of packed U (Cb) and V (Cr) samples. When the combined U-V array is addressed as an array of little-endian WORD values, the U samples are contained in the LSBs of each WORD, and the V samples are contained in the MSBs. (This memory layout is similar to NV12 although the chroma sampling is different.)
YUV Formats: 10-Bit and 16-Bit
GUID |
Format |
Sampling |
Packed or planar |
Bits per channel |
MFVideoFormat_IYUV |
IYUV |
4:2:0 |
Planar |
16 |
MFVideoFormat_P010 |
P010 |
4:2:0 |
Planar |
10 |
MFVideoFormat_P016 |
P016 |
4:2:0 |
Planar |
16 |
MFVideoFormat_P210 |
P210 |
4:2:2 |
Planar |
10 |
MFVideoFormat_P216 |
P216 |
4:2:2 |
Planar |
16 |
MFVideoFormat_v210 |
v210 |
4:2:2 |
Packed |
10 |
MFVideoFormat_v410 |
v40 |
4:4:4 |
Packed |
10 |
MFVideoFormat_Y210 |
Y210 |
4:2:2 |
Packed |
10 |
MFVideoFormat_Y216 |
Y216 |
4:2:2 |
Packed |
16 |
MFVideoFormat_Y410 |
Y40 |
4:4:4 |
Packed |
10 |
MFVideoFormat_Y416 |
Y416 |
4:4:4 |
Packed |
16 |
For more information about these formats, see 10-bit and 16-bit YUV Video Formats.
压缩视频类型
GUID |
Description |
MFVideoFormat_DV25 |
DVCPRO 25 (525-60 or 625-50). |
MFVideoFormat_DV50 |
DVCPRO 50 (525-60 or 625-50). |
MFVideoFormat_DVH1 |
DVCPRO 100 (1080/60i, 1080/50i, or 720/60P). |
MFVideoFormat_DVSD |
SDL-DVCR (525-60 or 625-50). |
MFVideoFormat_DVSL |
SD-DVCR (525-60 or 625-50). |
MFVideoFormat_MP43 |
Microsoft MPEG 4 codec version 3. This codec is no longer supported. |
MFVideoFormat_MP4S |
ISO MPEG 4 codec version 1. |
MFVideoFormat_MPEG2 |
MPEG-2 video. (Equivalent to MEDIASUBTYPE_MPEG2_VIDEO in DirectShow.) |
MFVideoFormat_MPG1 |
MPEG-1 video. |
MFVideoFormat_MSS1 |
Windows Media Screen codec version 1. |
MFVideoFormat_MSS2 |
Windows Media Video 9 Screen codec. |
MFVideoFormat_WMV1 |
Windows Media Video codec version 7. |
MFVideoFormat_WMV2 |
Windows Media Video 8 codec. |
MFVideoFormat_WMV3 |
Windows Media Video 9 codec. |
创建不压缩的视频Media Type
YUV介绍
如何使用Media Foundation自带的例子
常用到的宏定义
请注意每个的声明
#define SAFE_RELEASE(x) { if (x != NULL) { x->Release(); x = NULL; } }
#define SAFE_DELETE(x) { if (x != NULL) { delete x; x = NULL; } }
#define SAFE_ARRAY_DELETE(x) { if (x != NULL) { delete [] x; x = NULL; } }
#define CHECK_HR(hr) { if (FAILED(hr)) { goto done; } }
宏使用举例
HRESULT Example()
{
// Declare variables.
HRESULT hr = S_OK;
IUnknown *pUnk = NULL; // Initialize pointers to NULL.
// Do work.
CHECK_HR(hr = CreateAnObject(&pUnk));
CHECK_HR(hr = UseTheObject(pUnk));
done:
// Control always jumps to this point on failure.
// Clean up by releasing resources.
SAFE_RELEASE(pUnk);
return hr;
}
====================================
作者:王琦 Sanford.sh@gmail.com
以上内容为原创,请尊重原创,如转载,请告知作者并注明作者!
Media Foundation——媒体类型(1)相关推荐
- 样式link属性media用法--媒体类型查询
引用外部样式使用link 你可能想针对将要显示页面的设备类型(桌面PC.笔记本电脑.平板电脑.手机或者甚至页面的印刷版本)来调整页面的样式,可以利用一个media属性, 在<link>元素 ...
- Media Type 媒体类型(MIME Type、Content Type)
媒体类型用于声明随之而来的数据的格式.又称:MIME类型.MIME Type.Content Type. 是一种用于在异构系统.分布式网络之间声明并传递信息主体格式的方法. 一般的,在文件系统中,我们 ...
- Java中printmax的调用形式_媒体类型和响应式设计
一.媒体类型: 常用的三种为:all,print和screen 二.媒体类型引用方法:link标签,xml方式,@import和css3新增的@media四种 link方法: link方法引入媒体类型 ...
- CSS基础之媒体类型(@media)样式
定义 使用 @media,可以针对不同的媒体类型定义不同的样式. 使用 @media, 可以针对不同的屏幕尺寸设置不同的样式 当你重置浏览器大小的过程中,页面也会根据浏览器的宽度和高度重新渲染页面. ...
- media属性和媒体类型
一.media属性 当设定样式的时候,可以指定此样式应用于何种媒体,例如: <link rel="stylesheet" href="basic.css" ...
- 媒体类型@media
媒体类型允许你指定文件将如何在不同媒体呈现.该文件可以以不同的方式显示在屏幕上,在纸张上,或听觉浏览器等等. @media 规则允许在相同样式表为不同媒体设置不同的样式. 浏览器屏幕上显示一个14像素 ...
- 视频特效滤镜 via Media Foundation Transform (MFT)
视频特效滤镜 via Media Foundation Transform 视频特效定义 Media Foundation Transform IMFTransform::GetInputStream ...
- 音频特效滤镜 via Media Foundation Transform (MFT)
音频特效滤镜 via Media Foundation Transform 音频特效定义 Media Foundation Transform IMFTransform::GetInputStream ...
- Microsoft Media Foundation官方文档翻译(20)《Stream Subtype GUIDs》《...
官方英文文档链接:https://docs.microsoft.com/en-us/windows/desktop/medfound/stream-subtype-guids 基于05/31/2018 ...
最新文章
- mysql配置_Mysql配置 max_allowed_packet
- 把view或者div绘制 canvas ,导出图片功能实现完整源码附效果图(兼容H5和小程序)
- 20155117 王震宇 2006-2007-2 《Java程序设计》第三周学习总结
- 多线程中数据的并发访问与保护
- FastDFS配置手册trackerstorage
- 26. 左旋转字符串
- php csrf jsonp,读取型CSRF(JSONP劫持、CORS跨域资源读取、Flash跨域劫持)
- Python入门--特殊属性
- linux脚本编程教程,shell脚本编程基础教程
- Kubernetes 小白学习笔记(31)--kubernetes云原生应用开发-istio架构和安装
- 使用procexp.exe查看线程详细信息
- ubuntu安装ROS教程
- Proteus仿真C51利用双定时器输出占空比可变的PWM
- 转:原来可以这样出书、写书?
- 扫雷小游戏(两小时完成)
- 内网代理神奇Venom
- regopenkeyexfailed什么意思_外置网卡驱动安装出现RegOpenKeyEx Failed,怎么回事?
- WebRTC Native M96音频基础知识介绍--使用Opus
- c语言编程 菲薄拉,C语言设计模式-封装-继承-多态
- 要访问1KB的内存为啥需要10位地址线,而不是13位?