May 14, 2008

FLV VIDEO COMPRESSION

FLV VIDEO COMPRESSION

Nowadays, broadband connections are widespread amongst the internet. Finally, video can be effectively added to website. But which format to go for? (Flash!). And how to get it done? This article features some tips and tricks for compressing and delivering video to the web.

Video formats

There are a couple of interesting video formats available for the web. So which one to go for? Nowadays, the best option is the Flash Video (FLV) format. Why? Let's have a look at the numbers:

Player

Spread

Size

Formats

Flash Player 7

99%

1 MB

FLV

Flash Player 9 r60

30%*

2 MB

FLV, MP4

Windows Media Player

84%**

7 MB

WMV,AVI,MPG

Quicktime Player

68%

32 MB

MOV,MPG,MP4

VLC

?

9 MB

ALL FORMATS

Real Player

55%

8 MB

RM,AVI,MPG

Microsoft Silverlight

?

2 MB

WMV,ASF,MP3

* Solely based upon my serverlogs, may 2008

** I doubt this figure, since about every Windows PC has it installed. It should be more.

Note the sheer difference in web coverage and installer file size between Flash and the other formats. Also, installing the flash plugin doesn't require you to fill in tons of forms, subscribing you to redundant services and filling your mailbox with spam. Real is notably good in that, that is, if you can find the button for the free player at all ..

Video quality of the different formats widely vary. MPG compression is quite bad, a thing from the past. Regular FLV, WMV and MP4 have a similar, decent quality/ filesize performance. Quicktime 7 introduced a superior new codec (H.264) in 2004, which is used in MP4 and MOV files. Flash Player 8 introduced a similar impressive new codec, the ON2 VP6. And the latest Windows Media (version 10) has the excellent VC-1 codec. What does this mean? If you use one of these newer codecs you get great video quality at small filesizes, but since the software is less widely adopted, it's possible that your visitors first need to upgrade their plugin.

The only weak point of the flash player is that it solely supports its native FLV format, so you'll have to convert your existing videos to the FLV format. MP4 support is on it's way as well, but the required plugin version hasn't spread yet.

Compression software

Which brings us to the point of compression software. There are a couple of interesting packages:

  1. The Flash VideoEncoder, which comes with Flash CS3 ($699,-).
  2. Sorenson Squeeze for Flash MX ($119)
  3. The ON2 Flix Encoders (from $69 - free demos)
  4. The RivaVX FLV Encoder (Free, just for Windows)
  5. The VisualHub Video Converter (just for MAC, free trial or $25)
  6. The ZamZar website (free conversion).
  7. The HeyWatch! website ($0.10 per conversion).
  8. The FFMPEG compression suite (Free, nerdy, command-line, all platforms)

If you have Flash MX 2004 Pro, make sure to upgrade to version of the Flash Video Exporter (Video Updater 1.2) Previous versions had less features and more bugs. The Flash Video Exporter integrates with your existing video software and is in most cases available if you export a video from there. The others packages are stand-alones that accept a wide range of video formats. As of Flash8, the Flash VideoEncoder is also standalone.

Note that many sites (eg. YouTube) offer server-side encoding of video. You can upload whatever format you want, and they encode it automatically to FLV. There are two good software packages for this. The first is ON2's Flix Engine, which supports Flash8 FLV but costs $3500/year. The second is a combination of open-source tools, based around FFMPEG. It's free, but currently only supports the inferior Flash7 FLV (plus you have to take care of installing and updating all codecs.)

Source material

Bad source (camera shake, noise) gives bad compression. Try to compress from good source. With DV, i always rescale the source (720x540) to 320x240 to an uncompressed intermediate file. Due to the scaling, the dv noise has become sub-pixel noise and is way less visible.

Lots of cuts and motion also give bad compession. Remember that the compressor works roughly like this: it saves one frame (the keyframe) entirely. and then saves only the changes that occur in the following frames. This starts again at the next keyframe. So if you have a cut, every pixel of the next frame has to be saved. If you only have a talking head, few pixels will change and the file will compress very well.

Compression settings

I don't like big screen sizes. There's nothing I can see at 720x540 that i cannot see at 360x270. Remember that the screen area of the first one is 4 times the area of the second one, and that the file will also become about 4 times as large. You will rule out a lot of people with you big-screen fetish. Use resolutions of around 240 px wide for home video till 480 px wide for demoreels ..

I always use the 2-pass VBR converter (except for rough tests). It takes the most time, but gives the best performance. I use a keyframe for every 2 seconds (50 frames) for video with little motion up to a keyframe every half second (10 frames) for video with a lot of motion. Bitrate for the video: 200 - 1000 kbps, again depending on the amount of motion in the source material. Just try it and if it looks good, try a lower bitrate until the quality starts to decline. My audio is set to 32, 64 or 96 kbps mp3. 32 for just speech, 96 for cool music. Again, listen if the sound starts to loose crispness. Remember that a byte is not a bit ! A byte is 8 bits ..

Delivering FLV files

Ok, so now you have a couple of good-looking FLV files. What to do with them? Windows Media Player, Winamp and Quicktime will refuse to play them. For desktop viewing, you could use the excellent VLC Media Player. Just drop a FLV file on top of it and you're good to go.

For web publishing you can use my FLV Media Player. You don't need the original Flash Software, just a text editor to type in the correct path to your FLV file in the HTML file. More information and options can be found in the description of the FLV Media Player. If you don't like this script, just check out some other players. Note that some of them are not free and for some others you need the Flash authoring software.

Progressive download vs. streaming

The codecs and formats I discussed here are all based upon progressive downloading; a file is downloaded and played when enough data has been delivered. For enterprise video users (100's of video's, or videos from over 10 minutes) this is not efficient. They are better off checking out the various streaming platforms. A streaming platform detects your connection speed and delivers video exactly at the bandwidth you can handle (plus you can scrub the video without downloading it completely). For Flash, the streaming platform is called Flash Media Server, more info can be found at Adobe.com or at the FlashComGuru website.

A Bug in FLV compressors

warningNote that there is an annoying bug in most older FLV compression software (notably FFMPEG, FLV Video Exporter 1.1, Sorenson Squeeze 3 and the free Riva encoder). The duration and dimension metadata of a file is not correctly saved, leaving the FLV Player progressbar and movie scrubbing useless (or even setting the dimensions of a FLV file to 0x0 pixels). You can solve these problems by patching your FLV files with a small, free program, Buraks FLVMDI, and all your troubles are gone. For those of you running a Ruby Interpreter on their system, this little program does the same in Ruby.

Another note on movie scrubbing; Flash seems to only scrub to keyframes. So if you compress a movie with very few keyframes, the scrubbing won't run very smooth. Compress with more keyframes (can be set in nearly every compression tool) to get rid of this problem.

No comments:

Post a Comment

Popular Posts