Category Archives: General

On WebP and Academic Exercises

Yesterday, Google released a new still image format called WebP. To those skilled in the art, this new format will be recognizable as a single VP8 golden frame with a 20-byte header slapped on the front (and maybe a little metadata thrown in for good measure). We have a MultimediaWiki page and a sample ready to go.

Further, I submitted a patch to ffmpeg-devel for FFmpeg’s img2 handling system to decode these files. FFmpeg should support processing these files soon… if anyone cares. This leads into…

The Point, or Lack Thereof
Since yesterday’s release, I have read a whirlwind of commentary about this format, much of it critical and of the “what’s the point?” variety. For my part, I can respect academic exercises, a.k.a., just trying random stuff to see if you can make it work. That’s pretty much this blog’s entire raison d’être. But WebP transcends mere academic exercise; Google seems to be trying to push it as a new web standard. I don’t see how the format can go anywhere based on criticisms raised elsewhere — e.g., see Dark Shikari’s thoughtful write-up — which basically boil down to WebP not solving any real problems, technical, legal, or otherwise.

How did WebP come to be? I strongly suspect some engineers noticed that JPEG is roughly the same as an MPEG-1 intraframe, so why not create a new still frame format based on VP8 intraframes? Again, I can respect that thinking– I have pondered how a still image format would perform if based on VP3/Theora or Sorenson Video 1.

Technically
Google claims a significant size savings for WebP vs. standard JPEG. Assuming that’s true (and there will be no shortage of blog posts to the contrary), it will still be some time before WebP support will find its way into the majority of the web browser population.

But this got me thinking about possible interim solutions. A website could store images compressed in both formats if it so chose. Then it could serve up a WebM image if the browser could support it, as indicated by the ‘Accept’ header in the HTTP request. It seems that a website might have to reference a generic image name such as <img src="some-picture.image">; the web server would have to recognize the .image extension and map it to either a .jpg or a .webp image depending on what the browser claims it is capable of displaying.

Leftovers
I appreciate that Dark Shikari has once again stuck his neck out and made a valiant — though often futile — effort to educate the internet’s masses. I long ago resigned myself to the fact that many people aren’t going to understand many of the most basic issues surrounding multimedia technology (i.e., moving pictures synchronized with audio). But apparently, this extends to still image formats as well. It was simultaneously humorous and disheartening to see commenters who don’t even understand the application of, e.g., PNG vs. JPEG: Ahem, “We already have a great replacement for jpg: .PNG”. Coupled with the typical accusations of MPEG tribalism, I remain impressed D. Shikari finds the will to bother.

Still, I appreciate that the discussion has introduced me to some new image formats of which I was previously unaware, such as PGF and JPEG XR.

Launch Leech and the History of WMV

I was combing through my programming archives again and came across an old Perl script called launch-leech.pl. This was a private script I used to maintain for the benefit of myself and a few friends. See, there was this site called Launch.com (URL doesn’t seem to do anything as of this writing but here’s the Wikipedia page). Purchased by Yahoo! in 2001, Launch still maintained their independent branding. They also carried a lot of music videos, of which I am a huge junkie. launch-leech.pl was the tool I used to download the videos. This was particularly useful since I stubbornly clung to dialup internet access until mid-2004 and it would have been impossible to stream video at any decent quality (though there were 56k streams, so like I said– not possible at any decent quality).



Technically
I followed Launch.com for many years. To be honest, I only “followed” in that I figured out where their “latest videos” URL lived and regularly polled it. Each video had either a 6-, 7-, or 8-digit unique ID that could be plugged into the launch-leech.pl script which would then have a conversation with the relevant servers, determine the correct streaming URL with the highest quality, then download and save the URL by handing it off to an external program (first ASFRecorder, though I later switched to mmsclient).

At one point, I even wrote a crawler that compiled an offline database of all the videos, their IDs and their metadata. I never thought of anything interesting to do with it, though.



Windows Media Legacy
During these glory days of leeching, Launch.com streamed using Windows Media. I admit, it’s a bit of a blur now — the site might have used Real or QuickTime, but I was obviously most in tune with the WM side. I remember when I first found the site circa 2000-2001, the videos were in MS MPEG-4v3, and the high quality bitrate was 300 kbits/sec. Eventually, Launch.com would stream WMV7, WMV8, and finally WMV9, with bitrates up to 700 kbits/sec. However, they never broke free of the 320×240 encoding resolution, which was frustrating. When I wasn’t able to notice any substantial difference between 300 and 700 kbits/sec, I felt it might be time to put those extra bits to work on a resolution upgrade.

