What is Lossy Compression?
Lossy compression reduces file size by irreversibly discarding information considered less important to perceived quality. Decompression produces an approximation rather than the exact original data.
How Lossy Compression works
A lossy encoder typically transforms samples into a representation in which perceptually less important detail can be isolated, quantizes that detail coarsely or drops it, and entropy-codes what remains. The quantization step discards precision that decoding cannot restore. JPEG illustrates the pattern: its DCT-based processes quantize frequency coefficients with a quantization table, the example tables in the standard are based on psychovisual thresholds, and encoders commonly also store color at lower resolution than brightness. Video encoders add rate control, which decides how much quantization each part of the picture receives; x265, for example, raises or lowers per-block quantization according to the complexity of the source. Because these decisions differ between codecs, encoders, and presets, results at the same nominal bitrate can look or sound different, so judge settings on your own content. Pipelines normally keep the highest-quality source available and create each delivery derivative from it, not from another derivative.
Key facts
- 1Decoding and re-encoding with a lossy encoder quantizes the data again and generally adds loss; reusing the earlier quality setting cannot bring back what was already discarded. Some operations avoid this by working on the coded data instead: libjpeg-turbo’s
jpegtran, for example, rotates or flips a JPEG by rearranging its coefficients without fully decoding the image, so the image data is transformed without degradation, which its manual contrasts with decoding and re-encoding. The manual also states the limits:jpegtrancannot change image quality, rotations and flips leave partial edge blocks untransformed when the dimension the transform depends on—the width for-flip horizontalor-rotate 270, the height for-flip verticalor-rotate 90, either one for-rotate 180—is not a multiple of the iMCU block size (usually 8 or 16 pixels), and dropping those blocks with-trimis not strictly lossless. - 2Quality numbers are encoder-specific and not interchangeable.
cjpeg -qualityruns from 0 (worst) to 100 (best) and scales quantization tables, while the x265--crfrate factor runs the other way: a higher value means more quantization and lower quality, and file size then depends on the complexity of the source. Compare encoders by inspecting or measuring their output, not by matching numbers. - 3The top of a quality scale is not necessarily lossless. For
cjpeg, quality 100 only minimizes loss in the quantization step; subsampling and round-off error still lose information. Exact reconstruction needs a lossless mode or format, and because some formats, such as WebP, offer both, a file extension does not tell you which was used. - 4Changing the container does not have to cost quality. FFmpeg’s stream copy (
-c copy) passes packets through without decoding or encoding, so there is no quality loss, but it can fail when the target container needs information the source lacks, and it cannot apply filters. Resizing is a filter, so a new video size means transcoding: decoding and encoding again, which FFmpeg’s documentation says degrades quality in most cases.
When Lossy Compression matters
Use lossy coding when bandwidth or storage savings justify some loss of image, audio, or video fidelity. Excessive settings or repeated recompression can create visible or audible artifacts.
How Transloadit helps with Lossy Compression
Transloadit exposes the lossy or lossless choice in its image Robots. /image/optimize uses only lossless PNG optimizers by default; setting lossy: true lets the lossy compressor pngquant compete as well, and the smallest result wins. /image/resize has a quality parameter that controls the compression of JPG and PNG output.
The lossy parameter affects PNG optimization only. The documentation warns that pngquant reduces PNGs to a 256-color palette, which may cause noticeable color shifts in images with rich color palettes, subtle gradients, or brand-specific colors.
Explore Transloadit’s file formats & compression capabilities
Sources
- MDN Glossary: Lossy compression
- ITU-T T.81 | ISO/IEC 10918-1: JPEG requirements and guidelines (DCT quantization, Annex K)
- libjpeg-turbo: cjpeg and djpeg usage (the -quality switch)
- libjpeg-turbo: jpegtran manual (lossless JPEG transformations)
- x265 documentation: command line options (CRF and adaptive quantization)
- FFmpeg documentation: ffmpeg tool (Streamcopy and Transcoding)