Rss

Muxing and chunking

Interesting bits from the lists, which I really ought to read more often.

QuickTime 7.6’s support document has a blunt and ambiguous little feature, “Audio tracks from MPEG video files now export consistently.” What does this mean? According to quicktime-users, you can export muxed MPEG-1 and not lose your audio, something Ben Waggoner notes we’ve been waiting 12 years for. Seriously, I could have used this like four companies ago at VNI… maybe then we’d have used QTJ instead of JMF.

The issue is this: “muxed” MPEG-1 means that audio and video samples are interleaved. That means when you play back, you generally have the samples you need for a given time all in one place (i.e., adjacent in a stream, in contiguous disk sectors, etc.). This is handy, of course, but QuickTime has its own idea about how samples are supposed to be organized (in a QuickTime movie, there are “chunks” of samples, and tables to optimize looking up chunks for a given time). Since MPEG-1 didn’t use that organization, QuickTime’s support for MPEG-1 was less robust than it was for other formats (notably, you don’t have these problems in MPEG-4, whose container format is highly .mov-like).

Great that they’ve taken care of this, but how relevant is MPEG-1 anymore, particularly as a production format where you’d care to take MPEG-1 as a source and then need to export out of it?

Similar and interesting bit from the coreaudio-api list. Jens Alfke noted slow seeking with MP3s. Again, the reason is that those files don’t have packet/chunk tables, so seeking to an arbitrary time in VBR data requires reading and decoding all the data up to that point. Ouch! Equally intersting in the followup from Apple’s Jeff Moore is that Core Audio’s AudioFile builds its own packet table as it seeks, so you don’t experience this problem when you seek back to an earlier point, or to any other point that’s been played or jumped to.

Better yet, there’s an easier workaround: put your audio data into a container format that has those kinds of tables, like MPEG-4 or Core Audio Format (.caf). Seems like .mov should work too, but Jeff didn’t mention it explicitly.

Interestingly, you can see this in the sample app I wrote for the next beta of the Prags’ iPhone book. Once beta 10 comes out, get the sample code, load the SimpleAudioPlayer project, add an MP3 file to the project (must be named audio.mp3) and delete the audio.m4a reference. Build and go.
simple-audio-player-metadata

While playing, use the slider to jump most of the way into your song. Especially on the device, you’ll notice a lag of 1-2 seconds while it seeks to that location. But then seek back earlier into the song, and then back again to any point before your first jump, and it’s instantaneous.

I didn’t make a big deal of the CAF format in the chapter, primarily because when I used Sound Studio to create sample files for the System Sounds example, the AIFF files sounded right and the CAFs had weird dropouts and stuttering. For the sake of expedience, I used the AIFFs for that example. But given some of CAFs advantages, most notably its packet tables and its codec agnosticism, it might become more prominent in later rewrites.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.