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

Adjust quality based on output file size #4070

Open
danvoyce opened this issue Apr 18, 2024 · 2 comments
Open

Adjust quality based on output file size #4070

danvoyce opened this issue Apr 18, 2024 · 2 comments
Labels

Comments

@danvoyce
Copy link

Feature request

I know this feature has been requested a lot over the years, but we are in the future now so I'd like to think there's a way to do this that's smarter than the brute force approach.

What are you trying to achieve?

Ultimately what I and I believe others are wanting to achieve is specific output size, so no matter what size file we are trying to compress, we can be sure that it's below x.

Yes we can brute force it, but that's not very performant.

I'd like to think with someone a lot smarter than me could potentially use some ML magic and come up with a better approach...

Anyone?

@lovell
Copy link
Owner

lovell commented Apr 18, 2024

The performance of the "brute force" example you've linked to could be improved, or at least made more consistent, with the use of binary search.

Given most lossy image encoding is entropy-based, you may also have some luck by investigating either linear or polynomial regression ("AI" from the 19th century) of image entropy for a given image corpus that represents your scenario. For JPEG encoding, the higher the entropy value of an image, the lower the required quality value is likely to be in order to hit a target file size.

@danvoyce
Copy link
Author

Is this something you'd consider adding to the library? I'd love to dig deeper on this but don't have the time at the mo or know where to start 😅

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

No branches or pull requests

2 participants