At least they were nice enough to re-encode a number of old videos using better codecs and bitrates with each revision, thus prompting me to scan through the site collecting updated video IDs for download.



Epilogue
I don’t clearly remember when I stopped visiting Launch.com. Video-wise, the web has been a blur of Flash video ever since about 2006. Meanwhile, I spent a lot of time collecting a bunch of music videos in the first half of the decade only to find that pretty much every version of every music video made since the dawn of time is available on demand thanks to YouTube. I have found that this phenomenon manifests in many areas as internet technology marches on.

The Real Entertainment
The launch-leech.pl tool represents a recurring pattern for me. I derive as much — if not more — entertainment from creating programs like launch-leech.pl (and implicitly reverse engineering something in the process; in this case, a website) as I do from the intended entertainment media itself. I seem to have this issue a lot with games, too.

Is this an issue for anyone else? Am I the only one who would rather play with the box that a shiny toy comes packaged in?

Naive Sorenson Video 1 Encoder

(Yes, the word is “naive” — or rather, “naïve” — not “native”. People always try to correct me when I use the word. Indeed, it should actually be written with 2 dots over the ‘i’ but who has a keyboard that can easily do that?)

At the most primitive level, programming a video encoder is about writing out a sequence of bits that the corresponding video decoder will understand. It’s sort of like creating a program — represented as a stream of opcodes — that will run on a given microprocessor or virtual machine. In fact, reading a video codec bitstream specification will reveal a lot of terminology along the lines of “transmitting information to the decoder” or “signaling the decoder to do xyz.”

Creating a good encoder that will deliver decent quality at a reasonable bitrate is difficult. Creating a naive encoder that produces a technically compliant bitstream, not so much.



When I wrote an FFmpeg encoder for Sorenson Video 1 (SVQ1), the first step was to just create a minimally compliant bitstream. The coarsest encoding mode that SVQ1 allows is to encode the average (mean) of each 16×16 block of samples. So I created an encoder that just encoded the mean of each block. Apple’s QuickTime Player was able to play the resulting video in all of its blocky glory. The result rather reminds me of the Super Nintendo’s mosaic effect.

Level 5 blocks (mean-only 16×16 encoding):



Level 3 blocks (mean-only 8×8 encoding):



It’s one thing for your own decoder (in this case, FFmpeg’s own decoder) to be able to decode the data. The big test is whether the official decoder (in this case, Apple QuickTime Player) can decode the file.



Now that’s a good feeling. After establishing that sort of baseline, it’s possible to adapt more and more features of the codec.

How Much H.264 In Each Encoder?

Thanks to my recent experiments with code coverage tools, I have a powerful new — admittedly somewhat specious — method of comparing programs. For example, I am certain that I have read on more than one occasion that Apple’s H.264 encoder sucks compared to x264 due, at least in part, to the Apple encoder’s alleged inability to exercise all of H.264’s features. I wonder how to test that claim?

Experiment
Use code coverage tools to determine which H.264 encoder uses the most features.

Assumptions

  • Movie trailers hosted by Apple will all be encoded with the same settings using Apple’s encoder.
  • Similarly, Yahoo’s movie trailers will be encoded with consistent settings using an unknown encoder.
  • Encoding a video using FFmpeg’s libx264-slow setting will necessarily throw a bunch of H.264’s features into the mix (I really don’t think this assumption holds much water, but I also don’t know what “standard” x264 settings are).

Methodology

  • Grab a random Apple-hosted 1080p movie trailer and random Yahoo-hosted 1080p movie trailer from Dave’s Trailer Page.
  • Use libx264/FFmpeg with the ‘slow’ preset to encode Big Buck Bunny 1080p from raw PNG files.
  • Build FFmpeg with code coverage enabled.
  • Decode each file to raw YUV, ignore audio decoding, generate code coverage statistics using gcovr, reset stats after each run by deleting *.gcda files.

Results

  • x264 1080p video: 9968 / 134203 lines
  • Apple 1080p trailer: 9968 / 134203 lines
  • Yahoo 1080p trailer: 9914 / 134203 lines

I also ran this old x264-encoded file (ImperishableNightStage6Low.mp4) through the same test. It demonstrated the most code coverage with 10671 / 134203 lines.

Conclusions
Conclusions? Ha! Go ahead and jump all over this test. I’m already fairly confident that it’s impossible (or maybe just very difficult) to build a single H.264-encoded video that exercises every feature that FFmpeg’s decoder supports. For example, is it possible for a file to use both CABAC and CAVLC entropy methods? If it’s possible, does any current encoder do that?