What is Video Compression? How does it work?
Tags: webdev, javascript, devops, beginners
Published: 2024-06-24 19:56:26

Video compression is the process of reducing the file size of a video without significantly reducing its quality.

It reduces the size of the data that is required for video files. The video compression tries to reduce the file size without compromising on reduction in quality of the video

Video compression does this by removing redunded and non essential data from video files.

thus making them smaller in size without significantly reducing the quality

## **Types of Video Compression**

There are broadly two types of video compression. Each method has its own use case and advantage and disadvantages depending on what is the desired quality, file size and other aspects

Understanding these two types of video compression is important if you are working with video files compression

### **Lossy Compression**

* What it is
    

Lossy Compression as the word implies is type of video compression that leads to a loss in the quality of video

Here what is get in return to the loss of video quality is the great reduction in file size of the video

This is used in applications where reduction in data quality is acceptable, it is used by streaming service providers to reduce bandwidth and CPU usage on their end

#### **How it works**

Lossy compression works by simplifying the data by various means such as

* reducing the resolution of the video for example from 4k to 1080p video.
    
* Altering the sub sampling of colors
    
* Consolidating similar data points into a single average that approximates the original data
    

#### **Advantages**

The main advantage of lossey compression is that it greatly reduces the file size of the video.

This makes it easier to store and transmit the video over the internet

#### **Disadvantages**

The main drawback is that the quality of the video is diminished, the more lossey the compression is the smaller is the file size and worse is the quality of video

### **Lossless Compression**

Lossless compression on the other hand aloows for the orignal data to be reconstructed from the compressed data

This method is essential in situations where you need high quality video such as premium streaming providers, Blue ray disks, or medical imaging etc

#### **How it works**

lossless compression identifies and eliminates statistical  redundencies without affecting the content, often using different algorithms that encode data more efficiently than video formats

#### **Advantages**

There is no loss in quality is the main advatage.

#### **Disadvantages**

The compression ratio is much lower than lossey compression thus the file size is reduced but not by much.

This means that the file sizes are much larger as compared to lossey compression.

When streaming files over the internet you need high bandwidth and cpu  capacity in order to stream the video and greater disk space to store the c video, but the video is of high quality

## **Popular Video Compression Algorithms and Standards**

Several algorithms and standards are available to compress video, these algorithms are designed with different use cases and each compress video under different contraints

like some reduces the resoulution and other reduce audio quality etc.

### **H.264 (Advanced Video codec, AVC)**

this compression algorithm was introduced in 2003, H.264 is one of the most highly used video coded because it delivers good video quality with  small file size, thus giving a balance between video quality and compression

Technology: The H.264 codec uses motion compensation and spatial prediction to achieve a level of high compression ratio with good quality video

Usage: H.264 is compatible with almost all platfroms and devices today, thus it is highly versatile and can be used for both high defination and standard defination video compression

### **H.265 (High Efficiency Video Coding, HVEC)**

It is a successor to the H.264, the H.265 delivers video quality that is similar to the H.264 but with smaller file size.

It delivers upto 50% percent reduction in file size, which is a good thing since video quality is getting bigger and bigger

Technology: The H.265 uses improved methods of coding blocks, motion vectors and improved spatial reduction to reduce the file size of the video

The H.265 has high computational requirements, but because it reduces the file much more and without significant loss in quality it is being widely used in the industry.

It has only one time computational requirement during compression, computational power has also become much cheaper with time.

### **VP9**

The VP9 protocol was developed by google, it is an open source and royalty free codec that has been designed with web video in mind

This codec priomarily competes with H.265

Technology: The VP9 is best at reducing the bitrate needed for high quality video, which is good for YouTube Video where there is a need for bandwidth optimization

Usage: VP9 was developed by google for web based video

## **Key Concepts in Video Compression**

### **Bitrate**

Bitrate is the amount of data that is processed per unit of time in a video file.

This data is measured in Mbps that is Megabits of data per second. Bitrate is a determinant of file size that is streaming.

A higher bitrate could mean a greater resolution video that is, all things being equal a 4k video would have a greater bitrate that 1080p, which in turn would have a greater bitrate that 720p video.

Compression techniques can reduce the bitrate while attempting to maintain as much as original quality as possible

### **Resolution**

Resolution indicates the number of pixels that can be displayed, more pixels can be a bigger video or a crisper video.

Higher resolution means more detail and clearer images the downside is that mor processing power is required to play the video and more storage space is required to store the video and more bandwidth is required to stream the video over the internet

### **Frame Rate**

A video is made up of multiple still images that are consicutive in nature and appear very fast so as to create an illusion that the images are moving and thus creates a video

the frequency at which these images appear is called as frame rate. The more the frame rate the more images are appear in a given amount of time

for example: a 24 fps video would render 24 images per second and a 60 fps video would render 60 images / frames per seconds

