Skip to content

normalize flash playback speed using ffmpeg

Video is a great way to demo a new system or option.  As a world, we're moving to the availability of high-speed connections just about everywhere, but we're not there yet.  That means that you probably want to crunch down a 30M high-quality video you just generated into something more tolerable, like 5-7M.  I've found that generating flash files (hey, it works for youtube, google, etc) and posting them with something like swfobject with ffmpeg is really a simple and great way to go.

First stab at ffmpeg

Check the documentation for a true reference of all ffmpeg options, but with this simple command string, I am able to crush down a 30M, 7 minute presentation to under 5M.  As you can see, the frame rate is only 2fps and the bitrate is quite low, but when the two come together, you end up with a tiny file.

ffmpeg -i -b 100000 -r 2 talk-MIR08-trim.swf

Maintaining playback speed

One problem I've noticed though is that if your video doesn't contain any audio, when you use the frame rate option, the flash player will try to take your new video and play it back at a normal rate.  For example, if you set the rate at 2fps, flash is probably going to play it back at 30fps.  The net result? You get a fun 15x playback rate.  It's great if you meant to make your presentation at light-speed, but usually that's not the desired effect?

Fortunately, there is a simple solution for this somewhat perplexing problem.  I scoured the flash and swfobject documentation pages for some extra parameter that could save the day, but alas there was none.  Instead, let's think about what's typically in a video, or more generally a multimedia document?  Both audio and video, right?  There's the solution.

If you don't have it, go fetch the great open-source audio application Audacity, after all, you never know when cool little tricks like this may come in handy.  With Audacity, open a new document and "Generate -> Silence...".  Compute what the true runtime of your video should be and generate that much silence.  Next, save the file to WAV or MP3 format next to your video file.

Finding video length

Finding video length

Audacity Generate menu

Audacity Silence specification

Multiplex audio silence and video

Now, let's jump back to ffmpeg and just add a few more arguments.  Since the audio content is silence, we can really squeeze down the number of bits required by the MPEG1-Layer 3 codec.  I found that keeping the audio clip as mono, 11.025kHz sample rate and only 48kB was about as small as it could go.  What does that look like on the command line...?

ffmpeg -i -i silence.wav -b 100000 -r 2 -ar 11025 -ab 48000 talk-MIR08-trim.swf

Tada!  Your new file is now much smaller at a low-framerate and it preserves the normal playback speed.  Good luck and happy movie making.

Post a Comment

Your email is never published nor shared. Required fields are marked *