Coming up: another one of my utter unscientific excercises. This time I'm taking a look at how keyframe density during Flash Video encoding affects the output filesize.
As you may know, Flash Video files (.flv) usually consist of loads and loads of frames, comparable to the Flash timeline. This series of frames inside the flv file is made up of some keyframes as well as interframes (the frames in between the keyframes). A keyframe will hold the entire image information for that frame (a fully functional image so to speak) whereas interframes contain only the changes from one frame to the next. This aids compression as only changed data is adding to the weight of interframes.
'Great' you might say, 'I'll encode with hardly any keyframes next time'. Nice idea, but there is a trade-off which, if you use progressive Flash Video delivery, is seek-ability.
Imagine a scrubber to seek through a video. You'll notice how the video 'jumps' when you scrub backward and forward - what you see there are the keyframes and the less keyframes you encode the less accurate your seek and search mechanism will be.
I deploy quite a lot of progressively delivered Flash Video and I really don't like inaccurate seeking. So I wondered how badly the filesize of a flv is affected if I encode using a higher keyframe density. If you use Sorenson Squeeze to encode your Flash Video then it's likely that the keyframe density default is 300 - one keyframe every 300 frames. To me this seems to be a really low density and it will mean that the encoded flv will not be seekable very accurately. If your videos are short - and web video often is - then the result can be pretty bad.
Here are some example to illustrate. I'm displaying the videos at 200% in order to stretch the seekbar out a bit more, this makes the differences even more apparent. Please click play on each video, wait for the video to be downloaded and then start scrubbing.
Continue reading here
Video 1:
Made for the Autobahn
Keyframe every 300 frames
Filesize: 1.14 MB
Video 2:
Made for the Autobahn
Keyframe every 100 frames
Filesize: 1.14 MB
Video 3:
Made for the Autobahn
Keyframe every 50 frames
Filesize: 1.17 MB
Video 4:
Made for the Autobahn
Keyframe every 10 frames
Filesize: 1.35 MB
You should notice that Video 1 is almost unsuable when it comes to scrubbing. There seems to be only one point in the whole video that we can seek to. Video 2 is a little better with a few more keyframes but still hardly an improvement - but notice the filesize is virtually identical and only differed after the second decimal digit.
Video 3 gets better and we know see a little tradeoff in terms of filesize: 1.17MB with doubling the keyframe density from Video 2.
Video 4 is the best one out of the lot, we can seek this one very well to many points throughout. Filesize now goes up to 1.35MB but in some circumstances I would find this perfectly acceptable. Keyframe density
is pretty high with one keyframe every 10 frames.
Note that the source file was a .mov Quicktime movie starting out at 1.76MB. It's a small file and a short video. So how would this experiment go if we had a larger, longer file?
I tested with another clip, a .mpg video file of 30MB. With just under 3 minutes in length this is a typical web video file. Here are the results:
Video 5:
7K Preview
Keyframe every 300 frames
Filesize: 10.248 MB
Video 6:
7K Preview
Keyframe every 100 frames
Filesize: 10.363 MB
Video 7:
7K Preview
Keyframe every 50 frames
Filesize: 10.129 MB
Video 8:
7K Preview
Keyframe every 10 frames
Filesize: 10.192 MB
Thsi is strange. The filesize of the video with a keyframe density of 10 is actually smaller than the filesize of the video with a keyframe density of 300 and 100. Only the file with a keyframe density of 50 is smaller.
I don't really have an explanation for this but it seems clear that for this particular video it's actually more efficient to encode using a high keyframe rate. This seems strange as all other encoding settings were identical. Maybe Squeeze does some adjusting to the bitrate behind the scenes yet I cannot see any difference in video quality between the files. I personally would definitely opt for the 10 keyframe file here.
I guess what we can learn from this little experiment is: maybe encode your files twice or even three times, using different keyframe settings. Your users will benefit from being able to seek more effectively and the player will appear much more reponsive.

#1 by spender on 5/10/06 - 2:19 PM
#2 by stoem on 5/10/06 - 2:23 PM
Remember that I'm playing this back at 200% size which should show up any loss even more - and I cannot honestly say that quality seems to have dropped. And if I can't tell then my users can't either.
You're probably right though with your assumption, something must be affected. Still I found this very interesting. At the end of the day you could encode multipel times and publish the video that you feel hits the sweetspot.
#3 by stoem on 5/10/06 - 2:24 PM
#4 by adam on 5/11/06 - 5:48 PM
#5 by dorian on 6/1/06 - 11:33 AM
encoder ,what are the diffrents of 30fps, 25fps, 24fps, etc.