The better the frame rate the smoother the video and crisper the image quality. Also, more frame rate require a larger file size for the video and higher cpu and bandwidth requirements to stream and display the video

## **Encoding (Compression) and Decoding (Decompression) Video**

Encoding (Compression)

The encoding is the process of converting raw video into compressed format.

### **Temporal Compression**

The encoder looks at multiple frames to find areas in the video that do not change much and compresses these areas more efficiently.

Techniques like the motion estimator predicts the motion from one frame to another and only stores the difference between frames and not the entire frame

### **Spatial Compression**

Here the encodor looks across multiple images and sees parts of the image that are similar and compresses them by reducing detail.

This is often done using or transforming the spatial domain data into a frequency domain data using mathematical transformations like Discrete Cosine transform (DCT) .

The resulting data often contains  many low values and zeros which can be eliminated and the data compressed more efficiently

### **Quantization**

This compression techniques significantly reduces the amount of data by approximating the transformed coeffients to a lower precision.

While the quantization effectively reduces the file size. It also reduces the quality significantly and also creates compression artifacts.

### **Entropy Coding**

Encoder uses coding algorithms such as the Huffman coding or the Arithematic coding to further compress the video by removing statistical redundencies, encoding frequently occuring patterns with shorter codes.

## **Decoding (Decompression)**

Decoding is the reverse process of encoding

### **Entropy decoding**

The decodier basically processes the compressed data stream to expand it back to its original state

### **Inverse Quantization**

This step reverses the quantized state to its approximate orignal data by a process called inverse quantization

### **Reconstruction**

Motion vactors and temporal data is used to reconstruct the full video sequence.

This process fills in data between keyframes where only changes where stored during compression process.

## **Importance of Video Compression in Digital Media**

here are some of the ways in which video compression is important in digital media

### **Efficiency in Storage**

High defination video files are large files and these file can consume valuable hard disk space.

For Example a single 1080p uncompressed file can consume upto 100GB in space

Compression algoritms can reduce this space usage without compromising much on quality by upto 90% which is great

This makes it easy to store the files on servers and on computer hard disks

### **Bandwidth management**

Streaming video requires a lot of bandwidth, this is important perticularly when you are streaming high defination video.

Many people also stream on mobile devices which inherently do not have a lot of bandwidth

With compresssion the amount of data being transmitted is reduced significantly which in turn reduces bandwidth consumti0n

This makes streaming smoother for end user and also saves money to the streaming service and the internet service provider as well.

### **Cost Effectiveness**

Reducing the size of the video helps in storage as well as transmission of video files over the internet

This in turn saves money for the businesses operating in this field such as streaming service providers like Netflix or YouTube, internet service providers

### **Scalability**

As the demand for video content is growing, video compression has become essential so as to scale to millions of users

It allows platforms to host milllions of users with streaming more videos and audio and even allow users to stream content with limited internet speed.


![Metered TURN Servers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdkpxuhfp5y77v3l1vpq.png)


## [**Metered TURN servers**](https://www.metered.ca/stun-turn)

1. **API**[**:**](https://www.metered.ca/stun-turn) TURN server management with powerful API. You can do things like Add/ Remove credentials via the API, Retrieve Per User / Credentials and User metrics via the API, Enable/ Disable credentials via the API, Retrive Usage data by date via the API.
    
2. **Global Geo-Location targeting:** Automatically directs traffic to the nearest servers, for lowest possible latency and highest quality performance. less than 50 ms latency anywhere around the world
    
3. **Servers in all the Regions of the world:** Toronto, Miami, San Francisco, Amsterdam, London, Frankfurt, Bangalore, Singapore,Sydney, Seoul, Dallas, New York
    
4. **Low Latency:** less than 50 ms latency, anywhere across the world.
    
5. **Cost-Effective:** pay-as-you-go pricing with bandwidth and volume discounts available.
    
6. **Easy Administration:** Get usage logs, emails when accounts reach threshold limits, billing records and email and phone support.
    
7. **Standards Compliant:** Conforms to RFCs 5389, 5769, 5780, 5766, 6062, 6156, 5245, 5768, 6336, 6544, 5928 over UDP, TCP, TLS, and DTLS.
    
8. **Multi‑Tenancy:** Create multiple credentials and separate the usage by customer, or different apps. Get Usage logs, billing records and threshold alerts.
    
9. **Enterprise Reliability:** 99.999% Uptime with SLA.
    
10. **Enterprise Scale:** With no limit on concurrent traffic or total traffic. Metered TURN Servers provide Enterprise Scalability
    
11. **5 GB/mo Free:** Get 5 GB every month free TURN server usage with the Free Plan
    
12. Runs on port 80 and 443
    
13. Support TURNS + SSL to allow connections through deep packet inspection firewalls.
    
14. Supports both TCP and UDP
    
15. Free Unlimited STUN