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

Error in encoding big images with CTU size 16 #1161

Open
keni7385 opened this issue Apr 12, 2024 · 4 comments
Open

Error in encoding big images with CTU size 16 #1161

keni7385 opened this issue Apr 12, 2024 · 4 comments

Comments

@keni7385
Copy link

keni7385 commented Apr 12, 2024

Hello,

I am using libheif to encode large images via x265 encoder. I am interested in testing the smallest CTU size (16).
I receive the Invalid Image size error. For squared images with size HxH, this happens for H>1488.

For convenience, we can reproduce the error using heif-enc on a 2048x2048 test image:

 heif-enc -p x265:ctu=16  man4.jpg man4_ctu16.heic
Could not encode HEIF/AVIF file: Encoder plugin generated an error: Invalid image size

It works fine with a smaller image, e.g. 1024x1024, or with higher ctu:

 heif-enc -p x265:ctu=16  man1.jpg man1_ctu16.heic
 heif-enc -p x265:ctu=32  man4.jpg man4_ctu32.heic
 heif-enc -p x265:ctu=64  man4.jpg man4_ctu64.heic

It seems to be independent on the image content, at least with the samples I have tried.

I am using libheif v1.17.6 and x265 v3.5.


test_images.zip

@bradh
Copy link
Contributor

bradh commented Apr 13, 2024

I can reproduce. However the problem is not in libheif, or in the x265 plugin.

You can reproduce this problem with x265 on the command line.

x265 --ctu=16 man4.y4m out.bits 
y4m  [info]: 2048x2048 fps 25/1 i420p8 sar 1:1 frames 0 - 0 of 1
raw  [info]: output file: out.bits
x265 [info]: HEVC encoder version 3.5+1-f0c1022b6
x265 [info]: build info [Linux][GCC 11.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [warning]: Max TU size should be less than or equal to max CU size, setting max TU size = 16
x265 [warning]: QGSize should be less than or equal to maxCUSize, setting QGSize = 16
x265 [warning]: level 5 detected, but CTU size 16 is non-compliant
x265 [info]: NONE profile, Level-NONE (Main tier)
x265 [info]: non-conformant bitstreams not allowed (--allow-non-conformance)
x265 [error]: x265_encoder_open() failed for Enc, 
x265 [error]: Failure generating stream headers in x265

I don't have a solution right now, but would suggest you can work out an appropriate set of options using x265 (and probably the HEVC encoder specifications, e.g. ISO/IEC 23008-2) to find the options you need.

In any case, I don't think this is an issue in libheif.

@keni7385
Copy link
Author

keni7385 commented Apr 16, 2024 via email

@farindk
Copy link
Contributor

farindk commented Apr 16, 2024

The x265 command line docs says that the default maximum TU size is 32. If you set CTU to 16, this combination makes no sense as the TU has to be smaller or equal to CTU. My guess is that if you set --max-tu-size also to 16, it would work.

BTW: any reason for reducing the CTU size? It should just lower the compression ratio.

@keni7385
Copy link
Author

keni7385 commented Apr 16, 2024

If I set --max-tu-size=16 it does remove the warning:

x265 [warning]: Max TU size should be less than or equal to max CU size, setting max TU size = 16

but it still results in errors because of a non-conformant bitstream. It happens similarly if I also add --qg-size=16, as both QGSize and MaxTU are already adjusted automatically by setting --ctu=16 (if I interpret the logs correctly).

x265 --ctu=16 --max-tu-size=16 --qg-size=16 --log-level=full  man4.y4m out.bits
y4m  [info]: 2048x2048 fps 25/1 i420p8 sar 1:1 frames 0 - 0 of 1
raw  [info]: output file: out.bits
x265 [info]: HEVC encoder version 3.5
x265 [info]: build info [Linux][GCC 11.2.0][64 bit] 8bit+10bit+12bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x265 [warning]: level 5 detected, but CTU size 16 is non-compliant
x265 [info]: NONE profile, Level-NONE (Main tier)
x265 [info]: non-conformant bitstreams not allowed (--allow-non-conformance)
x265 [error]: x265_encoder_open() failed for Enc,
x265 [error]: Failure generating stream headers in x265

BTW: any reason for reducing the CTU size? It should just lower the compression ratio.

I am experimenting with a custom inloop filter, I would like to see how it behaves at different CTU sizes.

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

3 participants