ffmpeggstreamerlibavgstreamer-1.0jpeg2000

How to increase the compression ratio of a JPEG2000 file with "avenc_jpeg2000" GStreamer encoder?


I'm using the plugin avenc_jpeg2000, from gst-libav module, combined with videotestsrc and filesink plugins for encoding a raw picture to a JPEG2000 picture:

gst-launch-1.0 videotestsrc num-buffers=1 ! avenc_jpeg2000 ! filesink location=/tmp/picture-ref.jp2

This pipeline works and produce a 31.85 KiB (32,616) file.

Pipeline graph

Now, I want to divide the size of my output file by two by increasing the compression ratio of the encoder avenc_jpeg2000. To achieve this, I want to minimize the number of bits required to represent the image with an allowable level of distortion. I know JPEG2000 standard support lossless and lossy compression mode. For my use case, the lossy compression mode is acceptable.

How should I proceed to increase the compression of my output file ? What encoder's properties should I play with for doing that ?

My test configuration:

I tried to play with "bitrate" and "bitrate-tolerance" properties, but it seems to have no effect on the size of the output file:

gst-launch-1.0 videotestsrc num-buffers=1 ! avenc_jpeg2000 bitrate=100000 bitrate-tolerance=10000 ! filesink location=/tmp/picture-test-01.jp2

I compare files by doing a checksum with sha224sum command :

d0da9118a9c93a0420d6d62f104e0d99fe6e50cda5e87a46cef126f9  /tmp/picture-ref.jp2

d0da9118a9c93a0420d6d62f104e0d99fe6e50cda5e87a46cef126f9  /tmp/picture-test-01.jp2

Solution

  • For lossy compression, you can increase the value of the quantization.

    First, set the encoding type of the encoder to "Constant Quantizer" and then, find an appropriated quantizer value.

    In my case, to produce a 15 KiB file, I used the following pipeline:

    gst-launch-1.0 videotestsrc num-buffers=1 ! avenc_jpeg2000 pass=2 quantizer=10  ! filesink location=/tmp/picture-test-02.jp2