Win32 API 日本語リファレンス
ホームMedia.MediaFoundation › DXVA2_VideoDesc

DXVA2_VideoDesc

構造体
サイズx64: 48 バイト / x86: 40 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
SampleWidthDWORD4+0+0ビデオ フレームの幅 (ピクセル単位)。
SampleHeightDWORD4+4+4ビデオ フレームの高さ (ピクセル単位)。
SampleFormatDXVA2_ExtendedFormat8/4+8+8ビデオ形式に関する追加の詳細。DXVA2_ExtendedFormat 構造体として指定します。
FormatD3DFORMAT4+16+12サーフェイスの形式。D3DFORMAT 値または FOURCC コードとして指定します。FOURCC コードは D3DFORMAT マクロまたは MAKEFOURCC マクロを使用して構築できます。
InputSampleFreqDXVA2_Frequency8+20+16入力ビデオ ストリームのフレーム レート。DXVA2_Frequency 構造体として指定します。
OutputFrameFreqDXVA2_Frequency8+28+24出力ビデオのフレーム レート。DXVA2_Frequency 構造体として指定します。
UABProtectionLevelDWORD4+36+32ユーザーがアクセス可能なバス (UAB) が存在する場合に必要となるデータ保護のレベル。TRUE の場合、UAB が存在するときはビデオを保護する必要があります。FALSE の場合、ビデオを保護する必要はありません。
ReservedDWORD4+40+36予約済みです。0 でなければなりません。

公式ドキュメント

DXVA デコーダー デバイスまたはビデオ プロセッサー デバイス用のビデオ ストリームを記述します。

解説(Remarks)

InputSampleFreq メンバーは、ビデオ レンダラーが受け取るデコード済みビデオ ストリームのフレーム レートを示します。OutputFrameFreq メンバーは、インターレース解除後に表示されるビデオのフレーム レートを示します。入力ビデオがインターレースであり、サンプルにインターリーブされたフィールドが含まれる場合、出力フレーム レートは入力フレーム レートの 2 倍になります。入力ビデオがプログレッシブである場合、または単一のフィールドを含む場合、出力フレーム レートは入力フレーム レートと同じです。

フレーム レートが判明している場合、デコーダーは InputSampleFreqOutputFrameFreq の値を設定してください。判明していない場合は、これらのメンバーを 0/0 に設定して、フレーム レートが不明であることを示します。

次のコードは、IMFMediaType インターフェイスで表される Media Foundation のメディア タイプを DXVA2_VideoDesc 構造体に変換します。

// Fills in the DXVA2_ExtendedFormat structure.
void GetDXVA2ExtendedFormatFromMFMediaType(
    IMFMediaType *pType, 
    DXVA2_ExtendedFormat *pFormat
)
{
    // Get the interlace mode.
    MFVideoInterlaceMode interlace = 
        (MFVideoInterlaceMode)MFGetAttributeUINT32(
            pType, MF_MT_INTERLACE_MODE, MFVideoInterlace_Unknown
         );

    // The values for interlace mode translate directly, except for mixed 
    // interlace or progressive mode.

    if (interlace == MFVideoInterlace_MixedInterlaceOrProgressive)
    {
        // Default to interleaved fields.
        pFormat->SampleFormat = DXVA2_SampleFieldInterleavedEvenFirst;
    }
    else
    {
        pFormat->SampleFormat = (UINT)interlace;
    }

    // The remaining values translate directly.
    
    // Use the "no-fail" attribute functions and default to "unknown."
    
    pFormat->VideoChromaSubsampling = MFGetAttributeUINT32(
        pType, MF_MT_VIDEO_CHROMA_SITING, MFVideoChromaSubsampling_Unknown);

    pFormat->NominalRange = MFGetAttributeUINT32(
        pType, MF_MT_VIDEO_NOMINAL_RANGE, MFNominalRange_Unknown);

    pFormat->VideoTransferMatrix = MFGetAttributeUINT32(
        pType, MF_MT_YUV_MATRIX, MFVideoTransferMatrix_Unknown);

    pFormat->VideoLighting = MFGetAttributeUINT32(
        pType, MF_MT_VIDEO_LIGHTING, MFVideoLighting_Unknown);

    pFormat->VideoPrimaries = MFGetAttributeUINT32(
        pType, MF_MT_VIDEO_PRIMARIES, MFVideoPrimaries_Unknown);

    pFormat->VideoTransferFunction = MFGetAttributeUINT32(
        pType, MF_MT_TRANSFER_FUNCTION, MFVideoTransFunc_Unknown);

}


