Breaking Eggs And Making Omelettes
A blog dealing with technical multimedia matters, binary reverse engineering, and the occasional video game hacking.
Les articles publiés sur le site
-
The New Samples Regime
1er décembre 2011, par Multimedia Mike — GeneralA little while ago, I got a big head over the fact that I owned and controlled the feared and revered MPlayer samples archive. This is the repository that retains more than a decade of multimedia samples.
Conflict
Where once there was one multimedia project (FFmpeg), there are now 2 (also Libav). There were various political and technical snafus regarding the previous infrastructure. I volunteered to take over hosting the vast samples archive (53 GB at the time) at samples.mplayerhq.hu (s.mphq for this post).However, a brand new server is online at samples.libav.org (s.libav for this post).
Policies
The server at s.libav will be the authoritative samples repository going forward. Why does s.libav receive the honor? Mostly by virtue of having more advanced features. My simple (yet bandwidth-rich) web hosting plan does not provide for rsync or anonymous FTP services, both of which have traditionally been essential for the samples server. In the course of hosting s.mphq for the past few months, a few more discrepancies have come to light– apparently, the symlinks weren’t properly replicated. And perhaps most unusual is that if a directory contains aREADME
file, it won’t be displayed in the directory listing (which frustrated me greatly when I couldn’t find this README file that I carefully and lovingly crafted years ago).The s.mphq archive will continue to exist — nay, must exist — going forward since there are years’ worth of web links pointing into it. I’ll likely set up a mirroring script that periodically (daily) rsyncs from s.libav to my local machine and then uses lftp (the best facility I have available) to mirror the files up to s.mphq.
Also, since we’re starting fresh with a new upload directory, I think we need to be far more ruthless about policing its content. This means making sure that anything that is uploaded has an accompanying file which explains why it’s there and ideally links the sample to a bug report somewhere. No explanation = sample terminated.
RSS
I think it would be nifty to have an RSS feed that shows the latest samples to appear in the repository. I figure that I can use the Unix ‘find’ command on my local repository in concert with something like PyRSS2Gen to accomplish this goal.Monetization
In the few months that I have been managing the repository, I have had numerous requests for permission to leech the entire collection in one recursive web-suck. These requests often from commercial organizations who wish to test their multimedia product on a large corpus of diverse samples. Personally, I believe the archive makes a rather poor corpus for such an endeavor, but so be it. Go ahead; hosting this archive barely makes a dent in my fairly low-end web hosting plan. However, at least one person indicated that it might be easier to mail a hard drive to me, have me copy it, and send it back.This got me thinking about monetization opportunities. Perhaps, I should provide a service to send HDs filled with samples for the cost of the HD, shipping, and a small donation to the multimedia projects. I immediately realized that that is precisely the point at which the vast multimedia samples archive — with all of its media of questionable fair use status — would officially run afoul of copyright laws.
Which brings me to…
Clean Up
I think we need to clean up some samples, starting with the ones that were marked not-readable in the old repository. Apparently, some ‘samples’ were, e.g., full anime videos and were responsible for a large bandwidth burden when linked from various sources.We multimedia nerds are a hoarding lot, never willing to throw anything away. This will probably the most challenging proposal to implement.
-
Using lcov With FFmpeg/Libav
Last year, I delved into code coverage tools and their usage with FFmpeg. I learned about using GNU gcov, which is powerful but pretty raw about the details it provides to you. I wrote a script to help interpret its output and later found another script called gcovr to do the same, only much better.
I later found another tool called lcov which is absolutely amazing for understanding code coverage of your software. I’ve been meaning to use it to further FATE test coverage for the multimedia projects.
Click for larger image
Basic Instructions
Install the lcov tool, of course. In Ubuntu,'apt-get install lcov'
will do the trick.Build the project with code coverage support, i.e.,
./configure --enable-gpl --samples=/path/to/fate/samples \ --extra-cflags="-fprofile-arcs -ftest-coverage" \ --extra-ldflags="-fprofile-arcs -ftest-coverage" make
Clear the coverage data:
lcov --directory . --zerocounters
Run the software (in this case, the FATE test suite):
make fate
Let lcov work its magic:
lcov --directory . --capture --output-file coverage.info mkdir html-output genhtml -o html-output coverage.info
At this point, you can aim your web browser at html-output/index.html to learn everything you could possibly want to know about code coverage of the test suite. You can sort various columns in order to see which modules have the least code coverage. You can drill into individual source files and see highlighted markup demonstrating which lines have been executed.
As you can see from the screenshot above, FFmpeg / Libav are not anywhere close to full coverage. But lcov provides an exquisite roadmap.
-
On ALAC’s Open Sourcing
1er novembre 2011, par Multimedia Mike — Codec TechnologyApple open sourced their lossless audio codec last week. Pretty awesome! I have a theory that, given enough time, absolutely every codec will be open source in one way or another.
I know I shouldn’t bother reading internet conversation around any news related to multimedia technology. And if I do read it, I shouldn’t waste any effort getting annoyed about them. But here are some general corrections:
- ALAC is not in the same league as — nor is it a suitable replacement for — MP3/AAC/Vorbis or any other commonly used perceptual audio codec. It’s not a matter of better or worse; they’re just different families of codecs designed for different purposes.
- Apple open sourced ALAC, not AAC– easy mistake, though there’s nothing to ‘open source’ about AAC (though people can, and will, argue about its absolute ‘open-ness’).
- There’s not much technical room to argue between ALAC and FLAC, the leading open source lossless audio compressor. Both perform similarly in terms of codec speeds (screamingly fast) and compression efficiency (results vary slightly depending on source material).
- Perhaps the most frustrating facet is the blithe ignorance about ALAC’s current open source status. While this event simply added an official “open source” status to the codec, ALAC has effectively been open source for a very long time. According to my notes, the ALAC decoding algorithm was reverse engineered in 2005 and added into FFmpeg in March of the same year. Then in 2008, Google — through their Summer of Code program — sponsored an open source ALAC encoder.
From the multimedia-savvy who are versed in these concepts, the conversation revolves around which would win in a fight, ALAC or FLAC? And who between Apple and FFmpeg/Libav has a faster ALAC decoder? The faster and more efficient ALAC encoder? I contend that these issues don’t really matter. If you have any experience working with lossless audio encoders, you know that they tend to be ridiculously fast to both encode and decode and that many different lossless codecs compress at roughly the same ratios.
As for which encoder is the fastest: use whatever encoder is handiest and most familiar, either iTunes or FFmpeg/Libav.
As for whether to use FLAC or ALAC — if you’ve already been using one or the other for years, keep on using it. Support isn’t going to vanish. If you’re deciding which to use for a new project, again, perhaps choose based on software you’re already familiar with. Also, consider hardware support– ALAC enjoys iPod support, FLAC is probably better supported in a variety of non-iPod devices, though that may change going forward due to this open sourcing event.
For my part, I’m just ecstatic that the question of moral superiority based on open source status has been removed from the equation.
Code-wise, I’m interested in studying the official ALAC code to see if it has any corner-case modes that the existing open source decoders don’t yet account for. The source makes mention of multichannel (i.e., greater than stereo) configurations, but I don’t know if that’s in FFmpeg/Libav.
-
More Cinepak Madness
20 octobre 2011, par Multimedia Mike — Codec TechnologyFellow digital archaeologist Clone2727 found a possible fifth variant of the Cinepak video codec. He asked me if I cared to investigate the sample. I assured him I wouldn’t be able to die a happy multimedia nerd unless I have cataloged all possible Cinepak variants known to exist in the wild. I’m sure there are chemistry nerds out there who are ecstatic when another element is added to the periodic table. Well, that’s me, except with weird multimedia formats.
Background
Cinepak is a video codec that saw widespread use in the early days of digital multimedia. To date, we have cataloged 4 variants of Cinepak in the wild. This distinction is useful when trying to write and maintain an all-in-one decoder. The variants are:- The standard type: Most Cinepak data falls into this category. It decodes to a modified/simplified YUV 4:2:0 planar colorspace and is often seen in AVI and QuickTime/MOV files.
- 8-bit greyscale: Essentially the same as the standard type but with only a Y plane. This has only been identified in AVI files and is distinguished by the file header’s video bits/pixel field being set to 8 instead of 24.
- 8-bit paletted: Again, this is identified by the video header specifying 8 bits/pixel for a Cinepak stream. There is essentially only a Y plane in the data, however, each 8-bit value is a palette index. The palette is transported along with the video header. To date, only one known sample of this format has even been spotted in the wild, and it’s classified as NSFW. It is also a QuickTime/MOV file.
- Sega/FILM CPK data: Sega Saturn games often used CPK files which stored a variant of Cinepak that, while very close the standard Cinepak, couldn’t be decoded with standard decoder components.
So, a flexible Cinepak decoder has to identify if the file’s video header specified 8 bits/pixel. How does it distinguish between greyscale and paletted? If a file is paletted, a custom palette should have been included with the video header. Thus, if video bits/pixel is 8 and a palette is present, use paletted; else, use greyscale. Beyond that, the Cinepak decoder has a heuristic to determine how to handle the standard type of data, which might deviate slightly if it comes from a Sega CPK file.
The Fifth Variant?
Now, regarding this fifth variant– the reason this issue came up is because of that aforementioned heuristic. Basically, a Cinepak chunk is supposed to store the length of the entire chunk in its header. The data from a Sega CPK file plays fast and loose with this chunk size and the discrepancy makes it easy to determine if the data requires special handling. However, a handful of files discovered on a Macintosh game called “The Journeyman Project: Pegasus Prime” have chunk lengths which are sometimes in disagreement with the lengths reported in the containing QuickTime file’s stsz atom. This trips the heuristic and tries to apply the CPK rules against Cinepak data which, aside from the weird chunk length, is perfectly compliant.Here are the first few chunk sizes, as reported by the file header (stsz atom) and the chunk:
size from stsz = 7880 (0x1EC8); from header = 3940 (0xF64) size from stsz = 3940 (0xF64); from header = 3940 (0xF64) size from stsz = 15792 (0x3DB0); from header = 3948 (0xF6C) size from stsz = 11844 (0x2E44); from header = 3948 (0xF6C)
Hey, there’s a pattern here. If they don’t match, then the stsz size is an even multiple of the chunk size (2x, 3x, or 4x in my observation). I suppose I could revise the heuristic to state that if the stsz size is 2x, 3x, 4x, or equal to the chunk header, qualify it as compliant Cinepak data.
Of course it feels impure, but software engineering is rarely about programmatic purity. A decade of special cases in the FFmpeg / Libav codebases are a testament to that.
What’s A Variant?
Suddenly, I find myself contemplating what truly constitutes a variant. Maybe this was just a broken encoder program making these files? And for that, I assign it the designation of distinct variation, like some sort of special, unique showflake?Then again, I documented Magic Carpet FLIC as being a distinct variant of the broader FLIC format (which has an enormous number of variants as well).
-
Space Adventure CD-ROM
1er octobre 2011, par Multimedia Mike — Game HackingI acquired a CD-ROM entitled Space Adventure by Knowledge Adventure (I like these people; they make decent, entertaining educational games). The physical media displays a copyright date of 1993, very early in the multimedia era.
This 1993 CD-ROM makes proud use of multimedia files. What kind? There’s a movies/ directory with 17 .mov files. It would be way too simple if these were QuickTime files, though. These represent a custom format, and video-only since a separate sounds/ directory contains .snd files with filenames corresponding to the .mov files. The .snd files are actually Creative Voice (a.k.a. VOC) files. As for this MOV format, wiki page and samples.
I was also surprised to find the binary ultrasnd.exe file among the drivers on the disc. The Gravis UltraSound was released in 1992. The sound setup utility does not have an option for the GUS, however. No matter since DOSBox has great SB/Pro/16 emulation.
I’m also a bit puzzled about why the DOSBox screenshots are 720 x 480 (posted here are various cropping and resizings).