HTML 5 and video codecs…

Lots of fuss about the HTML 5 video codec. What is it gonna be? Theora or H.264. I would say both. Youtube, for instance, has a low quality version of the video and a high quality (HD) version. Why not encode the low quality “baseline” version as Theora, and the high quality version in the format-of-the-week (i.e.: H.264). It would be a bit like the “alt” tag for embedded pictures on the web. This approach does neither increase the disk storage requirements, nor the required bandwidth for Youtube, and the content is available to everyone. When the time is right, the high quality codec might be replaced with either Theora, Dirac, or On2’s (recently bought by Google) codec. I’m probably forgetting something here… 🙂



It is interesting that it is very tricky to code in PHP sometimes. Take the openssl_pkcs7_verify function.
It has a “mixed” return type:

Returns TRUE if the signature is verified, FALSE if it is not correct (the message has been tampered with, or the signing certificate is invalid), or -1 on error.

So the first instinct is, at least for me, to test the return value of the function like this:

// success
// fail

This unfortunately does not work as expected, as -1 also evaluates to TRUE here. So the correct way to “cast” this return value to a boolean is with code like this:

$result = openssl_pkcs7_verify(...);
$bool_result = ($result == 1) ? TRUE : FALSE;

Now suppose you have this “true” boolean value, and you want to print the result. A possible approach would be like this:

$res = FALSE;
echo "Result: " . ($res) ? "VALID" : "INVALID";

This code always prints VALID, not the expected Result: INVALID, because the string concatenation is evaluated, not the variable $res itself. So no matter what the result is in $res, it always prints VALID, which can be a bit tricky if you are not paying close attention and ran out of coffee :). To fix this, you obviously need to add brackets like this:

$res = FALSE;
echo "Result: " . (($res) ? "VALID" : "INVALID");

I guess I should really program regularly to not forget all this stuff 🙂