HRESULT ConvertMFTypeToDXVAType(IMFMediaType *pType, DXVA2_VideoDesc *pDesc)
{
    ZeroMemory(pDesc, sizeof(*pDesc));

    GUID                    subtype = GUID_NULL;
    UINT32                  width = 0;
    UINT32                  height = 0;
    UINT32                  fpsNumerator = 0;
    UINT32                  fpsDenominator = 0;

    // The D3D format is the first DWORD of the subtype GUID.
    HRESULT hr = pType->GetGUID(MF_MT_SUBTYPE, &subtype);
    if (FAILED(hr))
    {
        goto done;
    }

    pDesc->Format = (D3DFORMAT)subtype.Data1;

    // Frame size.
    hr = MFGetAttributeSize(pType, MF_MT_FRAME_SIZE, &width, &height);
    if (FAILED(hr))
    {
        goto done;
    }

    pDesc->SampleWidth = width;
    pDesc->SampleHeight = height;

    // Frame rate.
    hr = MFGetAttributeRatio(pType, MF_MT_FRAME_RATE, &fpsNumerator, &fpsDenominator);
    if (FAILED(hr))
    {
        goto done;
    }

    pDesc->InputSampleFreq.Numerator = fpsNumerator;
    pDesc->InputSampleFreq.Denominator = fpsDenominator;

    // Extended format information.
    GetDXVA2ExtendedFormatFromMFMediaType(pType, &pDesc->SampleFormat);

    // For progressive or single-field types, the output frequency is the same as
    // the input frequency. For interleaved-field types, the output frequency is
    // twice the input frequency.  
    pDesc->OutputFrameFreq = pDesc->InputSampleFreq;

    if ((pDesc->SampleFormat.SampleFormat == DXVA2_SampleFieldInterleavedEvenFirst) ||
        (pDesc->SampleFormat.SampleFormat == DXVA2_SampleFieldInterleavedOddFirst))
    {
        pDesc->OutputFrameFreq.Numerator *= 2;
    }

done:
    return hr;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// DXVA2_ExtendedFormat  (x64 8 / x86 4 バイト)
typedef struct DXVA2_ExtendedFormat {
    _Anonymous_e__Union Anonymous;
} DXVA2_ExtendedFormat;

// DXVA2_Frequency  (x64 8 / x86 8 バイト)
typedef struct DXVA2_Frequency {
    DWORD Numerator;
    DWORD Denominator;
} DXVA2_Frequency;

// DXVA2_VideoDesc  (x64 48 / x86 40 バイト)
typedef struct DXVA2_VideoDesc {
    DWORD SampleWidth;
    DWORD SampleHeight;
    DXVA2_ExtendedFormat SampleFormat;
    D3DFORMAT Format;
    DXVA2_Frequency InputSampleFreq;
    DXVA2_Frequency OutputFrameFreq;
    DWORD UABProtectionLevel;
    DWORD Reserved;
} DXVA2_VideoDesc;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DXVA2_ExtendedFormat
{
    public _Anonymous_e__Union Anonymous;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DXVA2_Frequency
{
    public uint Numerator;
    public uint Denominator;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DXVA2_VideoDesc
{
    public uint SampleWidth;
    public uint SampleHeight;
    public DXVA2_ExtendedFormat SampleFormat;
    public uint Format;
    public DXVA2_Frequency InputSampleFreq;
    public DXVA2_Frequency OutputFrameFreq;
    public uint UABProtectionLevel;
    public uint Reserved;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DXVA2_ExtendedFormat
    Public Anonymous As _Anonymous_e__Union
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DXVA2_Frequency
    Public Numerator As UInteger
    Public Denominator As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DXVA2_VideoDesc
    Public SampleWidth As UInteger
    Public SampleHeight As UInteger
    Public SampleFormat As DXVA2_ExtendedFormat
    Public Format As UInteger
    Public InputSampleFreq As DXVA2_Frequency
    Public OutputFrameFreq As DXVA2_Frequency
    Public UABProtectionLevel As UInteger
    Public Reserved As UInteger
End Structure
import ctypes
from ctypes import wintypes

class DXVA2_ExtendedFormat(ctypes.Structure):
    _fields_ = [
        ("Anonymous", _Anonymous_e__Union),
    ]

class DXVA2_Frequency(ctypes.Structure):
    _fields_ = [
        ("Numerator", wintypes.DWORD),
        ("Denominator", wintypes.DWORD),
    ]

class DXVA2_VideoDesc(ctypes.Structure):
    _fields_ = [
        ("SampleWidth", wintypes.DWORD),
        ("SampleHeight", wintypes.DWORD),
        ("SampleFormat", DXVA2_ExtendedFormat),
        ("Format", wintypes.DWORD),
        ("InputSampleFreq", DXVA2_Frequency),
        ("OutputFrameFreq", DXVA2_Frequency),
        ("UABProtectionLevel", wintypes.DWORD),
        ("Reserved", wintypes.DWORD),
    ]
#[repr(C)]
pub struct DXVA2_ExtendedFormat {
    pub Anonymous: _Anonymous_e__Union,
}

#[repr(C)]
pub struct DXVA2_Frequency {
    pub Numerator: u32,
    pub Denominator: u32,
}

#[repr(C)]
pub struct DXVA2_VideoDesc {
    pub SampleWidth: u32,
    pub SampleHeight: u32,
    pub SampleFormat: DXVA2_ExtendedFormat,
    pub Format: u32,
    pub InputSampleFreq: DXVA2_Frequency,
    pub OutputFrameFreq: DXVA2_Frequency,
    pub UABProtectionLevel: u32,
    pub Reserved: u32,
}
import "golang.org/x/sys/windows"

type DXVA2_ExtendedFormat struct {
	Anonymous _Anonymous_e__Union
}

type DXVA2_Frequency struct {
	Numerator uint32
	Denominator uint32
}

type DXVA2_VideoDesc struct {
	SampleWidth uint32
	SampleHeight uint32
	SampleFormat DXVA2_ExtendedFormat
	Format uint32
	InputSampleFreq DXVA2_Frequency
	OutputFrameFreq DXVA2_Frequency
	UABProtectionLevel uint32
	Reserved uint32
}
type
  DXVA2_ExtendedFormat = record
    Anonymous: _Anonymous_e__Union;
  end;

  DXVA2_Frequency = record
    Numerator: DWORD;
    Denominator: DWORD;
  end;

  DXVA2_VideoDesc = record
    SampleWidth: DWORD;
    SampleHeight: DWORD;
    SampleFormat: DXVA2_ExtendedFormat;
    Format: DWORD;
    InputSampleFreq: DXVA2_Frequency;
    OutputFrameFreq: DXVA2_Frequency;
    UABProtectionLevel: DWORD;
    Reserved: DWORD;
  end;
const DXVA2_ExtendedFormat = extern struct {
    Anonymous: _Anonymous_e__Union,
};

const DXVA2_Frequency = extern struct {
    Numerator: u32,
    Denominator: u32,
};

const DXVA2_VideoDesc = extern struct {
    SampleWidth: u32,
    SampleHeight: u32,
    SampleFormat: DXVA2_ExtendedFormat,
    Format: u32,
    InputSampleFreq: DXVA2_Frequency,
    OutputFrameFreq: DXVA2_Frequency,
    UABProtectionLevel: u32,
    Reserved: u32,
};
type
  DXVA2_ExtendedFormat {.bycopy.} = object
    Anonymous: _Anonymous_e__Union

  DXVA2_Frequency {.bycopy.} = object
    Numerator: uint32
    Denominator: uint32

  DXVA2_VideoDesc {.bycopy.} = object
    SampleWidth: uint32
    SampleHeight: uint32
    SampleFormat: DXVA2_ExtendedFormat
    Format: uint32
    InputSampleFreq: DXVA2_Frequency
    OutputFrameFreq: DXVA2_Frequency
    UABProtectionLevel: uint32
    Reserved: uint32
struct DXVA2_ExtendedFormat
{
    _Anonymous_e__Union Anonymous;
}

struct DXVA2_Frequency
{
    uint Numerator;
    uint Denominator;
}

struct DXVA2_VideoDesc
{
    uint SampleWidth;
    uint SampleHeight;
    DXVA2_ExtendedFormat SampleFormat;
    uint Format;
    DXVA2_Frequency InputSampleFreq;
    DXVA2_Frequency OutputFrameFreq;
    uint UABProtectionLevel;
    uint Reserved;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; DXVA2_VideoDesc サイズ: 40 バイト(x86)
dim st, 10    ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; SampleWidth : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; SampleHeight : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; SampleFormat : DXVA2_ExtendedFormat (+8, 4byte)  varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; Format : D3DFORMAT (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; InputSampleFreq : DXVA2_Frequency (+16, 8byte)  varptr(st)+16 を基点に操作(8byte:入れ子/配列)
; OutputFrameFreq : DXVA2_Frequency (+24, 8byte)  varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; UABProtectionLevel : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; Reserved : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; DXVA2_VideoDesc サイズ: 48 バイト(x64)
dim st, 12    ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; SampleWidth : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; SampleHeight : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; SampleFormat : DXVA2_ExtendedFormat (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; Format : D3DFORMAT (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; InputSampleFreq : DXVA2_Frequency (+20, 8byte)  varptr(st)+20 を基点に操作(8byte:入れ子/配列)
; OutputFrameFreq : DXVA2_Frequency (+28, 8byte)  varptr(st)+28 を基点に操作(8byte:入れ子/配列)
; UABProtectionLevel : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; Reserved : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global DXVA2_ExtendedFormat
    #field byte Anonymous 8
#endstruct

#defstruct global DXVA2_Frequency
    #field int Numerator
    #field int Denominator
#endstruct

#defstruct global DXVA2_VideoDesc
    #field int SampleWidth
    #field int SampleHeight
    #field DXVA2_ExtendedFormat SampleFormat
    #field int Format
    #field DXVA2_Frequency InputSampleFreq
    #field DXVA2_Frequency OutputFrameFreq
    #field int UABProtectionLevel
    #field int Reserved
#endstruct

stdim st, DXVA2_VideoDesc        ; NSTRUCT 変数を確保
st->SampleWidth = 100
mes "SampleWidth=" + st->SampleWidth