How the media bitrate information is obtained in file property
domo
0
Reputation points
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;
}
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.
Sign in to answer