Skip to content

khavishbhundoo/Guetzli-mjpeg

Repository files navigation

Introduction

Motion JPEG (M-JPEG or MJPEG) is a video compression format in which each video frame or interlaced field of a digital video sequence is compressed separately as a JPEG image.The MJPEG video codec is mostly used in IP cameras and certain digital cameras.

Advantages of MJPEG

  • MJPEG video codec produces higher quality videos compared to codecs based on temporal interframe compression such as H.264.Temporal interface compressions codecs use sophisticated algorithms to apply compression across the video as a whole discarding data in the process.Compression schemes using interframe compression can often experience unacceptable quality loss when the video content changes significantly between each frame.

  • MJPEG is simple to implement as is non-proprietary and the variance from one manufacturer to the next is typically minimal.In comparison H.264 have many variants and its implementation differ from one manufacturer to the next.

  • Uses minimum computing power to encode and decode

Disadvantages of MJPEG

  • Videos produced with MJPEG are often huge in size compared to temporal interframe compression vodecs such as H.264.

Aim

This is an attempt to reduce the file size of MJPEG videos without affecting the perceived video quality.

Methodology

An MJPEG video comprises of a series of JPEG frames.Firstly we convert a sample high quality lossless image into JPEG images of various qualities with different encoders to determine at which quality there is no perceived quality loss and which decoder produces the smallest JPEG.

Butteraugli is a project that estimates the psychovisual similarity of two images. It gives a score for the images that is reliable in the domain of barely noticeable difference.

Guetzli is a JPEG encoder that aims for excellent compression density at high visual quality. Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg. Guetzli generates only sequential (nonprogressive) JPEGs due to faster decompression speeds they offer.

We need to achieve a butteraugli score of less than one to ensure that the visual quality isn't affected.

Decoder comparisions

Based on the data above , we can conclude that the following:

  • Regardless of the jpeg encoder used , quality 95 is the sweet spot where we get great quality with file size saving
  • Guetzli generates the smallest JPEG at a given quality
  • libjpeg-turbo generates slighly better JPEG than all other decoders.However at a quality setting of 95 its irrelevant as the perceived quality loss is not noticeable for all encoders.

An MJPEG lossless 25 frames per seconds(fps) video with a duration of 10 is created from the generated JPEG.

The following videos are then created

Original Video : Consist of JPEG frames generated at a quality of 100 with libjpeg

Original Optimized Video : Consist of JPEG frames generated at a quality of 95 with libjpeg

Guetzli Optimized Video : Consist of JPEG frames generated at a quality of 95 with Guetzli

The ffmpeg command used to generate the videos is as follows:

ffmpeg -f image2 -s 444x258 -framerate 25 -i bees%01d.jpg -codec copy video.mp4

-f image2 --> tells ffmpeg to select a group of images

-s 444x258 --> the resolution of the video

-framerate 25 --> set the framerate to 25(default).The framerate of a video encoded by ffmpeg is 25 by default.This option is here just for completeness

-codec copy --> tells ffmpeg to not encode the JPEG again due to generation loss

video.mp4 --> name of generated video

Results

Results

Conclusion

We managed to reduce the file size of MJPEG videos by up to 74% without any noticeable visual quality loss.At the time of this writing , it might not be practical to use guetzli as the de-facto JPEG encoder due to performance issues.Nevertheless significant file savings , around 62% in our case , have been obtained even with a standard decoder like libjpeg.Guetzli can be use in situations where sufficient resource is available or when processing time is not an issue (i.e for archiving purposes).

In situations where minimal quality loss is acceptable(i.e anything except IP cameras) , the file size of MJPEG videos can still be reduced.

Guetzli Optimized Video(90) : Consist of JPEG frames generated at a quality of 90 with Guetzli

Video90

Here is a side by side comparision of Guetzli optimized MJPEG videos SideBySide

References

https://github.com/google/butteraugli

https://github.com/google/guetzli

Authors

Jyrki Alakuijala ( @jyrkialakuijala )

Khavish Anshudass Bhundoo

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published