libjxl icon indicating copy to clipboard operation
libjxl copied to clipboard

Error when tying to convert to jxl

Open Dogstar359 opened this issue 1 year ago • 10 comments

im trying to convert my jpgs to jxl most seem to convert fine, but some files give this error.

E:\libjxl>cjxl 0_0009.jpg 0_00091.jxl -v JPEG XL encoder v0.10.3 4a3b22d [AVX2,SSE2] Note: Implicit-default for JPEG is lossless-transcoding. To silence this message, set --lossless_jpeg=(1|0). Read JPEG image with 2710692 bytes. Encoding [JPEG, lossless transcode, effort: 7] JPEG bitstream reconstruction data could not be created. Possibly there is too much tail data. Try using --jpeg_store_metadata 0, to losslessly recompress the JPEG image data without bitstream reconstruction data. EncodeImageJXL() failed.

whats worse is that when i add --jpeg_store_metadata 0 like so 0_0009.jpg 0_00091.jxl --jpeg_store_metadata 0 i get

E:\libjxl>cjxl 0_0009.jpg 0_00091.jxl --jpeg_store_metadata 0 Unknown argument: --jpeg_store_metadata Use 'cjxl -h' for more information

Ive been using XL Converter to convert my jpgs, and have contacted them, he seem to think the problem lies with cjxl, and that it could be to do with the metadata, but when i strip the metadata the error still occurs. can anyone help? Thankyou

Dogstar359 avatar Aug 26 '24 17:08 Dogstar359

you can close the thread as ive just learned that you cant help without me sending the images. which are kinda personal to me. I would have liked to try and fix the problem, but i dont want to waste anyones time. If anyone knows of a way to resave jpg images without losing quality while keeping them the same size i would appreciate it, as it seems to be the images. Thankyou

Dogstar359 avatar Aug 26 '24 18:08 Dogstar359

@Dogstar359 Are the images motion/live photos created by a mobile device?

0fbcb238c0 avatar Aug 26 '24 18:08 0fbcb238c0

they are still images/photographs taken with my kodak digital camera, ive just learned that if i use --allow_jpeg_reconstruction 0 it actually processes the images without error, and they display fine, but am not sure if using the command is safe on the images.

Does this reconstruction change the fidelity of the images or are they the same as the original ? As i am archiving my photographs to save space.

Dogstar359 avatar Aug 26 '24 18:08 Dogstar359

The default behaviour of cjxl is lossless recompressing JPGs to JXL. So no data is lost and you save some storage because of the recompression. It is also possible to reconstruct the original JPG from the JXL using djxl.

If you specified "--allow_jpeg_reconstruction 0" then cjxl will convert the already lossy JPG to JXL in a lossy manner. The resulting JXL will therfore not be the same as the original JPG.

0fbcb238c0 avatar Aug 26 '24 19:08 0fbcb238c0

If you specified "--allow_jpeg_reconstruction 0" then cjxl will convert the already lossy JPG to JXL in a lossy manner. The resulting JXL will therfore not be the same as the original JPG.

That's what --lossless_jpeg=0 does. --allow_jpeg_reconstruction=0 doesn't force it to decode the JPG to pixels - it will still do a lossless transcode, but it doesn't try to store the metadata (jbrd) that would allow you to reconstruct the JPG bit-for-bit later.

So encoding with the the latter option is safe and lossless in this case - but you would lose quality if you decided to convert back to JPG.

As for why it's failing for that file, it could be related to one of these: https://github.com/libjxl/libjxl/issues/2693#issuecomment-1662249549 https://github.com/libjxl/libjxl/issues/803#issuecomment-963083226

alistair7 avatar Aug 26 '24 20:08 alistair7

is there a way to rebuild the image, the samesize and quality, and then re-encode to jxl so that it could be converted back to jpg later if needed?

Dogstar359 avatar Aug 26 '24 20:08 Dogstar359

Yes, if you have access to jpegtran from libjpeg-turbo you could try:

jpegtran -copy all -optimize 0_0009.jpg > 0_0009_copy.jpg

That keeps pixels and metadata exactly the same, but rewrites the file structure, and it might be possible to then compress 0_0009_copy.jpg with cjxl in a reversible way. This has usually worked for me when I've run into that error.

If that doesn't work, try -copy none instead of -copy all - that will preserve the pixels exactly but remove all metadata (but you said you'd already tried removing metadata, so not sure if it will help in this case).

alistair7 avatar Aug 26 '24 21:08 alistair7

Thankyou ive downloaded jpegtran, and ill give it a try. Just wish there was a simpler method as ive got a couple hundred images to convert if it works.

Dogstar359 avatar Aug 26 '24 22:08 Dogstar359

i just wanted to ask is the problem im having with encoding jxl files a bug in libxjl or more of a problem with the jpgs themselves. I only ask because i raised the issue as a bug on github, and if the problem is with the files its not really a fault with libxjl, more of a feature that could, if possible be implemented in a future release, if the problem can be fixed of course.

Dogstar359 avatar Aug 26 '24 23:08 Dogstar359

From what I understand, the JXL format doesn't support lossless transcoding of "unusual" JPGs, and it's a limitation in the JXL spec, not something that can be fixed in libjxl.

It's hard to know for sure without seeing an example file, but I'd guess your JPGs have one or more of those unusual features. jpegtran should be able to fix them in most cases.

alistair7 avatar Aug 27 '24 18:08 alistair7