sh0dan // VoxPod

Friday, September 29, 2006

Command Line Flash 8 FLV Encoding

I have been searching for a command line Flash 8 (VP6) FLV video creation tool for a long time. I've bought On2's Flix Pro - but even though it is a mile better than Sorenson's horrible Squeeze, it still had some serious issues with AviSynth input for instance. In general it was good for one-at-the time encoding, but batch processing was tedious and buggy.

So for a while I had actually went back to Flash 6, and batch encoding via ffmpeg's built-in FLV-encoder. While browsing for some info on VP6, I found an ffmpeg patch, that allowed for VP6 AVI to FLV muxing. Even though it's a few months old, it hadn't been included in ffmpeg, so I merged it myself, and after learning how to build ffmpeg, I got a working version. Here are the tools you need:

ffmpeg win32 binary including VP6 FLV mux patch.
Toolpack with example avs and bat.

You also need: Avisynth 2.5.6 or later, and last but not least the On2 VP6.2 VFW codec. The On2 codec is free for personal use, but for some strange reasion it is no longer offerered at On2's website. For commercial use, you should be (morally) ok, if you just buy Flix Pro.

Short how-to:
  1. Install AviSynth.
  2. Install VP6.2 codec.
  3. Unpack ffmpeg and the toolpack from above in the same directory.
  4. Put an AVI file called "example.avi" (that is readable by AviSynth) into the directory with ffmpeg.
  5. Run "example.bat".
  6. Wait.
  7. You should (with a bit of luck) have an "example.flv" by the time the bat file finishes.
You can use the excellent FLV Player by Martijn de Visser to watch your result offline, or use Jeroen Wijering's great Flash Video Player and put your result online.

Customization.

The important part of video encoding is of course customization. There are three main points. The AviSynth script providing the input - the video encoding parameters and the audio encoding parameters. I will cover how you can modify these settings, as there are many good guides on what settings to use for good quality.

Customizing Input
Your input is a basic AviSynth script. The example included looks like this:

AviSource("example.avi")
ConvertToYV12()
SSRC(44100)
ConvertAudioTo16bit()
FlipVertical()

If you don't understand anything of this, avisynth.org is a good place to start learning.

Yes - VP6.2 supports YV12 input, and yes - your video has to be upside down(!!). Of course you can use MPEG2 input using DGMPEGDec and others using DirectShowSource. Other than that, the audio must be 44100, 22050 or 11025Hz, 16 bit for the mp3 encoding.

Use Virtual Dub to open your script, while you are finetuning it.

Customizing Encoding Parameters.

If you know AVS2AVI, you'll know that codec settings can be stored in a configuration file. To do that, execute this command:

avs2avi.exe "example.avs" "temp.avi" -P 2 -p 0 -s vp62.conf -e -w

This will allow you to choose two pass encoding parameters in a dialog like this:


Be sure to choose the VP62 codec, as shown above, and press Configure. Once you've configured settings for pass one, press OK. The same dialog will show up again, and this time you configure your second pass. Click ok, and your new settings will be stored in vp62.conf

If you only need one pass, use this command line:

avs2avi.exe "example.avs" "temp.avi" -P 1 -p 0 -s vp62.conf -e -w

You then use a command similar to this to execute the actual encode:

avs2avi.exe "example.avs" "temp.avi" -P 2 -p 0 -l vp62.conf -w

First pass is usually very fast, but the second pass can be rather slow, if you choose best quality.

Configuring Audio

Audio encoding is done by ffmpeg, which uses the LAME engine for encoding. The encoding settings in the example are:

-ab 128 -ac 2 -ar 44100

Which relate to bitrate, channels and samplerate. These are the settings you may need to adjust. 64 kbit mono is actually very good for low bandwidth video.


That's the basics! Enjoy!

Edit: Discussion is a bit tedious here, so here is a link to a doom9 forum thread, where you can ask questions. I'll post a "troubleshooting" guide.