How to Create and Compress Web-Based Video
When delivering video to your customers over the web, you want to get the highest possible quality at the smallest possible file-size. Uncompressed digital video files are enormous, and even conventionally compressed video is far, far too large (and bandwidth intensive) for web-based delivery. So, people have been hard at work for the last decade or so developing special techniques for compressing video files dramatically enough to make web-delivery viable, while sacrificing as little playback quality as possible to keep web-based video something the consumer would actually want to watch.Methods of Compressing Video
Video is compressed in two ways: (1) each frame is compressed as if it where a normal still image (this is called “spatial” compression), and (2) entire sequences of frames are compressed by setting a start and end frame and replacing the frames in between with shorthand information about how those frames differ from the start or end frame.
A little more detail on both types of compression: Spatial compression just treats an individual frame as if it were a still image, and compresses it much like a regular jpeg. This type of compression uses two techniques: First, the compressor finds all the pixels that have the same color values and, instead of describing each pixel individually, describes them all in one shot (this is called “lossless” compression, and is the type of compression used in Tiff files). Second, the compressor tried to make the pixels in an image be more alike, so it’s easier to describe them all in a few short definitions. It does this mainly by averaging nearby pixel colors together. In addition to the spatial technique, use Temporal compression. The compressor sets a “Key Frame” every so often. It then throws away all the frames in between the Key Frames, and replaces them with “Delta Frames” (or “Difference Frames”) which only describe the pixels that have changed since the previous frame.
Video Compression “Codecs”
“Codec” stands for “video COmpression and DECompression.” A codec is a specific strategy for combining Spatial and Temporal techniques to compress video and audio. Sorenson 3 is widely accepted as the most common and effective codec for web-based video. Whatever codec you use to compress your video, the person watching the video must have the same codec to decompress it so they can view it in their player.
Every Codec accepts at least a few basic parameters which tell it how much to compress the video. The essential three settings are: (1) the physical dimensions of the video, (2) the number of frames per second, and (3) the target data rate.
Physical Dimensions of the Video
Obviously, the bigger the picture the more pixels are going to be in each frame; and the more pixels in each frame, the more data required to describe each frame. Which means, the wider and taller your video, the larger the file is going to be and the more bandwidth it is going to require to deliver to your customer.
Standard Television is 640 pixels wide and 480 pixels high (“640×480”). Standard web based video used to be 160×120, but that is now considered a “low-bandwidth option.” 320×240 is the standard height and width for web video these days.
Frames Per Second
The more frames you have per second of video the more pixels your video file has to describe, and thus the larger your file-size and bandwidth needs will be. On the other hand, the fewer frames per second the choppier your motion appears.
Television transmits around 30 frames per second (“fps”). The standard for internet video varies. Webcam-type video goes as low as 1 or 2 fps, but most web video is somewhere in the vicinity of 15 fps.
Data Rates
A “data rate” defines how much data you can transfer in a second. If you want someone to be able to watch your video in real time, you can’t deliver them more data than they are able to receive at a given time.
Since regular TV sends 30 frames every second, with each frame being 640 pixels wide by 480 pixels tall, its data rate is an absolutely enormous 27 Megabytes per second. A dial-up connection transfers an honest 4 or 5 Kilobytes of data per second. If delivering real time video to a dial up audience is your goal, you are going to have to create video files that look acceptable to your customer and that have a data rate of 4 or 5 KB / second. That’s about 5,000 times less bandwidth than TV – good luck! An honest “broadband connection” can deliver about 25 Kilobytes of data each second. That’s about 1,000 times less bandwidth than TV.
The Art of Compression
So how the hell are you supposed to deliver video anyone would actually want to watch over a connection that is 1 to 5 thousand times inferior to a television set? Well, obviously your content needs to be something they can’t get on TV, at least not as easily. But as far as this article is concerned your main strategy is to use your compression codec wisely. First understand your target customer. Are you going to cater to people who don’t mind waiting for downloads? If so, you have some more leeway (but fewer customers). In reality you should provide at least two options to your customer – a higher-quality / longer-wait version and a lower-quality / quicker-playing version.
The first talent you need to acquire in the art of compression is mastering your data-rate. Use this formula:
data-rate = (width x height x frames-per-second ) / 48,000
So, if you want to deliver an average quality web video (320×240 @ 15fps), your base data-rate would be 24KB per second (that’s about 192 kbps). You can play with this number. If your video has a lot of movement in it, you are going to need a larger data-rate to get it to look descent – as high as 48 KBps (384 kbps). If most of the pixels in your video stay the same from frame to frame, you can get quality looking results with smaller data-rates – as low as 12 KBps (96 kbps). You should also play with frames per second. Again – if your pixels are always changing frame to frame (read: “a lot of motion in the video”) you might benefit from a few more frames per second. But if your video is fairly static, without a lot of difference from frame to frame, you can get away with reducing your frames per second to 10 or lower.
Starting at Square One
As you already no doubt understand, the fewer changes you have from frame to frame the more you can apply compression with less visible side effects on the finished product you deliver on your website. Keep this in mind while filming and editing! What you do before compression will have more effect on the quality of your finished product than any amount of monkeying with data-rates and codecs. Here’s some specific advice:
1. Filming: Get those cameras on tripods! Jerky camera movement will kill the finished quality of your compressed video. Avoid excessively moving the camera around, panning, zooming, etc.
2. Editing: When editing your internet clips, edit out the jerky movement, pans, zooms, etc. that slipped by the camera person. And use very short transitions, fades, etc. If you don’t take the time to do this, you will have to be satisfied with having the pans, zooms and fades look like shit in your web video, while the rest of it looks just fine.
3. Rendering: Render in two passes. The first pass prepares your video for compression, and the second pass actually applies the codec and compresses it.
The First Pass: Preparing the Clip for Compression – In the first pass you need to: Get rid of artifacts and average out your pixel information by raising the contrast and brightness to blow-out the white areas and crush the blacks (reasonably, of course). Crop your source video. Especially if using a Sorenson codec, you should crop your source video to a pixel size that divides by 8. (Cropping the source will also get rid of the crappy looking lines that often appear on the edges of compressed video.) Don’t forget your audio. On the first pass, use your audio filters to normalize the audio track to 0 db. If you have a compression filter, use it! With the video and audio filters in place, and your cropping done, render your clip with a compression setting of “none.”
The Second Pass: Compressing It – Take the huge file you just rendered and stick it into your compression program. Run your codec on it, and work the three golden variables (dimensions, frames per second, and data-rate) as described in the first half of this article. Use trial and error to discover the tradeoffs and find the setting that works best for the type of video you are delivering to your customers on the Web.
4. Delivering: A few other web-video considerations outside the scope of this article, but which I should mention briefly: You also want to consider the final format you will deliver your web video in. Essentially you can choose between Quicktime, Real, Windows Media, and MPEG-1. You may also want to consider chopping you longer clips into individual scenes – they download more easily, and your customer might only want to watch a specific scene anyway (which will save you bandwidth). You also want to consider offering video for download or streaming it, or both.