One frame of Big Buck Bunny, 160×96, zoomed 2×, through four of Cinema's encodings. The sizes are for a minute of video. More on what's going on here below.
The Nokia 9210 Communicator can play video. It has RealPlayer, and the best setup anyone found for it is 160×96 pixels at 7 frames a second. That's a very small picture in the middle of a 640×200 screen, at a frame rate where motion turns into a slide show.
So on 12 September I asked Claude for "the fastest video player" for the 9210. The result is Cinema: video with sound, kept in sync, with seeking, volume, pause, resume and an English or Finnish user interface. As with my other projects on this blog, Claude (Anthropic's AI) wrote the code. I built it on my Windows 2000 VM, ran it on the phone and reported back. It took about a week, and it was one of the more educational weeks I've had with this phone.
The PC does the work
The 9210 has a ~52 MHz ARM and no video hardware at all, so decoding a real video codec on it is exactly what RealPlayer already struggles with. Cinema's idea is the same one SisuView uses for photos: do everything on a PC, ahead of time.
A Python converter uses ffmpeg to read any video, scales it, and converts every pixel into the screen's own format, 12-bit colour packed as 0x0RGB. On the phone there's no colour conversion and no codec. Cinema unpacks a frame and copies it straight into the screen's memory, past the window server, one Mem::Copy per line. That trick comes from my Game Boy emulator, which took it from the 9210 SDL port of Doom.
The first real test was the Odyssey trailer at RealPlayer's own 160×96 and 7 fps. Cinema shows its achieved frame rate in the corner as T:achieved/target, and the first build said T:7/7. Then 24 fps: T:22/24. Full screen at 640×200 managed 4 to 8 fps depending on the scene, because a busy frame takes more unpacking than a flat one.
The setting I kept is the one RealPlayer itself uses: decode a small picture and show it doubled. A 320×100 clip fills the screen, and at 15 fps the worst I saw was T:10/15. My verdict at the time was "not too bad".
Eleven rounds of sound
Then I said: "let's try sound next".
Claude found something on my disk that neither of us remembered properly: MdaSmoke, a small console test of CMdaAudioOutputStream, the streaming audio API, written earlier for a Doom port. It played a tone. So Cinema got a streaming audio track inside the .CIN file, fed to that API a chunk at a time.
Here's how the emulator answered, one test at a time:
PROPERR -5.SetAudioPropertiesL(aSampleRate, aChannels)doesn't take 11025 and 1. It takes bit flags likeESampleRate11025Hz. MdaSmoke had it right.- A frozen emulator. Each finished buffer started writing the next one from inside its own callback, and when the callback ran synchronously, that recursed forever.
- A second of very high-pitched sound, then
WRTERR -38. - Then
-38again and again: at 8000 and 11025 Hz, mono and stereo, with small buffers and with the whole track loaded into memory. Every time, the very first buffer came back withKErrBadDescriptor.
MdaSmoke rebuilt from scratch played cleanly: 22 chunks, no errors. So the API worked, just not inside a GUI app that was also decoding video. With the video switched off, Cinema's sound did play, garbled, and then the emulator froze. Adding pacing didn't fix it. Removing every file read from the audio path didn't fix it either. I recorded what came out:
The first two seconds of what the emulator played, recorded on the PC. The sound arrives in bursts, with gaps between them, and in places the output just holds one level. It sounded like a buzzing, crackling radio.
After eleven tests we gave up on streaming, and that was the right call. Nokia's own SDK sample plays sound with CMdaAudioPlayerUtility, which takes a whole file and plays it. So the audio moved out of the .CIN into a plain .WAV file next to it, and the audio code shrank to almost nothing. My report from the next test: "sound plays perfectly!" As I learned later with Doomunicator, the 9210's ROM doesn't even have the streaming audio DLL, so that road was closed on the real phone anyway.
Keeping the picture and the sound together
On the phone the sound played nicely, and by the end of the trailer it was several seconds ahead of the picture. Whenever a frame took longer than its slot, the time was simply lost, while the Media Server kept the sound at true speed.
The old player API can't tell you where the sound is, so the wall clock became the master. Every tick, Cinema works out which frame should be on screen by now, and if the picture is behind, it skips frames without decoding them until it catches up. "Sound keeps up!"
Two more sync bugs showed up later with a test clip made for this, one with sharp, regular sounds:
- Lag that grew the longer you watched. The catch-up loop measured the time once, before it started skipping, and the skipping itself takes time. Now it measures again after every skip.
- A fixed lag from the first frame. Opening the sound file is asynchronous on the Media Server, so the picture had a head start. Holding the video back 1 second put the sound half a second ahead, so we split the difference: 0.5 seconds. "Perfectly perfect."
Making it smaller
A 2-minute trailer at 320×100 and 15 fps took 23.7 MB, and memory cards for this phone are 128 or 512 MB. So the next few days went into file size:
The same trailer after each step. Above the line every pixel is exact; below it, it isn't.
- Delta frames store a frame as its difference from the last one, so a static background costs almost nothing: 12% smaller. A movie trailer is close to the worst case for this, with its fast cuts and moving camera.
- 12-bit packing stores two pixels in three bytes instead of four, because the screen only uses 12 of each pixel's 16 bits: another 14.5%.
- Motion compensation says "this block moved here" instead of storing it again. On a TV episode it saved 1.5%, because talking heads move their mouths, not whole blocks.
- A transform (Walsh–Hadamard, the DCT's integer cousin) made frames four to five times bigger. After delta coding, what's left is mostly zeros with a few isolated changes, and a transform spreads those out instead of packing them together.
Then I had an idea: what did early 2000s codecs do, when PCs were slow? Claude said vector quantization, which is how Cinepak works. The converter learns a codebook of small pixel blocks for each clip, and each frame becomes a list of codebook numbers. Decoding is one table lookup and one copy per block, so it's cheap on the phone.
The first try was 92.7% smaller and, in my words, "veeeery low" quality next to RealPlayer. The picture at the top shows why, and what fixed it. With 4×4 blocks the picture turns into a mosaic, because 256 codebook entries can't cover every 16-pixel pattern. 2×2 blocks look far better for about 3.5 times the size. A bigger codebook helps a little more. On the phone, VQ played at T:13/15, the same as the lossless format, and a 4096-entry codebook plays just as fast as a 256-entry one, because looking up entry 4000 costs the same as entry 4.
One file instead of two
Two files per clip is clumsy to copy, so we put the .WAV back inside the .CIN. The emulator played it, and the phone said OPNERR -4, out of memory. The 9210 has about 3.5 MB of free RAM, so a whole sound track can't sit in memory. The next design copied the sound out to a temporary file at the start. A 1 KB copy buffer froze the phone, with about 1800 file-server round trips. 64 KB played after 10 seconds, and 256 KB was barely faster. Writing to the memory card is simply slow on this phone. Back to two files: reading a file that's already on the card costs nothing extra.
Seeking, because RealPlayer can
Leave a clip and come back, and Cinema resumes the picture where you left it. The sound started from the beginning, because the player API has no seek. I pointed out that RealPlayer seeks just fine on the same phone. So Claude looked further and found CMdaAudioRecorderUtility, in the same library Cinema already linked, with a real SetPosition() and a Nokia sample that uses it. "Works on the 9210, perfect!"
With seeking in place, Left and Right jump 5 seconds. Forward is easy: skip frames to the next keyframe. Backward is the old trick for formats that can only be read forwards: go back to the first frame and skip forwards to the target.
The menu that broke everything
The menu got four groups: File, View, Play and Tools. We also greyed out the View and Play headings while no clip was playing. On the phone, that broke the whole menu: every item said "This item is not available", and the arrows couldn't move between the menus. Greying out individual items instead, the way apps grey out Paste when there's nothing to paste, works fine. On the way I also found that ä and ö work in the 9210's resource files. We had been avoiding them in every project because of an old assumption nobody had tested.
English and Finnish
For an English release, all the text moved into the resource file, which the SDK compiles once per language: LANG 01 09 gives an English and a Finnish file, and the installer keeps the one that matches the phone's language. The installer uses its own two-letter codes. Finnish is FI; SF, which sounds like Suomi-Finland, is Swiss French. Claude checked the SDK's table instead of guessing.
So how does RealOne do it in 1 MB?
RealOne fits the whole Odyssey trailer, picture and sound, into 1.05 MB. The VQ version I watch with Cinema is 4.2 MB of video and 1.8 MB of sound. So I asked Claude to look at the RealOne file:
| RealOne | Cinema, VQ | |
|---|---|---|
| Picture | 160×96, 7 fps | 320×100, 15 fps |
| Video | 72 kbps | 293 kbps |
| Bits per pixel | 0.67 | 0.61 |
| Sound | 8 kbps (RealAudio) | 128 kbps (plain PCM) |
Per pixel, Cinema's VQ is slightly more efficient than RealVideo 2.0. RealOne's file is smaller because its picture has less than a quarter of Cinema's pixels per second, and because its sound is compressed 16 times harder. Cinema's next easy win isn't in the video at all: ADPCM audio would make the sound four times smaller and costs almost nothing to decode.
What's missing
- Compressed sound, as above.
- Skip blocks. Every VQ frame is coded on its own, so a still background can flicker between codebook entries. Cinepak solved that with "this block didn't change" blocks, which would also make files smaller.
- The 9500. My 9210 has since started switching itself off and been retired, and I haven't tried Cinema on the 9500 yet.
Get it
Cinema is on GitHub as Scorpizoid/Cinema9210, GPL v2 or later. The 1.0 release has the SIS and the source. Install the SIS, then convert a video on a PC:
python cinema_convert.py movie.mp4 --size 320x100 --fps 15 --vq
or use cinema_gui.py, which finds ffmpeg by itself. Copy the .CIN and the .WAV to D:\CINEMA\ on the memory card. Enter or Space pauses, Left and Right seek, Up and Down change the volume, Tab toggles full screen, L loops, R restarts, and Backspace goes back to the list and remembers where you were.
Thanks to the Blender Foundation for Big Buck Bunny (CC BY 3.0, used in the pictures above), to Nokia for the SDK samples that showed which audio APIs actually work, and to ChatGPT for the icon.
A full-screen picture with sound, in sync, on a phone from 2001 that was sold with a 7 fps video player. That's the kind of week I like.



Ei kommentteja:
Lähetä kommentti