Name
cwebp
- compress an image file to a WebP file
Synopsis
cwebp [options] input_file -o output_file.webp
Description
This page documents the cwebp
command.
cwebp
compresses image using the WebP format. Input format can
be either PNG, JPEG, TIFF or raw Y'CbCr samples.
Options
The basic options are
-o string
- Specify the name of the output WebP file. If omitted,
cwebp
will perform compression but only report statistics.
-h, -help
- A short usage summary.
-H, -longhelp
- A summary of all the possible options.
-version
- Print the version number (as major.minor.revision) and exit.
-q float
- Specify the compression factor between 0 and 100. A small factor produces smaller file with lower quality. Best quality is achieved using a value of 100. The default is 75.
-alpha_q int
- Specify the compression factor for alpha compression between 0 and 100. Lossless compression of alpha is achieved using a value of 100, while the lower values result in a lossy compression. The default is 100.
-f int
- Specify the strength of the deblocking filter, between 0 (no filtering) and 100 (maximum filtering). A value of 0 will turn off any filtering. Higher value will increase the strength of the filtering process applied after decoding the picture. The higher the smoother the picture will appear. Typical values are usually in the range of 20 to 50.
-preset string
- Specify a set of pre-defined parameters to suit a particular type of
source material. Possible values are:
default, photo, picture, drawing, icon, text
. Since-preset
overwrites the other parameters' values (except the-q
one), this option should preferably appear first in the order of the arguments.
-sns int
- Specify the amplitude of the spatial noise shaping. Spatial noise shaping (or sns for short) refers to a general collection of built-in algorithms used to decide which area of the picture should use relatively less bits, and where else to better transfer these bits. The possible range goes from 0 (algorithm is off) to 100 (the maximal effect). The default value is 80.
-m int
- Specify the compression method to use. This parameter controls the tradeoff between encoding speed and the compressed file size and quality. Possible values range from 0 to 6. Default value is 4. When higher values are used, the encoder will spend more time inspecting additional encoding possibilities and decide on the quality gain. Lower value can result is faster processing time at the expense of larger filesize and lower compression quality.
-af
- Turns auto-filter on. This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality.
Additional options
More advanced options are:
-sharpness int
- Specify the sharpness of the filtering (if used). Range is 0 (sharpest) to 7 (least sharp). This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality.
-strong
- Use a stronger filtering than the default one (if filtering is
being used thanks to the
-f
option). Strong filtering is off by default.
-segments int
- Change the number of partitions to use during the segmentation of the sns algorithm. Segments should be in range 1 to 4. Default value is 4.
-partition_limit int
- Degrade quality by limiting the number of bits used by some
macroblocks. Range is 0 (no degradation, the default) to 100 (full degradation).
Useful values are usually around 30-70 for moderately large images.
In the VP8 format, the so-called control partition has a limit of 512k and is
used to store the following information: whether the macroblock is skipped,
which segment it belongs to, whether it is coded as intra 4x4 or intra 16x16
mode, and finally the prediction modes to use for each of the sub-blocks. For a
very large image, 512k only leaves room to few bits per 16x16 macroblock.
The absolute minimum is 4 bits per macroblock. Skip, segment, and mode
information can use up almost all these 4 bits (although the case is unlikely),
which is problematic for very large images. The partition_limit factor controls
how frequently the most bit-costly mode (intra 4x4) will be used. This is useful
in case the 512k limit is reached and the following message is displayed:
Error code: 6
(PARTITION0_OVERFLOW: Partition #0 is too big to fit 512k). If using-partition_limit
is not enough to meet the 512k constraint, one should use less segments in order to save more header bits per macroblock. See the-segments
option.
-size int
- Specify a target size (in bytes) to try and reach for the compressed output. Compressor will make several passes of partial encoding in order to get as close as possible to this target.
-psnr float
- Specify a target PSNR (in dB) to try and reach for the compressed output. Compressor will make several passes of partial encoding in order to get as close as possible to this target.
-pass int
- Set a maximum number of passes to use during the dichotomy used by
options
-size
or-psnr
. Maximum value is 10.
-crop x_position y_position width height
- Crop the source to a rectangle with top-left corner at coordinates
(
x_position, y_position
) and sizewidth x height
. This cropping area must be fully contained within the source rectangle.
-s width height
- Specify that the input file actually consists of raw Y'CbCr samples
following the ITU-R BT.601 recommendation, in 4:2:0 linear format. The
luma plane has size
width x height
.
-map int
- Output additional ASCII-map of encoding information. Possible map values range from 1 to 6. This is only meant to help debugging.
-pre int
- Specify a pre-processing filter. This option is a placeholder and has currently no effect.
-alpha_filter string
- Specify the predictive filtering method for alpha plane. One of 'none', 'fast' or 'best', in increasing complexity and slowness order. Default is 'fast'. Internally, alpha filtering is performed using four possible predictions (none, horizontal, vertical, gradient). The 'best' mode will try each modes in turn and pick the one which gives the smaller size. The 'fast' mode will just try to form an a-priori guess without testing all modes.
-alpha_method int
- Specify a algorithm used for alpha compression: 0 or 1. Algorithm 0 denotes no compression, 1 uses WebP lossless format for compression. The default is 1.
-alpha_cleanup
- Modify unseen RGB values under fully transparent area, to help compressibility. The default is off.
-noalpha
- Using this option will discard the alpha channel.
-lossless
- Encode the image without any loss.
-hint string
- Specify the hint about input image type. Possible values are:
photo
,picture
orgraph
.
-v
- Print extra information (encoding time in particular).
-print_psnr
- Compute and report average PSNR (Peak-Signal-To-Noise ratio).
-print_ssim
- Compute and report average SSIM (structural similarity metric).
-progress
- Report encoding progress in percent.
-quiet
- Do not print anything.
-short
- Only print brief information (output file size and PSNR) for testing purposes.
Examples
cwebp -q 50 -lossless picture.png -o picture_lossless.webp cwebp -q 70 picture_with_alpha.png -o picture_with_alpha.webp cwebp -sns 70 -f 50 -strong -af -size 60000 picture.png -o picture.webp