We’re working on a pretty cool system for detecting HD video, which has presented us with a small math challenge. It’s nothing too crazy, but we thought it’d be fun to see if anyone was up for helping us figure it out.


If you’d like to help with this algorithm, drop a comment here and/or contact me at: dean [at] pculture dot org.


Scanning for HD Video


Jason (our programming intern) built a scanner that will tell us some stuff about each video file, the most important things being: dimensions (WxH), video bitrate (kbps), and codec. The idea is to end up with a single number that gives us an idea of how relatively badass a video will look.


Resolution


The resolution is pretty straightforward, and I assume that adding width plus height is a good way to end up with a single number that can be compared across resolutions.


Codec & Video Bitrate


The codec/bitrate intersection is where things start to get a little crazier; different codecs have video bitrate sweet spots. When you nail it, you’re getting the best picture quality possible — go higher, and you’re wasting bits — go lower, and you’re going to have a degraded image. So the key here is to give more props to a video with a higher bitrate, until it reaches its optimal level, and then you just leave that number stable.


Codec vs Codec


Finally, all codecs are not created equally, so we want to adjust the above modifier against a baseline codec. H.264 gives the best looking picture at the lowest possible bitrate, so we’ll choose it as the base. Then we can create a ratio for other codecs, for example MPEG2 needs double the bitrate of h.264 to achieve the same image quality.


Comparing the Data


It’d be great to have some help mixing these numbers together in a way that gives us a final value, allowing us to compare channels across codecs, resolutions, and bitrates.


Below are some arbitrary numbers I worked out for optimal bitrates and codec-to-codec ratios. Two disclaimers here: I’m neither a math person, nor a codec guru… if you see holes in my thinking or feel like my codec comparisons are off, definitely say so in the comments.


Optimal Bitrates for h.264


1920×1080 = 10000 kbps


1280×720 = 5000 kbps


640×480 = 1800 kbps


400×300 = 600 kbps


Optimal Bitrate Ratio for Other Codecs


optimal vp6, xvid, divx bitrates should be 1.5x higher


optimal theora bitrates should be 1.7x higher


optimal mpeg2 bitrates should be 2x higher


optimal mpeg1 bitrates should be 3.5x higher


optimal mjpeg or mjpg bitrates should be 5x higher




http://www.getmiro.com/blog/2008/09/hd-det...lp-us-build-it/