Dynamic Compression and Packaging of Images

DZone 's Guide to

Dynamic Compression and Packaging of Images

Minor variances in quality are not easily traceable via naked eyes. This article highlights an approach which compromises in quality to reduce file size and the images be grouped and packaged as a single file with common areas, unlike the usual file compression algorithms.

· Mobile Zone ·
Free Resource


Easy availability of high end cameras in smart phones puts immense pressure on storage space to store pictures / images of high resolutions. Normal users (who are non-professionals) also end up storing the images generated by device as is. In reality users are more inclined towards compromising a bit on the quality and save on storage space. 

This article aims to provide a way to achieve this goal. Minor variances in quality are not easily traceable via naked eyes. This article highlights an approach which compromises in quality to reduce file size and the images be grouped and packaged as a single file with common areas, unlike the usual file compression algorithms.


Smart phones with very high mega pixel camera are a common phenomenon in the current digital era.  These devices deliver images of huge sizes. With the ever growing need to store or share these images resulting in storage constraints, it becomes increasingly necessary to identify a tool or method to address the needs.  The optimized compressions tools available in the market fall well short in achieving the growing demands. 

One common approach is to reduce the dimension of the image to save space.  Some users use image compression tools to reduce the file size while preserving the dimension of the image.  This can be achieved by using technique called Spatial Compression. Spatial compression optimizes pixel storage by comparing the common areas within the image and compromise a bit on the quality.  The degree of loss can be customized to match the requirement or importance of that image.

The proposed method extends Spatial compression to the next level and tries not to compress just within the image but also across the images as a group. 

Videos employ Spatial and Temporal compression techniques to create an optimal video size and quality.  Video clips are treated as a sequence of images.  Now the video compression happens over these individual images and later on packaged as single file. The images in a video are referred to as frames. Videos have more sophisticated and a wide variety of options when it comes to compression.  Our method tries to capitalize video compression techniques to compress and pack images or albums.

Spatial Compression: A compression algorithm applied to a single frame of an video independently, where the video image is compressed much like aJPEG image would be compressed. It is an intra-frame compression technique, i.e. compress using the parameters within single image/frame. It performs compression reordering and removal of redundant information of the field value of pixels without losing texture of the image.

Temporal Compression: is a type of compression used by some codecs that assumes frames beside each other look similar. The first frame in the series would be entirely digitized (called a key frame). In the next frame only the information that has changed is digitized. Because temporal compression makes one frame depend on another it makes editing temporally compressed video difficult. It is an inter-frame compression, i.e. compress using the parameters across a group of images/frames. This technique compares images to perform reordering and removal of redundant information and provide a way to derive the individual images.

Dynamic Compression and Packaging Technique

Static Images

Images generated by high mega pixel cameras are of bigger dimension and translate to big sized files. Though the size of the image is also dependent on the format of the image product and other related parameter, we will assume some common formats and parameter to get the actual feel of the image sizes. Some sample image sizes generated by camera sensors and internally optimized are given below. This may vary depending on the compression used in smart phone.

Camera Sensor (Mega Pixels)

Static Image Size (MB)


~ 2.0


~ 2.5


~ 3.0


~ 3.5


~ 4.0


~ 6.0


~ 8.0


~ 16.0

Often images taken using smart phones are related. Because images taken during an occasion have more similarities in the content. For e.g. images taken in a marriage reception have the stage and other ambiance in common, like wise ones taken during a price distribution ceremony, those taken in a tourist spot with a scenic hills on the background, etc. Spatial compression works at its best when the commonalities are more.  However it can contribute even if there are no noticeable similarities, because the compression algorithms are matured for that purpose also to get the best out of least commonalities.

Video Insight

Video can be seen as a sequence of images often termed as frames. The compression of these images to get an optimal sized video is handled by video codecs.  There are algorithms well matured over years that can group the fragments inside the images and also across images and decides on the best logic to store the underlying pixel details of the images in a best possible way.  This results in producing very compact sized videos.  These algorithms goes one step further to apply techniques on how human eyes work in recognizing the scene in a static image.  With this it lets go off some minor details in the original image but the human eye cannot detect these loss easily.

In fact there are codecs that produces loss-less compression.  So there is nothing compromised and can preserve every pixel of the original static image.  There by giving us a possibility of professional grade quality even during compression and packaging of static images as videos.

Compression & Packaging

Media tools help us in creating video files from static images.  Video files can be created by including one or more static images. Tools like VLC and FFMPEG are open source tools and comes with a handful of video codec bundled within itself. These tools can be used to input the source static images and the required parameters to control the desired output video container format, the codec to be used for video stream and the variable for the compression algorithm. There are wrappers around FFMPEG and other media tools for compression and packaging available to be set in smart phones.

Using FFMPEG the video can be created from a set of static images using the below sample command.

ffmpeg -i image-%03d.png myalbumaward.mp4

Here the input static images are named in a series manner, like image-001.png, image-002.png, . . . . , image-015.png. The source images can be of different formats like jpg, bmp, etc.

Now the video.mp4 file will have the individual static images within itself as a sequence of frames. The generated mp4 file will be of much lesser size. This is because of the compressions we discussed above. This mp4 video file acts as a compressed package file for the source static images.  This file can be stored and transported across over the internet easily. When we desire to get the individual static images out of this video file, the same tool can be used decode and generate the images.

Using FFMPEG the individual static images can be created from the video file using the below sample command.

ffmpeg -i myalbumaward.mp4 image-%03d.png

Here the output static images will be named in a series manner, like image-001.png, image-002.png, . . . . , image-015.png. The output images can be of different formats like jpg, bmp, etc. Some of freely available video codecs are MPG, H264, WMV, FLV, Real Video, etc.

The H264 codec can be carefully manipulated to produce lose less compression.  But as one can expect the efficiency will be very little.

Process of packaging images to video and extracting images back from video is given in Fig: 1A

Image title

Fig: 1A

Application of Compression and Packaging

Using the method of dynamic compression and packaging of static images, storage and transfer of bulk images are easier and very much space/bandwidth/cost effective. This method is not restricted only for images from smart phones, but can be applied for images from laptops, TVs and tablets. Also, this comes handy when we need to store our media in cloud space.

Image title

Fig: 1B


The packaged video file will be of much smaller size when compared to the total source of the static images.  The efficiency is also given for a sample run. For instance a source jpg static images compressed to an mp4 video file resulted in using only 10% of the total sizes of the original static images.  This results is an efficiency of 90%.  The extracted image in a jpg format also resulted in near original quality.  Also note that there are lossless codec to provide exact original image pixels.

Given below are some sample tests run with around 5 images of size totaling around 10MB and default compression parameters.

Image title

Advantages Over Default Options

The dynamic compression and packaging is more suited without compromising the resolution and quality but gaining on the storage size.

Image title


This topic provided a technique to dynamically compress a group of static images and package them as a single video file.  The packaged video file holds together all the source images in a more compact size, making it easier for storage and transfer it over the network taking little space or bandwidth. It also provided the technique to extract out the images from the packaged video and have all the individual static images in a near to original quality.


VLC Command line Reference

FFMPEG Command line Reference

compression, image compression

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}