Server-side seeking with MP4s

Recent versions of Flash can now play much better video, which can be contained in other containers - like m4v, mov, etc.  And, the easiest way to create the correct kind of video is using something that outputs those files - not flvs.  This creates better quality video with the same bitrate, and is more interoptable (for example, with PSPs and other video players.)

Another thing that is becoming popular is server-side seeking (or “pseudo-streaming“).  This is where the video is progressive (comes off a webserver not a streaming server), but you can still seek ahead of where you’ve downloaded so far - and it simply starts downloading a new stream that starts there.  YouTube is already doing this, as well as more and more video sites.

Combining the ideas, however, leads to a problem: server-side seeking doesn’t work with these other formats.  The necessary metadata has to be injected into an flv file.  So what do you do if you have a bunch of m4vs (say, designed to play in podcasts) sitting around and want to make them stream in your flash player?  Re-encode them, maybe losing quality?

It turns out the easiest way is simply to convert the container (using a tool like ffmpeg), without touching the video or audio streams themselves.  This allows the correct video and audio to sit in the flv file, which can sit alongside the metadata.

ffmpeg -i input.m4v -vcodec copy -acodec copy -f flv -y output.flv

Now that you have an flv, you can trigger the onMetaData event in Flash, but you still have the better encoding.  Here you might use yamdi to add the keyframe data into the flv so you can easily seek in it.

It’s a simple solution, but there’s not a lot of resources out there yet with people combining these two ideas.  But, this is what Amoeba Music is now already doing.

This entry was posted on Tuesday, September 16th, 2008 at 7:00 pm and is filed under Flash, PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply