次の方法で共有


MFSampleExtension_VideoEncodeBitsUsedMap属性

エンコードされたビデオ フレーム内の各ブロックのエンコードに使用されるビット数のマップを格納します。

データの種類

IMFMediaBuffer

注釈

使用されるビット マップにアクセスすると、開発者はエンコードされたフレーム全体のビット割り当てを分析できます。 これは、非効率性の診断、エンコード戦略の調整、ビデオの重要な領域が適切なビット割り当てを確実に受け取るのに役立ちます。

map を使用するビットは 、uint32_tの配列です。 各ブロックには、ブロックのエンコードに使用されるビット数を表す 1 つの uint32_t 値があります。 開発者は、 CODECAPI_AVEncVideoOutputBitsUsedMapBlockSize とビデオ フレームの幅と高さを使用してマップのサイズを決定する必要があります (幅/高さをブロック サイズで除算します。幅/高さがブロック サイズの正確な倍数でない場合は、ブロック サイズの次の倍数に切り上げます)。 これにより、行と列の数が提供され、ビデオ フレームとの適切な配置が保証されます。 マップは左から右、上から下に表示されます。

IMFAttributes::SetUnknown を使用して、QP マップを含む IMFMediaBuffer を出力サンプルにアタッチします。 IMFAttributes::GetUnknown を使用して、出力サンプルから QP マップを含む IMFMediaBuffer を取得します。

マップを使用するビットは、フレーム全体のエンコードが完了したときにのみ報告する必要があります。 エンコーダーが複数のスライスを使用する場合は、PSNR バッファーを最後のスライスの IMFSample にアタッチする必要があります。

例示

次の例では、 CODECAPI_AVEncVideoOutputBitsUsedMapBlockSize プロパティを使用して、マップ機能を使用したビットのレポートを有効または無効にするようにエンコーダー MFT を構成する方法を示します。 ブロック サイズが 0 の場合は無効になります。 ゼロでない場合は、有効になります。

#include <codecapi.h> 
#include <mfapi.h>
#include <wil.com.h>
#include <wil/result_macros.h>

//  Inform an encoder MFT to enable or disable reporting the bits used map feature. 
//  This function assumes that the encoder MFT supports ICodecAPI interface. 
//  It checks whether the property CODECAPI_AVEncVideoOutputBitsUsedMapBlockSize is supported. 
//  If not supported, it returns E_NOTIMPL. 

HRESULT ConfigureEncoderForBitsUsedMap(_In_ IMFTransform* encoder, uint32_t blockSize) 
{ 
    wil::com_ptr_nothrow<ICodecAPI> codecAPI; 
    RETURN_IF_FAILED(wil::com_query_to_nothrow(encoder, &codecAPI)); 

    // Check if the encoder supports the property 
    if (!codecAPI->IsSupported(&CODECAPI_AVEncVideoOutputBitsUsedMapBlockSize)) 
    { 
        return E_NOTIMPL; 
    } 

    // Configure encoder 
    wil::unique_variant value; 
    value.vt = VT_UI4; 
    value.ulVal = blockSize; // zero: disable; non-zero: enable 
    return codecAPI->SetValue(&CODECAPI_AVEncVideoOutputBitsUsedMapBlockSize, &value); 
} 

次の例は、 ICodecAPI をサポートするエンコーダー MFT の実装で使用できるヘルパー関数を示しています。 この関数は、エンコーダー MFT でマップ レポートを使用したビットが有効になっているかどうかを確認する方法を示します。 有効になっている場合、この関数は、マップを使用したビットを出力サンプルにアタッチする方法を示します。 これは、各出力サンプルに完全なフレームが含まれていることを前提としています。 エンコーダーが複数のスライスを使用する場合、マップを使用するビットは、最後のスライスの IMFSample にのみアタッチする必要があります。

#include <mfapi.h> 
#include <mfobjects.h> 
#include <codecapi.h> 
#include <wil.com.h>
#include <wil/result_macros.h>

// Function to query and attach bits used map to output samples 

HRESULT ReportBitsUsedMapOnOutputSample( 
    _In_ IMFTransform* encoder,  
    _In_ IMFSample* outputSample,  
    _In_ IMFMediaBuffer* bitsUsedMap // IMFMediaBuffer could be the GPU resource for bits used map if using hardware encoder 
)  
{ 
    RETURN_HR_IF_NULL(E_INVALIDARG, encoder); 
    RETURN_HR_IF_NULL(E_INVALIDARG, outputSample); 
    RETURN_HR_IF_NULL(E_INVALIDARG, bitsUsedMap); 

    // Query the encoder's codec API to check if bits used Map reporting is enabled 
    wil::com_ptr_nothrow<ICodecAPI> codecAPI; 
    RETURN_IF_FAILED(wil::com_query_to_nothrow(encoder, &codecAPI)); 

    wil::unique_variant value; 
    RETURN_IF_FAILED(codecAPI->GetValue(&CODECAPI_AVEncVideoOutputBitsUsedMapBlockSize, &value)); 

    if (value.vt != VT_UI4 || !value.ulVal) { 
        return S_OK; // Bits Used Map not enabled 
    } 

    // Attach the IMFMediaBuffer (Bits Used Map) to the output sample's attributes 
    wil::com_ptr_nothrow<IMFAttributes> sampleAttributes; 
    RETURN_IF_FAILED(wil::com_query_to_nothrow(outputSample, &sampleAttributes)); 

    return sampleAttributes->SetUnknown(MFSampleExtension_VideoEncodeBitsUsedMap, bitsUsedMap); 
}

次の例は、エンコーダー MFT によって生成された IMFSample オブジェクトからマップ データを使用するビットをアプリが取得する方法を示しています。

#include <mfapi.h> 
#include <mfobjects.h> 
#include <codecapi.h> 
#include <wil.com.h>
#include <wil/result_macros.h>

// Function to retrieve the bits used map data from an output sample 
HRESULT RetrieveBitsUsedMapFromOutputSample( 
    _In_ IMFSample* outputSample,  
    _COM_Outptr_result_maybenull_ IMFMediaBuffer** bitsUsedMap // Output: IMFMediaBuffer containing the bits used map 
) 
{ 

    RETURN_HR_IF_NULL(E_INVALIDARG, bitsUsedMap); 
    *bitsUsedMap = nullptr; 

    RETURN_HR_IF_NULL(E_INVALIDARG, outputSample); 

    // Retrieve the sample attributes 
    wil::com_ptr_nothrow<IMFAttributes> sampleAttributes; 
    RETURN_IF_FAILED(wil::com_query_to_nothrow(outputSample, &sampleAttributes)); 

    // Retrieve the IMFMediaBuffer associated with the bits used map 
    (void)sampleAttributes->GetUnknown(MFSampleExtension_VideoEncodeBitsUsedMap, IID_PPV_ARGS(bitsUsedMap)); 

    return S_OK; 

} 

要求事項

要件 価値
サポートされている最小のクライアント Windows 11 ビルド 26100
サポートされている最小のサーバー Windows Server 2025
ヘッダ mfapi.h