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.

42 Comments:

  • Great find sh0dan. Looking forward to testing some VP6 encodes out at work tommorrow. Thanks for uploading a binary. I still haven't got around to compiling FFMPEG myself.

    By Anonymous Anonymous, at 12:51 pm  

  • This is excellent! the FLV8 video quality is just awesome. Just 1 question: How would I get a copy of the VP62 codec for busienss use?

    By Anonymous Anonymous, at 6:52 am  

  • @Anonymous: I think you would have to contact ON2 to be sure. My guess is, that they wont complain if you have a a Flix Pro license.

    By Blogger Klaus Post, at 9:34 am  

  • hmm didn't work for me :(
    still searching for a solution to encode VP6 flvs on my linux box.

    By Anonymous Anonymous, at 8:54 pm  

  • it does work perfectly. however the encoder is painfully slow. I compared it to FFMpeg's FLV7 (Sorenson Spark) encoding which is blazing fast...

    By Anonymous Anonymous, at 8:19 pm  

  • nice! works like a charm!

    By Anonymous Anonymous, at 2:38 pm  

  • Hej Klaus,

    I get this result:

    Source:
    * Filename: "C:\Downloads\FLV encoding\ffmpeg\example.avs"
    * FourCC: YV12
    * Frames: 416
    * Resolution: 640x480
    * Frame rate: 15.000 FPS

    Error: The file you are trying to open is a -1456008473 pass file.

    The AVI file is from a Canon digital camera which uses the MJPEG codec. Can you help?

    PS: I'm in Denmark too.

    By Anonymous Anonymous, at 11:43 am  

  • Hi again,

    Found the problem. The example.bat file has the configuration step rem'ed out. Works fine when you execute
    avs2avi.exe "example.avs" "temp.avi" -P 2 -p 0 -s vp62.conf -e -w
    before example.bat.

    Carl

    By Anonymous Anonymous, at 3:04 pm  

  • Hello,

    I think the audio options for ffmpeg :
    -b 128 -ac 2 -ar 44100
    are partly inexact. In fact the option -b applies to the video bitrate, not for audio.

    It should be -ab 128. Thus the mp3 will be 128 kbits/s. If you don't specify -ab, the default value is 64 kbits/s...

    At least that's what my tests gave me

    Cheers!

    By Anonymous Anonymous, at 11:46 am  

  • My FLV file is very small and it looks broken (unreadable by any flv player).

    By Anonymous Anonymous, at 10:17 am  

  • If you find out that audio options have a strange behavior, you should try to put them after "-i "example.avs""

    The whole command line would then be :
    ffmpeg -y -i "temp.avi" -vcodec copy -i "example.avs" -ab 128 -ac 2 -ar 44100 "example.flv"

    I had problems with it so I put my feedback here...

    If you want to encode audio at 22050Hz (to save place), just change -ar to -ar 22050

    By Anonymous Anonymous, at 6:51 pm  

  • Thanks for the great info, sh0dan!

    I had problems using the example.avs file. The output avi file was a very small video, just 10 seconds long (not the same length as original), and instead of the original video stream, I got a video stream of an error message saying "AVISource: couldn't locate a decompressor for fourcc mjpg (C:\Documents and Settings\<snip>\example.avs, line 1). When I changed line 1 of 'example.avs' to 'DirectShowSource("example.avi")', everything worked fine! Hope this helps someone.

    Also, I found out that neokilly is correct, the '-b' option to ffmpeg should be '-ab'.

    By Blogger Eddie, at 10:34 pm  

  • My temp.avi is always a very small and broken file so the flv is broken too..

    By Anonymous Anonymous, at 6:24 pm  

  • I had some trouble finding the VP6 codec, so for anyone who hasn't downloaded it yet, here it is: vp6_vfw_codec.exe (1.67 MB)

    By Anonymous Anonymous, at 3:52 am  

  • Can this procedure encode any file type to flv ?=

    i am searching for a solution with vp6 encoding from any file type.

    the tool should be startet from a command line..

    any idea ?

    By Anonymous Anonymous, at 7:10 pm  

  • How to cofigure VP62 codec to encode alpha channel?

    By Blogger Boris, at 11:14 am  

  • thanks for the article.

    Do you know a way to concat two .flv files into a unique one? Im trying all the ways, but can find a solution :((

    By Blogger Unknown, at 5:49 pm  

  • To concat two .flv's this might work, it uses mencoder (works for me with avi files so might be worth a try with FLVs):

    mencoder -oac copy -ovc copy -idx -o myNewFLV.flv firstVideo.flv secondVideo.flv

    Videos need to be same size, codec, etc.

    By Anonymous Anonymous, at 2:55 am  

  • I am not sure to well understand your tutorial. FFMPEG seems having to do 2 pass. The both pass settings are written in vp62.conf. Does I have to open the AviSynth script with virtualdub, to save as Avi and to run the batch file or is it automatically done with FFMPEG?

    Another question: how can I edit your vp62.conf file?

    Why should I ask for 2 pass using VP62 codec? Did I missunderstood?

    Thanks anyway for this nice piece of code :D

    By Anonymous Anonymous, at 12:54 pm  

  • I am not sure to well understand your tutorial. FFMPEG seems having to do 2 pass. The both pass settings are written in vp62.conf. Does I have to open the AviSynth script with virtualdub, to save as Avi and to run the batch file or is it automatically done with FFMPEG?

    Another question: how can I edit your vp62.conf file?

    Why should I ask for 2 pass using VP62 codec? Did I missunderstood?

    Thanks anyway for this nice piece of code :D

    By Anonymous Anonymous, at 12:54 pm  

  • Thanks sho0dan... don't know how else I was going to get my AVS scripts into beautiful vp6 flash...

    BTW, it is simple to add an AVS "adapter" to your batch file to make it work with existing AVS files. Just take the script name as an argument...

    echo import("%~f1") > adapter.avs
    echo ssrc(44100) >> adapter.avs
    echo convertaudioto16bit() >> adapter.avs
    echo flipvertical() >> adapter.avs

    By Blogger Greg Dingle, at 3:35 am  

  • is this tool could encode a stream? For example from web camera?

    By Blogger coordinateaxis, at 9:45 am  

  • Hi sh0dan,

    thanks very much for your package.
    Its working very well!

    I have created a few batch scripts with the following benefits:

    +Easy configuration with presets
    +AVI encoding
    +WMV encoding
    +Entire folder encoding

    Give it a try:
    http://tigerix.funpic.de/blogspot.com/flv-vp62-encoder.html

    By Anonymous Anonymous, at 5:21 pm  

  • New Version:

    I have released a new version of my scripts mentioned in the previous post.

    X Lots of bug fixes: E.g. files & folders with space in name are now working correctly. E.g. "C:\Media Files"

    + Writes a log file

    + Hide encoding window (Needs to be activated in the script options)


    Please use Download-Link of previous post. Thanks.
    Have fun!

    Cheers, Tigerix.

    By Blogger Tigerix, at 3:19 am  

  • Tigerix; tnx for batch scripts, will certainly learn something new about batch scripting! :)

    By Anonymous Anonymous, at 2:28 pm  

  • eh, previous post was mine, not intentionally 'Anonymous'

    smok3 ~

    By Anonymous Anonymous, at 2:30 pm  

  • -Small bugfix
    (Hide window feature didn't work)

    Download new Version:
    http://tigerix.funpic.de/blogspot.com/flv-vp62-encoder.html

    @smok3: My pleassure. Happy to hear that there is someone using my script :)

    By Blogger Tigerix, at 12:12 pm  

  • This comment has been removed by a blog administrator.

    By Anonymous Anonymous, at 7:30 am  

  • This comment has been removed by the author.

    By Blogger Klaus Post, at 12:37 pm  

  • I was attempting to make a Flash from MPEG2 (.mpg) and I keep getting message file has nulls. I dont know what the means. Help..
    I want to build sort of a drop folder MPEG2 (.mpg) goes in and in another folder flash files with same name are there. Can amyone help me Please?

    By Blogger Unknown, at 1:40 am  

  • What's the point of AVISYNTH...I know to do the script but can't FFMPEG do that?

    By Anonymous Anonymous, at 8:09 am  

  • Does anybody know where I might find the most recent version of this script?

    By Anonymous Anonymous, at 10:22 am  

  • What's the point of AVISYNTH...I know to do the script but can't FFMPEG do that?
    AviSynth is used to deliver the video to AVS2AVI and AVS2AVI to convert the video to AVI/VP6. Since the VP6 codec is only available as a VfW codec, this step is necessary.

    By Anonymous Anonymous, at 1:44 am  

  • How would I get a copy of the VP62 codec for busienss use?
    Buy a copy of On2 Flix, install it and you'll have the codec available on your system. The conversion method described above still works, your not forced to use Flix :)

    By Anonymous Anonymous, at 1:48 am  

  • Very, very useful tool. Thank you so much for that!!!

    By Blogger Unknown, at 3:09 am  

  • Hi guys,

    I really need some help with install this on my server to get my streaming to work. Can some1 help pls. ill pay good.

    contact: kentalaxen@hotmail.com

    By Anonymous Anonymous, at 6:44 pm  

  • Can anyone get this to work under wine for linux?

    Thank you!

    By Anonymous Anonymous, at 9:47 pm  

  • This has been very useful, thanks!

    By Anonymous Anonymous, at 4:01 pm  

  • Hi guys and sh0dan ,

    I have a problem.

    Do you have the source of the ffmpeg-patched that you use for create windows .exe , so I can try to compile that ffmpeg in my Linux box?

    Br

    Goodbye

    Pierpaolo

    By Blogger Pierpaolo Gulla, at 12:52 am  

  • There is a patch file against revision 6373 included with the executable. Download this revision and apply the patch, and you should have the source code.

    By Blogger Klaus Post, at 7:17 am  

  • When i flip video from avisynth then use save video from VB then run bat file i expected video to return to normal when done but it does not go back it is always upside down even if i dont flip it with avisynth :(

    Please help at farmdve@data.bg or write here

    By Anonymous Anonymous, at 1:25 am  

  • Thanks for sharing this article.
    punjabi movies

    By Anonymous Anonymous, at 2:16 pm  

Post a Comment

<< Home