Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to compress png format images into jpeg or jpg formats? #91

Open
OroChippw opened this issue Jun 13, 2024 · 3 comments
Open

Comments

@OroChippw
Copy link

Is it possible to compress png format images into jpeg or jpg formats?
I have a png wallpaper with a resolution of 8000*4113. I try to compress it. The console output is as follows

GPUJPEG rev 44ebd07
CUDA driver version:   12.5
CUDA runtime version:  11.6
Using Device #0:       NVIDIA GeForce RTX 3060 (c.c. 8.6)
[Warning] Encoder input file [E:\OroChiLab\GPUJPEG\data\input\1.jpg] should be raw image (*.rgb, *.yuv, *.r, *.pnm)!
@MartinPulec
Copy link
Collaborator

Hi, actually no, the gpujpegtool command-line utility supports just raw images. But as GPUJPEG is mainly a library, it should be quite easy to create your own tool combining GPUJPEG and a PNG decoding library, eg. libpng.

However, I am not sure if GPUJPEG would have any advantage for your scenario - if trying to recompress just a single image, there is plenty of tools that would do the job directly like ImageMagick. But if you have some specific reason to use GPUJPEG, I'd be glad to hear if you wish to share.

@OroChippw
Copy link
Author

OroChippw commented Jun 14, 2024

Hi, actually no, the gpujpegtool command-line utility supports just raw images. But as GPUJPEG is mainly a library, it should be quite easy to create your own tool combining GPUJPEG and a PNG decoding library, eg. libpng.

However, I am not sure if GPUJPEG would have any advantage for your scenario - if trying to recompress just a single image, there is plenty of tools that would do the job directly like ImageMagick. But if you have some specific reason to use GPUJPEG, I'd be glad to hear if you wish to share.

I am very surprised to receive your reply so quickly, thank you.
In my application environment, I try to encode and compress a high-resolution PNG image (the image resolution may range from 8000 * 4113 to 8320 * 40000) to save local storage space, and then decode and decompress it when needed.

  1. The current solution is NvJpeg to implement the above process, but due to the performance of the machine, the compression speed of a single image is too slow. I am trying to find a faster solution.
  2. Regarding what you mentioned above: the gpujpegtool command-line utility supports just raw images. But as GPUJPEG is mainly a library, it should be quite easy to create your own tool combining GPUJPEG and a PNG decoding library, eg. libpng. I may not understand how to implement it in my application environment. Can you provide some links to relevant tutorials or a few suggestions? Thank you😊😊😊

@MartinPulec
Copy link
Collaborator

  1. The current solution is NvJpeg to implement the above process, but due to the performance of the machine, the compression speed of a single image is too slow. I am trying to find a faster solution.

I am afraid that re-encoding just a single image doesn't make much sense for a CUDA application like GPUJPEG (I don't know nvjpeg but I think it will be similar). I don't entirely know nvjpeg, but for GPUJPEG the main use case is to encode plenty of images in a batch, because there is an overhead with initialization of the library (CUDA etc), which needs to be amortized across multiple images.

It really depends on your use case - I can imagine letting the transcoding application running and passing it the JPEG files during the time. But running the process for single image would perhaps perfom worse than encoding on a CPU.

  1. Regarding what you mentioned above: the gpujpegtool command-line utility supports just raw images. But as GPUJPEG is mainly a library, it should be quite easy to create your own tool combining GPUJPEG and a PNG decoding library, eg. libpng. I may not understand how to implement it in my application environment. Can you provide some links to relevant tutorials or a few suggestions? Thank you😊😊😊

Well, the code examples can be found here. For decoding PNG with libpng there are certainly code samples (or ChatGPT could also help). I could certainly make up an example including the PNG decode, but at this time I am unsure if there is some point (regarding my considerations above).

On the command-line you can of course use a separate command to decode the PNG prior to encoding with GPUJPEG, eg. convert from ImageMagick:

convert image.png tmp.pnm
gpujpeg -e tmp.pnm image.jpg

But as indicated above, it won't have any performance benefits against converting directly to JPEG with the ImageMagick.

Also, even if you could afford to encode multiple images, it seems to me that the bottleneck would be the PNG decompress, which is performed by CPU.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants