How do video compression algorithms work?

Modern video compression algorithms are not like the image compression algorithms that you are used to before. Adding size and time means different mathematical and logic techniques are applied to video files to reduce the size but still maintain the video quality.

This article has used H.264 as a prototype compression standard. Although it is no longer the latest video compression format, it is still a sufficiently detailed example to explain the main concepts of video compression.

Learn about the operation of video compression algorithms

  1. What is video compression?
  2. I-frame, P-frame and B-frame
  3. Intraframe encryption (I-frame)
  4. Interframe Prediction (P-frame and B-frame)

What is video compression?

Video compression algorithms search for time and excess space. By encrypting redundant data a minimum number of times, the file size can be reduced. For example, you need to compress a scene emphasizing the change of expression slowly on the face of the character, lasting for 1 minute. Compression doesn't mean to encode images on every frame, but instead, you can encode a frame, then refer to that encoded frame until the video changes. This interpersonal prediction coding is responsible for strange, unreliable components that appear during video compression: parts of the old image move incorrectly because there is some element in the encoding process. broken.

I-frame, P-frame and B-frame

How do video compression algorithms work? Picture 1

I-frame is a fully encoded image. Each I-frame contains all the data needed to represent an image. P-frame is predicted based on how to change the image from the last I-frame. B-frame is predicted in two dimensions, using data from both the last P-frame and the next I-frame. P-frame only needs to store unique image information for itself. In the above example, P-frame needs to keep track of how the dots move on the frame, and Pac-Man can retain its position.

The B-frame looks at the next P-frame, I-frame and average movement on those frames. The algorithm knows where the image starts (first I-frame) and ends (I-frame second) and it uses partial data for predictive coding, eliminating all static pixels that are not needed to create image

Intraframe encryption (I-frame)

How do video compression algorithms work? Picture 2

The I-frame is independently compressed, just like how static images are saved. Since the I-frame does not use predictive data, the compressed image contains all the data used to display the I-frame. I-frames are still compressed by an image compression algorithm like JPEG. This encoding usually takes place in the YCbCr color space, separates brightness data from color data, allows movement and changes in color coded separately.

For the non-predictive codec like DV and Motion JPEG, everything will stop there. Because there is no predictive frame, the only thing that can be done is to compress the image in a single frame. The method is less efficient but produces a higher quality raw (raw) file.

In codecs that use predictive frame as H.264, predictive frame is periodically displayed to refresh the data stream, by setting a new reference frame. The farther I-frames are, the smaller the video file. However, if I-frames are too far apart, the accuracy of the predictive frames in the video will gradually decrease to an incomprehensible level. A bandwidth-optimized application will insert as few I-frames as possible without breaking the video stream. The frequency of I-frames is usually determined indirectly by the 'quality' setting in the encryption software. Professional video compression software like ffmpeg allows clear control of this problem.

Interframe Prediction (P-frame and B-frame)

Video encoders trying to 'predict' change from one frame to the next. The more accurate the prediction of the encoder, the more efficient the compression algorithm. This is what creates P-frames and B-frames. The number, frequency and exact order of the predictive frame, as well as the specific algorithm used to encode and reproduce them, is determined by the specific algorithm you use.

How do video compression algorithms work? Picture 3

Consider how H.264 works. The frame is divided into sections called macroblocks, usually consisting of 16 x 16 samples. The algorithm does not encrypt raw pixel values ​​for each block (block). Instead, the encoder looks for a similar block in an old frame, called a reference frame. If a valid reference frame is found, the block will be encoded with a mathematical expression called a motion vector, describing the exact nature of the change from the reference block to the current block. When the video is played, the video player will interpret those motion vectors correctly to 'translate' the video. If the block doesn't change, no vector is needed.

How do video compression algorithms work? Picture 4

After the data is sorted into frames, it is encoded into a mathematical expression with a transform encoder. H.264 uses a DCT (discrete-cosine transform) to change the visual data into mathematical expressions (namely the sum of the cosine functions oscillating at different frequencies). The selected compression algorithm determines the variable encoder. Then the data is 'rounded' by the quantitative set. Finally, the bits are run through a lossless compression algorithm to shrink the file size again. This does not change the data. It only organizes data in the most compact form possible. After that, the video is compressed, smaller in size than before and ready to watch.

4.4 ★ | 5 Vote

May be interested

  • Greedy Algorithm (Greedy Algorithm)Greedy Algorithm (Greedy Algorithm)
    greedy algorithm is a combination optimization algorithm. search algorithms, select local optimal solutions in each step in the hope of finding a global optimal solution.
  • Alignment algorithm (Merge Sort)Alignment algorithm (Merge Sort)
    mixing (merge sort) is an arrangement algorithm based on the divide and conquer algorithm. with the worst case time complexity of Ο (n log n), this is one of the algorithms that deserves the most attention.
  • How to Shrink AVI FilesHow to Shrink AVI Files
    shrinking or compressing avi video files is done in order to upload them to a website or send them via email. the compression of avi video files can be done through video editing programs on either a pc or a mac. the process is quite easy...
  • 5 best video compression apps on Android5 best video compression apps on Android
    you may have been in a situation where you needed to share or backup large videos online. it could be a movie, a comedy skit or your baby's first steps.
  • Which file compression format is best?Which file compression format is best?
    it's time to compress some files, so which format do you use? zip, rar, 7z, or something else? this article has tested a number of tests to determine which format allows maximum compression.
  • What is Memory Compression in Windows?What is Memory Compression in Windows?
    memory compression is a feature that gives your ram more space to prevent it from filling up too quickly.
  • How to Compress VideoHow to Compress Video
    this wikihow teaches you how to lower a video file's size without sacrificing too much quality. compression is necessary if you want to share your videos on the internet because it reduces the amount of data that is needed to stream or...
  • Fix the video card error does not workFix the video card error does not work
    video card is an extension device connected to the computer's motherboard. it is used to create an image on the screen.
  • How to compress video size without installing softwareHow to compress video size without installing software
    reducing video size with online tools is very simple, as users do not need to install software to reduce video size and can use it immediately.
  • Reduce image size, how to compress images online for freeReduce image size, how to compress images online for free
    most compression tools either leave your images looking blurry or take forever to process. these little-known compression tools are fast, easy, surprisingly effective—and chances are you're not using them yet.