{"id":1505,"date":"2014-02-08T21:48:14","date_gmt":"2014-02-08T19:48:14","guid":{"rendered":"https:\/\/alax.info\/blog\/?p=1505"},"modified":"2014-02-08T21:57:47","modified_gmt":"2014-02-08T19:57:47","slug":"media-foundation-mpeg-4-property-handler-might-report-incorrect-video-frame-rate","status":"publish","type":"post","link":"https:\/\/alax.info\/blog\/1505","title":{"rendered":"Media Foundation MPEG-4 Property Handler might report incorrect Video Frame Rate"},"content":{"rendered":"<div>\n<p>To follow up\u00c2\u00a0<a href=\"https:\/\/alax.info\/blog\/1502\" target=\"_blank\">previous post with Media Foundation bug<\/a>, here goes another one related to property handler for MPEG-4 files (<code>.MP4<\/code>) and specific property\u00c2\u00a0<code>PKEY_Video_FrameRate<\/code>\u00c2\u00a0which reports frame rate for given media file.<\/p>\n<p>This is the object responsible for filling columns in explorer, or otherwise visually the bug might look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1506\" alt=\"Image001\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image001.png\" width=\"377\" height=\"515\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image001.png 377w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image001-234x320.png 234w\" sizes=\"auto, (max-width: 377px) 100vw, 377px\" \/><\/p>\n<p>The values of the properties are also accessible programmatically using <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb761473%28v=vs.85%29.aspx\" target=\"_blank\"><code>IPropertyStore::GetValue<\/code><\/a>\u00c2\u00a0API, in which case they are:<\/p>\n<ul>\n<li><code>PKEY_Video_FrameWidth<\/code>:\u00c2\u00a0<code>1280<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>1,280<\/code><\/li>\n<li><code>PKEY_Video_FrameHeight<\/code>:\u00c2\u00a0<code>720<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>720<\/code><\/li>\n<li><span style=\"color: red;\"><strong><code>PKEY_Video_FrameRate<\/code>:\u00c2\u00a0<code>1091345<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>1,091,345<\/code><\/strong><\/span><\/li>\n<li><code>PKEY_Video_Compression<\/code>:\u00c2\u00a0<code>{34363248-0000-0010-8000-00AA00389B71}<\/code>\u00c2\u00a0(<code>VT_LPWSTR<\/code>) \/\/ FourCC H264<\/li>\n<li><code>PKEY_Video_FourCC<\/code>:\u00c2\u00a0<code>875967048<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>875,967,048<\/code><\/li>\n<li><code>PKEY_Video_HorizontalAspectRatio<\/code>:\u00c2\u00a0<code>1<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>1<\/code><\/li>\n<li><code>PKEY_Video_VerticalAspectRatio<\/code>:\u00c2\u00a0<code>1<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>1<\/code><\/li>\n<li><code>PKEY_Video_StreamNumber<\/code>:\u00c2\u00a0<code>2<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>2<\/code><\/li>\n<li><code>PKEY_Video_TotalBitrate<\/code>:\u00c2\u00a0<code>12123288<\/code>\u00c2\u00a0(<code>VT_UI4<\/code>) \/\/\u00c2\u00a0<code>12,123,288<\/code><\/li>\n<\/ul>\n<p>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 <code>mdhd<\/code>\u00c2\u00a0box for the video track shows the following information:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1507\" alt=\"Image003\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image003.png\" width=\"619\" height=\"449\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image003.png 619w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image003-320x232.png 320w\" sizes=\"auto, (max-width: 619px) 100vw, 619px\" \/><\/p>\n<p>Let us do some math now:<\/p>\n<ul>\n<li>Time Scale:\u00c2\u00a0<code>10,000,000<\/code><\/li>\n<li>Duration:\u00c2\u00a0<code>4,501,200,000<\/code>\u00c2\u00a0(around 7.5 minutes)<\/li>\n<li>Video Sample Count:\u00c2\u00a0<code>22,506<\/code><\/li>\n<\/ul>\n<p>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:<\/p>\n<blockquote><p>22506 \/ (4501200000 &amp; ((1 &lt;&lt; 32) &#8211; 1)) * 10000000<\/p><\/blockquote>\n<p>And we get\u00c2\u00a0<code>1,091<\/code>. Bingo! Arithmetic overflow in the property handler then&#8230;<\/p>\n<p>See also:<\/p>\n<ul>\n<li><a href=\"https:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/816075\/media-foundation-mpeg-4-property-handler-returns-incorrect-video-frame-rate\" target=\"_blank\">Media Foundation MPEG-4 Property Handler returns incorrect Video Frame Rate<\/a>\u00c2\u00a0on Microsoft Connect (including media sample)<\/li>\n<\/ul>\n<p>Bonus tool:\u00c2\u00a0<code>FilePropertyStore<\/code>\u00c2\u00a0application which reads properties of the file you drag and drop onto it,\u00c2\u00a0<a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Toolbox\/FilePropertyStore-Win32.exe\" target=\"_blank\"><code>Win32<\/code><\/a>\u00c2\u00a0and\u00c2\u00a0<a href=\"https:\/\/www.alax.info\/svn\/public\/trunk\/Toolbox\/FilePropertyStore-x64.exe\" target=\"_blank\"><code>x64<\/code><\/a>\u00c2\u00a0versions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1508\" alt=\"Image002\" src=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image0021.png\" width=\"541\" height=\"314\" srcset=\"https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image0021.png 541w, https:\/\/alax.info\/blog\/wp-content\/uploads\/2014\/02\/Image0021-320x185.png 320w\" sizes=\"auto, (max-width: 541px) 100vw, 541px\" \/><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>To follow up\u00c2\u00a0previous post with Media Foundation bug, here goes another one related to property handler for MPEG-4 files (.MP4) and specific property\u00c2\u00a0PKEY_Video_FrameRate\u00c2\u00a0which 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: The values of the properties are&hellip; <\/p>\n<p><a class=\"moretag\" href=\"https:\/\/alax.info\/blog\/1505\">Read the full article<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[63,379,424,470,471,472,168,150],"class_list":["post-1505","post","type-post","status-publish","format-standard","hentry","category-video","tag-bug","tag-h-264","tag-media-foundation","tag-mp4","tag-mpeg-4","tag-property-handler","tag-shell","tag-windows"],"_links":{"self":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/comments?post=1505"}],"version-history":[{"count":0,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/posts\/1505\/revisions"}],"wp:attachment":[{"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/media?parent=1505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/categories?post=1505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alax.info\/blog\/wp-json\/wp\/v2\/tags?post=1505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}