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.
Guetzli is an awesome jpeg encoder, however, it works a little bit slow. In order to speed it up, we have added CUDA & OpenCL support for Guetzli, optimized some procedure and added full jpeg format support. We tested it on our GPU server(single Tesla M40 GPU), and the test result with one of our sample pictures(750*400 in size) is as below.
Method | Usage | Cost |
---|---|---|
Original | guetzli \ |
14.7s |
Procedure Optimized | guetzli --c \ |
8.2s |
Using OpenCL | guetzli --opencl \ |
1.5s |
Using CUDA | guetzli --cuda \ |
0.8s |
Check the 'Extra features' section to see how to enable CUDA or OpenCL.
apt-get install libpng-dev
.dnf install libpng-devel
. pacman -S libpng
.apk add libpng-dev
.make
and expect the binary to be created in bin/Release/guetzli
.libpng
using vcpkg: .\vcpkg install libpng:x64-windows-static
.libpng
using vcpkg: vcpkg install tiff:x64-windows-static
..\vcpkg integrate install
. If you prefer not to do this, refer to vcpkg's
documentation.To install using Homebrew:
brew install guetzli
To install using the repository:
libpng
bin/Release/guetzli
.
There's also a Bazel build configuration provided. If you
have Bazel installed, you can also compile Guetzli by running bazel build -c opt //:guetzli
.
Note: Guetzli uses a large amount of memory. You should provide 300MB of memory per 1MPix of the input image.
Note: Guetzli uses a significant amount of CPU time. You should count on using about 1 minute of CPU per 1 MPix of input image.
Note: Guetzli assumes that input is in sRGB profile with a gamma of 2.2. Guetzli will ignore any color-profile metadata in the image.
To try out Guetzli you need to build or download the Guetzli binary. The binary reads a PNG or JPEG or TIFF image and creates an optimized JPEG image:
guetzli [--quality Q] [--verbose] original.png output.jpg
guetzli [--quality Q] [--verbose] original.jpg output.jpg
guetzli [--quality Q] [--verbose] original.tiff output.jpg
Note that Guetzli is designed to work on high quality images. You should always prefer providing uncompressed input images (e.g. that haven't been already compressed with any JPEG encoders, including Guetzli). While it will work on other images too, results will be poorer. You can try compressing an enclosed sample high quality image.
You can pass a --quality Q
parameter to set quality in units equivalent to
libjpeg quality. You can also pass a --verbose
flag to see a trace of encoding
attempts made.
Please note that JPEG images do not support alpha channel (transparency). If the input is a PNG with an alpha channel, it will be overlaid on black background before encoding.
Note: Please make sure that you can build guetzli successfully before adding the following features.
Note: Before adding CUDA support, please check whether your GPU support CUDA or not.
Note: If you don't have an NVIDIA card that support CUDA, you can try OpenCL instead. You can install any of the OpenCL SDKs, such as Intel OpenCL SDK, AMD OpenCL SDK, etc.
Note: The steps for adding OpenCL support is very similar with adding CUDA support, so the following introduction will be only for CUDA.
premake5.lua
, add $(CUDA_PATH)\include
to includedirs under workspace "guetzli", add defines { "__USE_CUDA__" }
and links { "cuda" }
under filter "action:gmake"
. Then do premake5 --os=linux gmake
to update the makefile.clguetzli/clguetzli.cl
and add #define __USE_CUDA__
at first line.make
and wait the binary to be created in bin/Release/guetzli
../compile.sh 64
or ./compile.sh 32
to build the 64 or 32 bits ptx file, and the ptx file will be copied to bin/Release/clguetzli
.CUDA Toolkit
.<vs2015 dir>\VC\bin\amd64\vcvars64.bat
to <guetzli dir>\vcvars64.bat
.Property Pages
as follows:
__USE_CUDA__
to preprocessor definitions.cuda.lib
to additional dependencies.$(CUDA_PATH)\include
to include directories.$(CUDA_PATH)\lib\Win32
or $(CUDA_PATH)\lib\x64
to library directories.clguetzli/clguetzli.cl
and add #define __USE_CUDA__
at first line.premake5.lua
, add $(OPENCL_SDK_PATH)\include
to includedirs under workspace "guetzli", add defines { "__USE_OPENCL__" }
and links { "**" }
under filter "action:gmake"
. Then execute premake5 --os=linux gmake
to update the makefile.clguetzli/clguetzli.cl
and add #define __USE_OPENCL__
at first line.make
and wait the binary to be created in bin/Release/guetzli
.clguetzli/clguetzli.cl
to bin/Release/clguetzli
before running.Intel OpenCL SDK
.<vs2015 dir>\VC\bin\amd64\vcvars64.bat
as <guetzli dir>\vcvars64.bat
Property Pages
as follows:
__USE_OPENCL__
to preprocessor definitions.OpenCL.lib
to additional dependencies.$(OPENCL_SDK_PATH)\include
to include directories.$(OPENCL_SDK_PATH)\lib\x86
or $(OPENCL_SDK_PATH)\lib\x64
to library directories.clguetzli/clguetzli.cl
and add #define __USE_OPENCL__
at first line.Property Pages
to turn on the Excluded From Build
property of clguetzli/clguetzli.cu
.links { ** }
under filter "action:gmake"
. Then execute premake5 --os=linux gmake
to update the makefile.guetzli [--c|--cuda|--opencl] [other options] original.png output.jpg
guetzli [--c|--cuda|--opencl] [other options] original.jpg output.jpg
guetzli [--c|--cuda|--opencl] [other options] original.tiff output.jpg
You can pass a --c
parameter to enable the procedure optimization or --cuda
parameter to use the CUDA acceleration or --opencl
to use the OpenCL acceleration.
If you have any question about CUDA/OpenCL support, please contact strongtu@tencent.com, ianhuang@tencent.com, chriskzhou@tencent.com or stephendeng@tencent.com.
apt-get install libjpeg8-dev
.dnf install libjpeg-devel
. pacman -S libjpeg
.apk add libjpeg
.premake5.lua
, add defines {"__SUPPORT_FULL_JPEG__"}
and links { "jpeg" }
under filter "action:gmake"
. Then do premake5 --os=linux gmake
to update the makefile.make
and wait the binary to be created in bin/Release/guetzli
libjpeg-turbo
using vcpkg: .\vcpkg install libjpeg-turbo:x64-windows-static
__SUPPORT_FULL_JPEG__
to preprocessor definitions in the project Property Pages
.