Welcome Guest [Log In] [Register]
Welcome to Fansub TV Subs. We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you're already a member please log in to your account to access all of our features.

Username:   Password:
Add Reply
Encoding Tutorial; The most confusing part
Topic Started: Aug 6 2009, 03:33 PM (1,599 Views)
JinK

Basic Concept
When one sees a video, they expect many things. One would expect the video to be clean with crisp edges and nice blending of colors. One would expect the video to play smoothly and without lag. One would expect the video and audio to be in synch. One would expect the video to be a good size for its quality given. One would expect the video to play correctly on their computer. All of these troubles depend on the encoder. To do all this is not one easy job. It requires a GREAT wealth of knowledge (as well as trial and error) to get the perfect outcome… a delicate balance between file size and quality. Many others explain videos from the basics to the specific details. In this tutorial, the fine details shall be explained first because if one wants to encode videos, an encoder must know these details.

Compression
As many know, an anime uncompressed takes a ridiculous amount of space; approximately 4 GB of data in a single minute in a 1280x720 video. Because of this, videos are compressed for the sake of saving space so that one can store more of those precious videos. That single minute that was 4 GB can be compressed down to a mere 20MB (that’s about 1/200ths the uncompressed size) and still retain its video and audio quality. Animes, as of late, have been compressed down to standard sizes of 175MB, 200MB, 230MB, 270MB, 300MB, 330MB, or 350MB for its ability to fit in CDs and DVDs and not because it’s an ideal size of a balance between quality and size. A video can be compressed in many, many methods. Compressing a video is quite the headache for anybody that doesn’t know anything about encoding. First of all, there are many different ways to compress videos. The reason why there are so many compression methods is because each compression method takes more or less CPU power or takes more or less space. Therefore, certain compression methods are used for different purposes (examples: streaming, archival, one-time-viewing, professional editing, etc.). These different ways of compressing videos are where codecs come in. Video codecs either encode for when you want to make into a different compression format or to change the compression level, or decode videos for when you wanna see video (You may notice that trays on the taskbar on the bottom right appear when you watch videos). Codecs basically allow one to read or write with different compression methods of videos. You may already know a few compression methods (H.264, divX, Xvid, rm, rmvb, mpeg, mp3, pcm, gsm, etc). For the sake of common understanding, to explain the image portion of a video, the word video shall be used and audio for the sound portion of a video from now-on-forth.
Edited by JinK, Aug 6 2009, 07:17 PM.
Offline Profile Quote Post Goto Top
 
JinK

Video Compression
Videos take a tremendously large portion of space. By compressing data, unneeded data gets thrown away. What kinds of data get thrown away? Well…for instance, when there is a still background, it’s unnecessary for the one to store the same data over and over again for each frame the background is there. Or in another situation, a moving object doesn’t change how it looks and merely moves around. One has to make sure that the video encoded is done well. There are many factors to which make a video good or bad. The two pictures below are from videos encoded to the same file size yet the outcome was drastically different.
Posted Image Posted Image
Video compression is very complex and is still advancing. And it's necessary to know all those little things.
There are two different types of video compression: lossy and lossless. As its name suggests, lossy video loses picture quality and lossless video retains all of the original video’s quality. However nice lossless sounds, it is largely not preferred as the video still is huge. Lossy video is what this tutorial shall cover. There are multiple compression methods. Compressing a video will require more than just general knowledge of compression formats. For the sake of simplicity, this tutorial shall talk specifically about mpeg-2, mpeg-4, divX, Xvid, and h.264 out of the countless others that there are.

  • DivX – DivX is a compression method that has simplicity in mind for anyone to use. It has a slider that lets the user decide whether a video being encoded should be in good quality yet huge is size or terrible is quality yet small in size. The DivX codec was then succeeded by XviD, which actually broke off as a freeware version of DivX.
    * Special benefits – Free
    * Disadvantages -
  • Xvid – Xvid is based off of the DivX codec but is a freeware version. Xvid was a more efficient version of DivX with some added capabilities as users upgraded this freeware codec. Basically similar to DivX in that its main point is the slider between quality and size.
    * Special benefits – Free
    * Disadvantages -
  • mpeg-2 – Moving Picture Experts Group 2. This encoding method is currently the standard video format used in DVDs and is used by many different television stations. This format is widely popular as it has become the standard that has been well implanted into today’s digital world. However, this format is largely inefficient in its ability to compress videos. This format does not do well in low video bitrates and does not support interlaced video unless one uses mpeg part 2. In short, you really want to use this format only if you want to play a DVD on a DVD player.
    * Special benefits – Very fast encoding
    * Disadvantages - Very large video size
  • mpeg-4 – mpeg-s is still a developing standard and is still improving. This compression method is more of a compilation of all the compressions out there, along with some new things. There are actually a number of different parts to mpeg-4 so when a program or hardware says that it is compatible with mpeg-4, it’s not always necessarily going to play correctly every time. Mpeg-4 has many different parts to consider when being used like Advanced Simple Profile, AVC, H.264, etc...
    * Special benefits – **TO BE EDITED**
  • h.264 – As you may have read from the above compression method, this actually was developed by Moving Picture Experts Group and is a part of mpeg-4. This video compression format has largely been accepted as the next predecessor to video. As of late, this format has become largely popular and is what I believe to be the most likely the most used in the fansub world. This compression method gives an outstanding video output even at low bitrates below 1MB/s and thus is used widely for HD streaming.
    * Special benefits – Currently supported by PSP, PS3, XBox360, PS4, WiiU, Wii, and many others
    * Disadvantages - Uses more CPU power to encode and decode (More power for stronger compression)


