Media Foundation MPEG-4 Property Handler might report incorrect Video Frame Rate

To follow up previous post with Media Foundation bug, here goes another one related to property handler for MPEG-4 files (.MP4) and specific property PKEY_Video_FrameRate which reports frame rate for given media file.

This is the object responsible for filling columns in explorer, or otherwise visually the bug might look like this:

Image001

The values of the properties are also accessible programmatically using IPropertyStore::GetValue API, in which case they are:

  • PKEY_Video_FrameWidth: 1280 (VT_UI4) // 1,280
  • PKEY_Video_FrameHeight: 720 (VT_UI4) // 720
  • PKEY_Video_FrameRate: 1091345 (VT_UI4) // 1,091,345
  • PKEY_Video_Compression: {34363248-0000-0010-8000-00AA00389B71} (VT_LPWSTR) // FourCC H264
  • PKEY_Video_FourCC: 875967048 (VT_UI4) // 875,967,048
  • PKEY_Video_HorizontalAspectRatio: 1 (VT_UI4) // 1
  • PKEY_Video_VerticalAspectRatio: 1 (VT_UI4) // 1
  • PKEY_Video_StreamNumber: 2 (VT_UI4) // 2
  • PKEY_Video_TotalBitrate: 12123288 (VT_UI4) // 12,123,288

The actual frame rate of the file is 50 fps. The file is playable well in every media player, so the problem is the reporting itself. Let us look inside the file to possibly identify the cause. The mdhd box for the video track shows the following information:

Image003

Let us do some math now:

  • Time Scale: 10,000,000
  • Duration: 4,501,200,000 (around 7.5 minutes)
  • Video Sample Count: 22,506

This makes the correct fps of 50 (frames per scaled duration). However the duration number itself is a pretty big one and looks exceeding the 32-bit range. Now let us try this one:

22506 / (4501200000 & ((1 << 32) – 1)) * 10000000

And we get 1,091. Bingo! Arithmetic overflow in the property handler then…

See also:

Bonus tool: FilePropertyStore application which reads properties of the file you drag and drop onto it, Win32 and x64 versions.

Image002

Leave a Reply