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
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,099 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,523 questions
{count} votes