Share via

How the media bitrate information is obtained in file property

domo 0 Reputation points
2024-03-11T03:06:41.4566667+00:00

The following code to query the video encoding bitrate of a media file (mp4) yields a number that deviates significantly from the value obtained by viewing it with other tools like mediainfo/ffprobe:

#include <windows.h>
#include <shlobj.h>
#include <propvarutil.h>
#include <propkey.h>
#include <iostream>
int main() {
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    IShellItem2* pItem = NULL;
    HRESULT hr = SHCreateItemFromParsingName(L"test.mp4", NULL, IID_PPV_ARGS(&pItem));
    if (SUCCEEDED(hr)) {
        PROPVARIANT propvar;
        hr = pItem->GetProperty(PKEY_Video_EncodingBitrate, &propvar);
        if (SUCCEEDED(hr) && propvar.vt == VT_UI4) {
            std::cout << "Video Encoding Bitrate: " << propvar.ulVal / 1024 << " kbps" << std::endl;
            PropVariantClear(&propvar);
        }
    }
    CoUninitialize();
    return 0;
} 

User's image

图片

Open source tools mediainfo and ffprobe results are consistent, and the algorithm is known. The question is how Windows gets this bitrate information. I have tried a variety of calculation methods, but still cannot get the results of Windows calculations. I don't know if it's a Windows calculation error, or there is some unique calculation method.

Windows development | Windows API - Win32
Windows for business | Windows Client for IT Pros | User experience | Other
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.