Video Standards
There were 3 video standards that were developed for the sake of broadcast television. Those three would be National Television System Committee(NTSC), Phase Alternating Line (PAL), and Séquentiel couleur avec mémoire (SECAM). NTSC and PAL the more commonly used systems. Although these were originally for analog systems and actually refer to color encoding and such into broadcast waves, these systems are now used mostly to identify standards of frame rate and frame size in digital videos, which are now much more popular. Currently, a new system is being developed, known as ATSC. This system will be used to broadcast high definition.

  • NTSC – This system was developed in North America and is used currently in the U.S., Canada, Mexico, Japan, South Korea, and some western countries of South America.
    *NTSC has a frame-rate of 23.976 Hz or 29.97 Hz.
  • PAL – This system was in Europe to take care of problems, particularly color hue. This system is used currently in most Europe, South-East Asia, Middle East, Southern and Eastern Africa, Brazil and Argentina.
    *PAL has a frame-rate of 25Hz.
  • SECAM – This system was developed in France and is used more heavily in Eastern Europe.
  • ATSC – This system is currently being developed and is said to replace North American and Canadian television broadcasts. This system is being developed particularly to support HDTV broadcasts. How this system works is yet to be announced.


Video bitrates
Bitrates are basically the amount of video information that the video gives out per second. You can find the average bitrate of a video by getting the size of the video and dividing the size in Kb(kilobits) by the number of seconds. You can find the size in kilobits by getting the size of the video in MB, multiplying that by 1024 to get kilobytes and then multiplying the kilobytes by 8 to get kilobits. Increasing the bitrate doesn’t necessarily always make the quality better, but it does increase the possibility of higher quality. However, higher bitrates mean higher file size, too. It's wise to have a Variable Bit Rate(VBR) than a Constant Bit Rate(CBR) as some parts of video are simple compared to other parts and thus you can save space by lowering the Bit Rate.

Motion estimation(ME)
Motion estimation compares macroblocks of a previous frame to macroblocks of the current frame.

  • Quarter Pixel (QPEL) – **TO BE EDITED**
  • Half Pixel – **TO BE EDITED**
  • Global Motion Compensation (GMC) – **TO BE EDITED**
  • Rate Distortion – **TO BE EDITED**


Quantization
Quantization is the most complex part of video compressing. This requires advanced knowledge and isn’t something a novice would want to try to mess with. Although, one may want to play around to try to find the perfect balance as quantization is something that directly effects the video quality, in a large way.

  • Luma – **TO BE EDITED**
  • Chroma – **TO BE EDITED**
  • Macroblocks - Macroblocks are a block of 16 by 16 pixels or sometimes smaller. The codec breaks apart each frame into macroblocks and works from there on each seperate macroblock. When the encoding is done badly, one sees each square of macroblock in each frame. Each Macroblock contains 3 pieces of informations: luminance(Y), blue color difference(cB), and red color difference(cR).
  • Multiple Math eXtension (MMX) – **TO BE EDITED**
    **NOTE: needs SSE
  • Trellis Search – **TO BE EDITED**
  • Blocking/de-blocking – **TO BE EDITED**
  • I-frames – I frames are also known as reference frames. These frames are necessary in any video encode as they are used to synch the video. I-frames hold all the data of the picture of a frame.
  • P-frames – P-frames are known as prediction frames. This frame only includes data of the difference between the previous and current frame. Such as if an object was moving and the background was the same, then the change in the object is the only thing saved into the frame.
  • B-frames – B-frames are known as Bi-predictive frames. This frame does the same thing as above, yet it saves even more data by only saving the changes from the previous AND next frames.


