No announcement yet.

Guide to Encoding Videos

  • Filter
  • Time
  • Show
Clear All
new posts

  • Guide to Encoding Videos

    I found this guide on the EvE-Online forums posted by their very own forum warrior Dark Shikari. I claim nothing over this article and none of it is my work it's all his. I thought this may be useful as Eve requires high res video with low file size since some of the Eve-vids are over 30 minutes long. These are the same charecteristics required of BF2142 videos.

    Dark Shikari's Guide to Encoding Videos

    I've seen a lot of videos lately that are badly encoded. Some have bitrates as high as 5000kbps and still look blocky, and others have bitrates as low as 1000kbps and look really ugly. The purpose of this guide is to explain the most common methods of video encoding for high-resolution high-bitrate videos, such as EVE videos. Each has its advantages and disadvantages; which one you choose should be based on which are important to you.

    Before I start, I should clarify the difference between a container and a codec. A codec is what actually compresses the video and stores the video data. Common codecs include Xvid, Divx, WMV9, and H.264. This data from the codec is stored in a container format, which interleaves the video and audio in a particular format. Different container formats have different properties, such as the ability to stream the video while downloading, the ability to have multiple audio streams and/or subtitles, the ability to play an incomplete file, and so forth. Common containers include .AVI (Audio-Video Interleave), .WMV, .MP4, .MKV (Matroska), and .OGM (Ogg Media).

    The best way to encode a video is to seperate the encoding and rendering steps. That is, when you are finished with making your video in Premiere, Vegas, or whatever movie maker you use, you save the video as an uncompressed file or a losslessly compressed file, which you then compress afterwards with the program of your choice. This is advantageous because it allows you to try many compression methods without re-rendering the whole video over and over. It also allows you to look to find errors in the video before you spend hours on a slow compression operation. Note that at high resolutions, uncompressed videos can get very, very large, on the order of 10s of gigabytes. As long as you have the space it should not be an issue, though sometimes the bitrate can be so high that your hard drive will be too slow to play back the video without stuttering. One solution for this is to use the HuffyUV codec, which will shrink your video by about 2-3 times without any lossiness. It is extremely fast and uses minimal CPU. If you want to compress your video more, you can try Xvid on single-pass mode with the Quantizer at 1.0, which will be minimally lossy and pretty fast.

    To get maximum quality, you should always encode in twopass mode. This does a first pass to see what parts of the video need more bitrate than others, and allocates extra to them in the second pass, which does the actual encoding. It will usually improve quality greatly over one-pass mode.

    The first part of the guide will be on video, and the second on audio. Audio is not as much of an issue as the bitrate is so much lower than the video bitrate that the difference between codecs is minimal.

    A quick overview of container formats before we get onto the codecs:

    .AVI: The standard format for video. An open standard, and supported by basically every player known to man. It is also very outdated and doesn't support most modern features, such as subtitles, streaming, multiple audio tracks, and so forth. It also doesn't support B-frames and some modern video codec features, and so its use has been deprecated in some codecs such as Theora and H.264.
    .WMV: Microsoft's proprietary video format. Supports most of the features AVI is lacking, but also only supports WMV video and audio; its not meant for other codecs. Its main disadvantage is that it is very incompatible with almost everything other than Windows Media Player; it cannot be opened in Virtualdub and has little support on other operating systems. The support that does exist is often questionably legal. This is probably the most popular container for EVE videos simply because Windows Movie Maker exports to it by default.
    .MP4: I don't know much about this one. It is Apple's competitor to WMV, and supports many more codecs. I don't use it personally.
    .OGM: Ogg Media, an ugly hack to get video into an Ogg file. Unfortunately, the source was lost (literally lost) for the main demuxer, and so the project has basically been abandoned and replaced by the much better Matroska format:
    .MKV: Matroska, the open source modern video format. Supports streaming, subtitles, variable frame rate, multiple audio tracks; everything you can think of, and is supported flawlessly by VLC, mplayer, and most other modern players. Its main disadvantage is that it isn't supported by default under Windows, unlike .AVI and .WMV, and requires extra software; either a supporting set of codecs and demuxers like the CCCP or simply a fully-featured player like VLC.


    Video Quality: **
    Windows Compatibility: ****
    Cross-Platorm Compatibility: *****
    Encoding Speed: ****
    CPU Required for Playback: ** (lower is better)

    Container normally used: .AVI

    Xvid is the most popular implementation of the MPEG-4 video standard. A very versatile codec, it is free and open source and though somewhat outdated today, it still has relatively good video quality. Though the decoder doesn't come with Windows, most users have either DivX, Xvid, or both, which are compatible with each other. As it is open source it is perfectly compatible on OS X and Linux also. It also requires considerably less CPU to play back than more modern codecs. The main disadvantage is the relatively low video quality; even at higher bitrates it can get blocky, especially with complex scenes in EVE Online. There are many options for video quality that affect compression speed; on the lower settings it can encode two or three times faster than it plays back, an order of magnitude faster than more modern codecs. On higher quality settings it slows down somewhat, but is still quite a bit faster.

    Xvid is easy to encode with. Simply download the latest version of Virtualdub and the Xvid codec. Open your video in VirtualDub, set the codec to Xvid, and set your options. For best quality:
    Profile (click "more..."): Advanced Simple @ L5

    Encoding type: Twopass. You will have to do the first pass and then run a second pass. In the second pass, it will allow you to choose the bitrate. The first pass will be considerably faster than the second.

    Zone options: Chroma Optimizer

    Quality preset (more...): Motion Search Precision: Ultra High, VHQ mode: Wide Search, Use VHQ for bframes too, Use chroma motion. On the "Quantization" tab make sure Trellis quantization is enabled.

    Once you're done, just save as. For the second pass, choose a good bitrate; don't make it less than 1500kbps, and for a large video (1024x768 or more) you might want 3000kbps or better. Especially with the lower quality Xvid codec, you should make sure not to choose too low a bitrate. If it looks blocky, you can always try it again with a higher bitrate. Make sure you compress your audio also using the audio menu, but that is covered later in the guide.

    The encoder for Xvid also includes a decoder.

    Windows Media Video 9

    Video Quality: ***
    Windows Compatibility: *****
    Cross-Platorm Compatibility: **
    Encoding Speed: **
    CPU Required for Playback: **** (lower is better)

    Containers normally used: .AVI, .WMV

    Windows Media Video is also a very popular codec due to both its use in Windows Movie Maker and due to the fact that its supported by default by all modern Windows installations. It has better video quality than Xvid and is equally versatile. Its main disadvantage is that it is not supported well on other operating systems due to its proprietary nature (note that this issue is seperate from the issue of the .WMV container not being compatible; both the container and video codec have problems). If embedded in a .AVI file, however, it can be opened fine in Virtualdub under Windows.

    There are many ways to encode Windows Media 9. If you want to put it in a .AVI file for compatibility, you'll need to use the VCM codec and Virtualdub. To make a .WMV file for the streaming capability, you will need the Windows Media Encoder software. Either way, always choose twopass mode and "Best Quality" on the slider, as this sacrifices compression speed for maximum quality. A reasonable bitrate is 1000-1500kbps for a 640x480 and 2500-3500 for a very large video such as 1024x768 or above. Try it and see how it comes out. Note that using the "Complex" or "Advanced" profile will improve quality but also increase the CPU required for playback, especially on a large video.


    Video Quality: *****
    Windows Compatibility: ***
    Cross-Platorm Compatibility: *****
    Encoding Speed: **
    CPU Required for Playback: ***** (lower is better)

    Containers normally used: .AVI (not recommended), .MKV, .MP4

    H.264 is the most recent of the three codecs in this guide and has by far the best quality. Though it is already two or three years old, it is still quite a bit newer than the older MPEG-4 based codecs like WMV9 and Xvid. Its main first adopters have been digital video distributers such as Apple who want to pack as much quality as possible into the smallest possible package, and interestingly enough, anime fansubbers, who realized that the extremely accurate motion search capability of H.264 increases quality greatly.

    The main advantage of H.264 is its incredibly high video quality, which is superior to every other major codec on the market at high bitrates. This allows you to either get crystal-clear quality at the same bitrate or get similar quality to WMV9 at a much lower file size, which should help a lot considering how slow EVE-files is these days. It has many disadvantages, however. First of all, while it can be put in a .AVI file, it has many modern features such as B-frames which either don't work in .AVI files or require ugly programming hacks in order to. Thus the developers will always tell you not to use .AVI files. The container I'd recommend is .MKV, Matroska, simply because anyone who has the ability to play H.264 video will almost certainly be able to open a Matroska file. MKV files also support streaming, just like WMV. H.264 is also slow to encode, like WMV9, and additionally requires more CPU for playback than any other modern codec. However, all modern processors should be able to play the video without stuttering, especially as the decoder is multithreaded. H.264 video will probably not work in real-time on older Pentium 3 systems, however, and the absolute highest resolution videos (1280x720) may have a minimum requirement of 1.5-2Ghz or so for playback.

    The best free encoder is x264, for which a Windows build (updated regularly) can be found here. There are GUIs available, but command-line mode is easy because you can just copy-paste the options to use without navigating through windows. Also note that x264 takes only YV12-formatted video as input; this means you will have to install Avisynth (make sure to choose the latest version). Create a script similar to the following and put it in the same directory as your video:


    Then, go to the command line, navigate to the directory, and use the following options to encode. These will ensure very high quality. The first line is the first pass command, the second is the second pass.

    x264 --trellis 2 --me umh --bime --merange 256 --partitions all --8x8dct --pass 1 --bitrate 1000 --subme 7 --b-rdo --mixed-refs --direct auto --progress --threads 4 -o output.mkv script.avs
    x264 --trellis 2 --me umh --bime --merange 256 --partitions all --8x8dct --pass 2 --bitrate 1000 --subme 7 --b-rdo --mixed-refs --direct auto --progress --threads 4 -o output.mkv script.avs

    Change the "bitrate" field to whatever you want. You will need less than if you used WMV9. If you need to speed up encoding, lower --subme to 5 or 6 and lower --merange to 32. Output.mkv is the name of your output file, and script.avs is the name of the above script file that you saved. Also note that the encoder is multithreaded (using the --threads option as shown above).

    Once you're done with this, open your original video file in VirtualDubMod, a fork of VirtualDub that handles MKV, MP4, and other modern container formats. Save the audio stream to a file, then open your output video and add the audio stream back in from the file, and compress it. Note you will get an error about not being able to read the video; don't worry about it! Save the resulting video (using Direct Stream Copy under video settings) as the MKV file of your choice, and you're done! A sample video encoded this way can be found here. It is 8 minutes at 40 FPS at only 1000 kilobits per second and high resolution, but looks relatively high quality. Its FRAPS of a battle against some dreadnoughts and carriers at a POS. And no, we didn't kill the carrier; somehow it managed to get out. We got another killed later though with help of a small Band of Brothers fleet.

    To play back a file of this sort, you need either the CCCP (to play the video in a normal video player like Windows Media Player) or a codec-independant player like VLC. I highly recommend VLC; it works flawlessly regardless of how screwed up the video codecs are on your computer and its a fast download.

    A quick guide to audio codecs:

    Since the video bitrates we're dealing with here are in the thousands, using low bitrate audio to "save space" is really silly. I usually use LAME MP3, which works on basically every video player and works in nearly all video containers. The ACM codec can be found here, which will add a LAME MP3 encoder to the list in Virtualdub. Use at least 128kbps and probably no more than 256kbps. Don't use any higher bitrate than the bitrate of your original music; that's pointless. Don't use anything lower than 128kbps or it will probably sound like crap.

    There are other audio options, like OGG, WMA, and AAC with much higher quality at lower bitrates, but there's little point in using them for the aforementioned reasons.

    In conclusion, if there is anything seemingly vague or incorrect in this guide, please post and I will correct it or add information to clarify.

    And I can't stress this enough, use VLC, it is a very good video player...


    Is this useful?

    |TG-Irr| Incurable

  • #2
    Re: Guide to Encoding Videos

    I'm missing some of the links out of the text and will add them in when I'm a little more awake.

    |TG-Irr| Incurable


    • #3
      Re: Guide to Encoding Videos

      The author of that article really pushes H.264, and while it may be technically superior and have tons of spiffy tricks internally, it impacts the ability of your audience to effortlessly play your videos. Those users who have not actively sought out additional video codecs or players may not be able to play back H.264 easily, and that can cause frustration. Just something to think about.

      Also, there are some differences between the subject matter of EVE-Online and FPS games (like 2142) that can make a difference in what codec is more optimal. EVE has large, slow moving, similarly colored backgrounds, that "appear" very far away and can take up a large portion of the frame that some codecs will munge the heck out of with compression. Whereas, a fast moving FPS game will see more radical changes in all fields of the video (i.e. buildings moving rapidly in close quarters combat.) Plus, a video of a FPS would be generally be more fast paced with action and the changes frame by frame will most likely be larger. Changes in subject matter can also make a difference as to which codec is more optimal for output.


      • #4
        Re: Guide to Encoding Videos

        In a later post he reccomends WMV9. And yeah I suppose the videos chareteristics are different in some aspects.

        |TG-Irr| Incurable


        • #5
          Re: Guide to Encoding Videos

          I tend to go for wmv9 due to the ability of people to be able to play it.

          “Up, sluggard, and waste not life; in the grave will be sleeping enough!” Benjamin Franklin




          TeamSpeak 3 Server




          Twitter Feed