Video Compression Guide

I just started to use fraps to record some of my PoE gameplay. I noticed that the resulting file .avi is poorly compressed (up to 10+GB of video), and it must be reencoded in order to be archived or uploaded to video hosting sites like YT.

For me this has been an occasion to rewake one of my old passions, the video encoding, which I had about 10 years ago, and to check what is the state of the art now. I wrote this guide on how to convert an .avi into a .mkv in a fast way. It requires some batch scripting, but it is quite easy.

Tools needed (free or Open):
- avisynth (this must be installed) http://sourceforge.net/projects/avisynth2/
- wavi.exe http://sourceforge.net/projects/wavi-avi2wav/
- neroaacenc.exe http://www.nero.com/ita/company/about-nero/nero-aac-codec.php
- x264.exe (8-bit depth) (must be the same 32 or 64 bit version as avisynth) http://www.x264.nl/x264_main.php
- mkvmerge.exe http://www.bunkus.org/videotools/mkvtoolnix/ or http://www.fosshub.com/MKVToolNix.html

Put all the .exe files into a folder, and create two files test.bat and test.avs in the same folder. You will edit these two file with notepad as follows

test.avs: (avisynth script)
---------------
avisource("x:\mypath\video_to_be_converted.avi")
bicubicresize(1280,720,0.1,0.45)
trim(1000,2000)
converttoyv12()
---------------
Notes:
- If you do not want to resize the video resolution, remove the second line. Of course you can use wathever resolution you like. The parameters 0.1 and 0.45 gives a quite 'good' quality.
- You can replace the second line with lanczosresize(1280,720) , it gives a little bit sharper video, but it is less comprimible
- the trim command takes the frame from #1000 to #2000 (1001 frames in this example). Remove this command if you want to encode the whole video. See also http://avisynth.nl/index.php/Trim
- If you remove the last 'convert' command, you can open this .avs file with virtualdub instead of using the following .bat file, so that you can use effects or do some basic video editing with a GUI tool

test.bat: (main .bat script)
---------------
wavi test.avs tmp.wav
neroAacEnc -br 90000 -2pass -if tmp.wav -of tmp.aac
x264 --output tmp.mkv --crf 25 --preset veryslow test.avs
mkvmerge -o final_video.mkv tmp.mkv tmp.aac
del tmp.wav
del tmp.mkv
del tmp.aac
---------------

Notes:

- The number after br is the audio bitrate. 90kbps is a good quality for me, if 2 pass is used. Tune it for your personal taste. I suggest to use 2 pass, since the encoding time for the audio is very low.

- x264 (video):
- The parameter after preset tunes the quality-vs-time ratio. Use the 'slow' preset for a faster encoding. There is also a 'placebo' preset, which is even slover.
- The number after crf is the quality. The lower, the better, but the larger filesize.

- The video encoding is for a 1-pass mode. If you want a two pass use instead

x264 --output tmp.mkv --bitrate xxxx --pass 1 --preset veryslow test.avs
x264 --output tmp.mkv --bitrate xxxx --pass 2 --preset veryslow test.avs

for three pass

x264 --output tmp.mkv --bitrate xxxx --pass 1 --preset veryslow test.avs
x264 --output tmp.mkv --bitrate xxxx --pass 3 --preset veryslow test.avs
x264 --output tmp.mkv --bitrate xxxx --pass 2 --preset veryslow test.avs

replace xxxx with the desired bitrate (in kbps). I suggest to use only 1 pass if you are confused about how multipass works.

For a full list of x264 options: http://mewiki.project357.com/wiki/X264_Settings

- The del commands remove temporary files

- If you want to upload to Youtube and you delete the final file after upload, you may want to use a lower --crf parameter to save quality.

Run the .bat file, and wait some minutes/hours. You will get the final_video.mkv in the same folder.



Roma timezone (Italy)

Report Forum Post

Report Account:

Report Type

Additional Info