Yearly Archives: 2009

iPhone Developments

Wikipedia’s knowledge of compilers credits the first compiler to Grace Hopper in 1952 (for a language called A-0). I suspect that if blogs existed in 1952, we would have been treated to rants such as:

I, personally, have a problem with a developer who feels entitled to be able to develop for a computer without investing the time to learn the machine opcodes or punch card formats that the machine was built around.

This is one of the arguments I have been hearing this past week after my employer announced an upcoming method for exporting Flash/AS3 projects as iPhone apps. It strikes me as an age-old argument between low vs. high level languages, that’s all. I chortle when recalling how certain people urged me to construct the FATE system in POSIX-complaint, ANSI C for maximum portability and speed instead of using a language like Python. Nowadays, that Python code is testing FFmpeg on a dozen different CPUs running 10 different operating systems. It makes me shudder to think of how much work it would have been to write the FATE script in straight C and how little benefit doing so would have brought.

In other groundbreaking iPhone news, Mans recently announced that FFmpeg can be built for the iPhone out of the SVN tree with only a minor modification to Apple’s iPhone toolchain (call the SDK police!). This is a feat that has thus far proved challenging, as Mans outlined here. I understand it will be a little difficult to continuously test FFmpeg on either a real iPhone or an emulator. However, I’m planning a revision to FATE’s architecture so that certain configurations can be marked “build-only” and forgo the test phase. This will also be useful for Hitachi SH-4 and perhaps other architectures that FFmpeg supports but for which we don’t have access to hardware for the sake of continuous testing.

Whenever the notion of compiling and running FFmpeg on the iPhone crops up, it prompts me to wonder why. Why do people care about this? Are they transcoding media on the iPhone? Are they republishing old games and using FFmpeg’s numerous game-oriented decoders for direct playback instead of doing the sensible thing and transcoding the original media to MP4/CAF/H.264/AAC for native playback through the platform’s frameworks and hardware acceleration? Is it just a point of academic curiosity thanks to the fact that FFmpeg is quickly becoming a standardized metric of compiler quality? Why?

13 Architectures

An impromptu query from the FATE database:

mysql> SELECT DISTINCT(architecture) 
  FROM web_config_cache 
  WHERE revision IS NOT NULL 
  ORDER BY architecture;

This yields 13 architectures currently being continuously tested in FATE:

+--------------+
| architecture |
+--------------+
| Alpha        | 
| ARMv5TE      | 
| ARMv7        | 
| AVR32        | 
| ia64         | 
| MIPS         | 
| PA-RISC      | 
| PowerPC      | 
| PowerPC 64   | 
| Sparc        | 
| Sparc64      | 
| x86_32       | 
| x86_64       | 
+--------------+

I suppose it’s questionable to treat ARMv5TE and ARMv7 as truly separate architectures. Still, it’s not a bad list of CPU coverage. It makes me wonder how it stacks up to the Linux kernel in terms of CPU support. According to Wikipedia, Linux still has the advantage.

One day I’ll figure out a way to continuously test FFmpeg on a Hitachi SH-4 using my old Sega Dreamcast. That’ll bring us closer.

A Lot Of New FATE Machines

Thanks to Thibaut VARĂˆNE for bringing an incredible number of new machines to the FATE table:

  • PowerPC / Mac OS X
  • ia64 / Linux
  • PA-RISC / Linux
  • Sparc / Linux
  • Sparc64 / Linux

As of this writing, the Sparc/64 machine is having trouble getting its first results uploaded to the FATE server. Those will hopefully start showing up soon.

Right now, none of the ia64 configurations compile successfully. This is indirectly how Thibaut learned of FATE (via this Roundup issue). No configuration is too marginal for us to track as long as someone has the resources to continuously run FATE cycles. If this is ever in doubt, just remember that Michael K. is testing FFmpeg on (Free)DOS via FATE.

I Need 16 Optimal Huffman Trees

Actually, I need 80 optimal Huffman trees, but let’s take it one step at a time.

The VP3 video codec — the basis of Theora — employs 80 different Huffman trees. There are 16 for DC coefficients and 16 each for 4 different AC coefficient groups. An individual VP3/Theora frame gets to select 4 different Huffman trees: one for Y-plane DC, one for C-plane DC, one for Y-plane AC, and one for C-plane AC. VP3 hardcodes these tables. Theora allows more flexibility and an encoder is free to either use the default VP3 trees or create its own set and encode them into the header of the container (typical an Ogg file).

Generating an optimal Huffman tree for a particular set of input is rather well established; any introduction to Huffman codes covers that much. What I’m curious about is how one would go about creating a set of, e.g., 16 optimal Huffman trees for a given input. The first solution that comes to mind is to treat this as a vector quantization (VQ) problem. I have no idea if this idea holds water, or if it even has any sane basis in mathematics, but when has that ever stopped me from running with a brainstorm?

Here’s the pitch:

  • Modify FFmpeg’s VP3/Theora decoder to print after each frame decode the count of each type of token that was decoded from the stream (for each of the 5 coefficient groups, and for each of the plane types), as well as the number of bits that token was encoded with. This will allow tallying of the actual number of bits used for encoding tokens in each frame.
  • Create a separate tool to process the data by applying a basic VQ codebook training algorithm. It will be necessary to treat all of the Y-plane AC tokens as single vectors and do the same with the C-plane AC tokens, even though each AC token vector needs to be comprised of 4 separate AC group vectors. Re-use some existing E/LGB code for this step.
  • Generate Huffman trees from the resulting vectors and count the number of bits per token for each.
  • Iterate through the frequency vectors captured from the first step and match them to the codebooks using a standard distance algorithm.
  • Tally the bits from using the new vectors and see if there is any improvement versus the default vectors (Huffman tables).

I don’t know if I’ll have time to get around to trying this experiment in the near future but I wanted to throw it out there anyway. With all of the improvments that the new Theora encoder brings to the tables, it seems that the custom Huffman trees feature is one that is left un-exercised per my reading of the documentation and source code. From studying the Big Buck Bunny Theora encodes (my standard Theora test vectors these days), I see that they use the default VP3 tables. The 1080p variant occupied 866 MB. Could there be any notable space savings from generating custom Huffman tables? Or was this a pointless feature to add to the Theora spec?