Last updated: May 29, 2024

<span aria-hidden="true" id="optimizing-video-quality-with-advanced-compression"></span>

# Optimizing video quality with advanced compression

![Joseph Grabski](/assets/images/teammates/joseph2.png?dpl=dpl_3fBRD5jmFtSDABLXGJJyXU1nVXf8)

**Joseph Grabski**

Content Lead · Rochester, United Kingdom · Show bio

[](https://x.com/joe%5Fgrabski)[](https://github.com/Missing-Tech)

As the digital world expands, video compression plays a vital role in optimizing video storage and transmission for streaming, social media, and multimedia apps. In this post, we explore various video compression techniques and how they help reduce file sizes while maintaining acceptable video quality.

![A pastel banner with the text 'Video Compression'. Different colored abstract shapes are in the background](/_next/static/immutable/media/opengraph-image.0urwrbzx-4036.png)

<span aria-hidden="true" id="lossy-vs-lossless-compression"></span>

## Lossy vs. Lossless compression

There are two main types of video compression: lossy and lossless. Lossy compression discards some of the original data, resulting in a smaller file size and a slight loss in video quality. Examples of lossy video codecs include [H.264 (AVC)⁠](https://en.wikipedia.org/wiki/Advanced%5FVideo%5FCoding),[H.265 (HEVC)⁠](https://en.wikipedia.org/wiki/High%5FEfficiency%5FVideo%5FCoding?useskin=vector),[VP9⁠](https://en.wikipedia.org/wiki/VP9?useskin=vector) and[AV1⁠](https://en.wikipedia.org/wiki/AV1). In contrast, lossless compression preserves all the original data, maintaining video quality at the cost of larger file sizes. Lossless codecs include[HuffYUV⁠](https://en.wikipedia.org/wiki/Huffyuv?useskin=vector) and[Lagarith⁠](https://en.wikipedia.org/wiki/Lagarith?useskin=vector).

**Note**

Depending on the number of times a video is viewed, machines have to exert a disproportional amount of effort to encode a file in order to get savings over today's popular codecs. For that reason, Transloadit only offers AV1 encoding to[Enterprise tier](/pricing.md) customers upon request.

Let's explore some of the differences between these codecs:

* **H.264 (Advanced Video Coding)**: One of the most widely used video codecs, H.264 provides efficient video compression with good video quality. It supports a wide range of resolutions, making it suitable for various applications, from mobile devices to high-definition television.
* **H.265 (High-Efficiency Video Coding)**: A successor to H.264, H.265 offers improved compression efficiency and supports higher resolutions such as 4K and 8K. The trade-off is that it requires more processing power, making it less suitable for low-end devices.
* **VP9**: An open-source video codec developed by Google that offers similar compression efficiency to H.265. It is commonly used for streaming videos on platforms such as YouTube.\
  To make WebM sources easier to play across browsers and devices, try our live[WebM to MP4 converter](/demos/video-encoding/webm-to-mp4.md).
* **AV1 (AOMedia Video 1)**: A next-gen open-source video codec with improved compression efficiency and high video quality. It supports up to 8K resolution, optimized for both hardware and software decoding. AV1 is ideal for streaming video on platforms like Netflix and YouTube.
* **HuffYUV**: provides fast encoding and decoding, making it ideal for applications that require high-speed processing, such as video editing. It offers excellent compression for simple video content, but is less effective for complex video content. HuffYUV is commonly used for intermediate storage or editing.
* **Lagarith**: offers very good compression for both simple and complex video content, and is designed to be fast for encoding and decoding. Lagarith is commonly used for capturing and archiving video footage.

<span aria-hidden="true" id="spatial-and-temporal-compression"></span>

## Spatial and temporal compression

Video compression techniques can be divided into two categories: spatial and temporal.

Spatial compression reduces redundancy within individual video frames by removing unnecessary data while preserving the essential elements. Techniques such as[\_discrete cosine transform (DCT)\_⁠](https://en.wikipedia.org/wiki/Discrete%5Fcosine%5Ftransform) and[\_wavelet transform\_⁠](https://en.wikipedia.org/wiki/Wavelet%5Ftransform) help achieve this by transforming pixel values into *frequency domain coefficients*, which can then be quantized and encoded.

Temporal compression, on the other hand, reduces redundancy between consecutive frames in a video sequence. Techniques like [\_motion estimation\_⁠](https://en.wikipedia.org/wiki/Motion%5Festimation) and[\_motion compensation\_⁠](https://en.wikipedia.org/wiki/Motion%5Fcompensation) exploit similarities between frames to minimize the amount of data required to represent the video.

<span aria-hidden="true" id="hevc-encoding-demo"></span>

## HEVC encoding demo

Transloadit offers many different [encoding presets](/docs/presets/video.md) for you to take advantage of. In the demo below, we use the[/video/encode](/docs/robots/video-encode.md) Robot to automatically transcode a video file into the HEVC video codec. We then export this file to S3 for later retrieval. For more information on how to set up S3, check out our[Setting up S3 for Transloadit⁠](http://localhost:3001/blog/2023/03/setting-up-s3-for-transloadit/)blog post.

```
<!-- This pulls Uppy from our CDN -->
<!-- For smaller self-hosted bundles, install Uppy and plugins manually: -->
<!-- npm i --save @uppy/core @uppy/dashboard @uppy/remote-sources @uppy/transloadit ... -->
<link
  href="https://releases.transloadit.com/uppy/v3.10.0/uppy.min.css"
  rel="stylesheet"
/>
<button id="browse">Select Files</button>
<script type="module">
  import {
    Uppy,
    Dashboard,
    ImageEditor,
    RemoteSources,
    Transloadit,
  } from 'https://releases.transloadit.com/uppy/v3.10.0/uppy.min.mjs'
  const uppy = new Uppy()
    .use(Transloadit, {
      waitForEncoding: true,
      alwaysRunAssembly: true,
      assemblyOptions: {
        params: {
          // It's often better store encoding instructions in your account
          // and use a `template_id` instead of adding these steps inline
          steps: {
            ':original': {
              robot: '/upload/handle',
            },
            hevc_encoded: {
              use: ':original',
              robot: '/video/encode',
              result: true,
              ffmpeg_stack: 'v7',
              preset: 'hevc',
              turbo: true,
            },
            exported: {
              use: ['hevc_encoded', ':original'],
              robot: '/s3/store',
              credentials: 'demo_s3_credentials',
              url_prefix: 'https://demos.transloadit.com/',
            },
          },
        },
      },
    })
    .use(Dashboard, { trigger: '#browse' })
    .use(ImageEditor, { target: Dashboard })
    .use(RemoteSources, {
      companionUrl: 'https://api2.transloadit.com/companion',
    })
    .on('complete', ({ transloadit }) => {
      // Due to `waitForEncoding:true` this is fired after encoding is done.
      // Alternatively, set `waitForEncoding` to `false` and provide a `notify_url`
      console.log(transloadit) // Array of Assembly Statuses
      for (const assembly of transloadit) {
        console.log(assembly.results) // Array of all encoding results
      }
    })
    .on('error', (error) => {
      console.error(error)
    })
</script>

```

[Read docs](/docs/sdks/uppy.md)

If a preset doesn't offer the exact encoding preset you are looking for, you can also consider using[custom FFmpeg options](/docs/robots/video-encode.md#ffmpeg-parameters-video-encode)in order to fine-tune the encoding to your specific needs.

<span aria-hidden="true" id="conclusion"></span>

## Conclusion

Video compression techniques play a crucial role in managing the size and quality of digital video files. By understanding the different methods and codecs available, content creators and developers can make informed decisions about which compression method best suits their needs. As video resolutions continue to increase and demand for video content grows, efficiency of video compression will only become more important in the years to come.

At Transloadit, we understand the importance of efficient video compression and deliver high-quality video content to your audience. Our powerful video encoding API allows you to effortlessly implement various video codecs and compression techniques into your workflow. With a wide range of customization options and support for adaptive streaming, we ensure that your videos are optimized for the best possible user experience across different devices and network conditions. As technology evolves, Transloadit will continue to stay at the forefront of video compression innovations, offering you cutting-edge solutions tailored to your needs.

[#video-encoding-service](/blog/tags/video-encoding-service.md)[#comparison](/blog/tags/comparison.md)[#video-encode-robot](/blog/tags/video-encode-robot.md)

### 👩‍💻 Join 20k+ developers

Sign up for our [monthly newsletter](/newsletters.md) to receive direct links to 3 exclusive tech — and 2 product updates. No less, no more.

Your email:

Get access

## File uploading and encoding. Made simple.

Transloadit streamlines file handling for developers, trusted by brands like Coursera and The New York Times. We’re known for a reliable API, top-notch support, and a strong commitment to open source, with projects like [Uppy⁠](https://uppy.io) and [Tus⁠](https://tus.io) setting standards in file processing.

[Sign up](/c/)[Book a Demo](https://survey.typeform.com/to/kRg47Xi5)

No credit card needed · 5 GB included in the free plan

Cancel anytime