Encoding modes

  • Single pass – **TO BE EDITED**
  • Double pass – **TO BE EDITED**
  • Nth pass – **TO BE EDITED**



Other Stuff

  • advanced hexagon search – **TO BE EDITED**
  • FourCC – **TO BE EDITED**
  • Processing modes
    *Sum of Absolute Differences (SAD) – **TO BE EDITED**
    *Sum of Squared Differeneces (SSD) – **TO BE EDITED**
    *Single Instruction, Multiple Data (SSID) – **TO BE EDITED**
    *Streaming SIMD Extensions (SSE) – **TO BE EDITED**
    **NOTE: Supports MMX algorithm
Edited by JinK, Apr 28 2013, 04:37 PM.
Offline Profile Quote Post Goto Top
 
JinK

Audio Compression
There are multiple compression methods. Compressing a video will require more than just general knowledge of compression formats. For the sake of simplicity, this tutorial shall talk specifically about mp3, **TO BE EDITED** out of the countless others that there are.
mp3 – **TO BE EDITED**

Audio Sample Rates
8000Hz, 11025Hz, 16000Hz, 22050Hz, 44100Hz, 48000Hz **TO BE EDITED**

Audio bitrates
Just like for the video, bitrates for audio are basically the amount of audio data that’s given out per second. You can find the average bitrate of an audio by getting the total size of audio in kilobits and dividing it by the total time. You can find the kilobits by getting the size in MB and multiplying by 1024 to get Kilobytes and then further multiplying by 8 to get Kilobits. 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 and 384kbps are standard bitrates for audio.

Channel Encoding

  • Mono – **TO BE EDITED**
  • Joint Stereo – **TO BE EDITED**
  • Stereo – **TO BE EDITED**
  • Surround – **TO BE EDITED**


Other Stuff
**TO BE EDITED**
Edited by JinK, Aug 6 2009, 09:43 PM.
Offline Profile Quote Post Goto Top
 
JinK

Putting it all together
This is the part where most people are familiar with and also the easy part. First, you need a container. A container holds the video and audio in a format to be read. Some formats include mp4, mkv, ogg, ogm, rmvb, rm, avi, flv, wmv, mpg, mp4, and etc. Not all containers are compatible with all video/audio compression formats. Although there are countless formats, this tutorial shall concentrate on 3 formats: avi, mkv, and mp4


  • Audio Video Interleave (avi) – AVI files have long been used as THE standard of video containers. This format is made from microsoft and derives from Resource Interchange File Format or RIFF and basically just stores everything in chunks. AVI has been heavily embedded as a standard container but has problems like unable to have B-frames, no support for subtitles, and other compatibility issues.
    *Special benefits – AVI is capable of holding nearly all video codecs, except those with B-frames, notably h.264. AVI can also hold almost any audio codecs, except for vorbis.
    **NOTE: DON'T EVER try to combine avi with vorbis. May cause even windows explorer to restart constantly, in which one would have to use Command prompt to delete the file created.
  • Matroska (mkv) – Matroska means nesting doll for those that are curious. This format can virtually hold any codec and as many as you like. That is why this format is largely popular and is used ever more by fansubbers.
    *Special benefits – MKV is capable of holding nearly all video/audio codecs
  • mp4 – **TO BE EDITED**


Programs
Virtual Dub – **TO BE EDITED**
Media Coder – **TO BE EDITED**
AviDemux – **TO BE EDITED**
MeGUI – **TO BE EDITED**
Sony Vegas – **TO BE EDITED**
MP4Muxer – **TO BE EDITED**
Edited by JinK, Feb 27 2010, 10:23 PM.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
ZetaBoards - Free Forum Hosting
Free Forums with no limits on posts or members.
Learn More · Register for Free
« Previous Topic · Miscellaneous · Next Topic »
Add Reply