Introduction
JPEG XL (.jxl) represents the future of image compression, offering superior quality at reduced file sizes. Since version 5.1 (with full animation support added in late 2024/early 2025), FFmpeg natively integrates this format via the libjxl library.
This guide details the essential commands to leverage this modern codec for both static images and animations, including a dedicated section on lossless workflows.
Technical Prerequisites
Before starting, ensure your FFmpeg installation is compatible:
- Required Version: FFmpeg 6.0 or higher is recommended for stable animation support ( libjxl_anim ).
- Compilation: FFmpeg must be compiled with --enable-libjxl.
- Verification: Run
ffmpeg -codecs | grep jxl. You should see libjxl (static) and libjxl_anim (animation).
1. Encoding Static Images
Converting to JPEG XL significantly reduces PNG or JPG file sizes while preserving visual quality.
1.1 Standard Lossy Encoding
ffmpeg -i input.png -c:v libjxl output.jxl
-distance: Controls quality.1.0is default (high quality),0.5is near-perfect,15.0is lowest.-effort: Controls compression speed/size trade-off (1= fastest,9= slowest/smallest).
1.2 Lossless Encoding (Static)
For archival or pixel-perfect requirements, set -distance to 0. This forces the encoder into Modular mode, ensuring bit-exact reconstruction.
ffmpeg -i input.png -c:v libjxl -distance 0 -effort 9 output_lossless.jxl
-distance 0: Mandatory for true lossless compression.-effort 9: Highly recommended for lossless. Since quality is fixed, higher effort significantly reduces file size without any quality trade-off, though it increases encoding time.- Note: You can optionally add
-modular 1to force modular mode explicitly, though-distance 0does this automatically.
2. Decoding and Conversion
FFmpeg handles conversion from JPEG XL to standard formats seamlessly, preserving color space and bit depth.
ffmpeg -i image.jxl output.png
3. Creating JPEG XL Animations
Replace heavy GIFs with lightweight, high-color-depth animated JPEG XL files. This requires the libjxl_anim codec and the image2pipe format.
3.1 Standard Lossy Animation
ffmpeg -i video.mp4 -c:v libjxl_anim -f image2pipe -distance 0.5 -effort 5 animation.jxl
3.2 Lossless Encoding (Animation)
Creating a truly lossless animation (e.g., for screen recordings or pixel art) follows the same logic as static images but uses the animation codec.
ffmpeg -i source.mov -c:v libjxl_anim -f image2pipe -distance 0 -effort 9 animation_lossless.jxl
-distance 0: Ensures every frame is encoded without loss.-effort 9: Crucial for animations. Lossless video data is large; maximum effort provides the best compression ratio to keep file sizes manageable.-f image2pipe: Required to stream frames correctly into the single animated .jxl container.
Performance Tip: Lossless animation encoding is computationally intensive. Using -effort 9 may be slow for long videos. If speed is critical, -effort 7 offers a good compromise with minimal size increase.
4. Summary of Key Parameters
Parameter
Lossy Value
Lossless Value
Description
Codec
libjxl / libjxl_anim libjxl / libjxl_anim Select based on static vs. animated.Distance
0.5 – 1.0 0.0 0.0 triggers bit-exact lossless mode.Effort
4 – 7 9 Maximize effort (9) for best lossless compression.Format
(Optional) image2pipe Mandatory for animations.Conclusion
JPEG XL combined with FFmpeg offers a robust, future-proof alternative to GIF and WebP, delivering both high-efficiency lossy compression and true lossless capabilities in a single format.
FFmpeg Options Explanation
-distance: Controls the visual quality (fidelity) of the image.
0.0: Mathematically Lossless. The output is bit-for-bit identical to the input; no data is discarded.0.5: Near-Perfect. Higher quality than default; artifacts are virtually non-existent even under close inspection (often used for archival).1.0: Default. High quality; generally considered "visually lossless" for standard viewing (artifacts are imperceptible to the human eye).15.0: Lowest Quality. Maximum compression with visible artifacts and blurring.
-effort: Controls the compression speed vs. file size trade-off (how hard the encoder works).
1: Fastest. Minimal compression; largest file sizes. Ideal for quick previews or real-time encoding.4–5: Balanced. The default range; offers a good compromise between encoding speed and file size reduction.7: High Compression. Significantly smaller files with a noticeable increase in encoding time. Recommended for web delivery and archives where size matters.9: Slowest. Maximum compression; smallest possible file sizes. Encoding can be extremely slow. Best for "write-once, read-many" archival storage where file size is the only priority.
Note: Unlike -distance, increasing -effort never reduces quality; it only increases the time required to encode.
Regarding Alpha (Transparency): If your input image has transparency (like a PNG), JPEG XL preserves it automatically. There is a separate parameter, -alpha_distance, if you wish to compress the transparency channel differently from the color data, but -distance only affects the color/visual fidelity.