Comments (5)
Hi @swistaczek!
Oh, GIFs are a painful subject... There are multiple problems:
- GIF encoding is slow. It involves the quantization and remapping of each frame. And this is a pretty slow process. We do our best to optimize it, but we can't overperform the CPU.
- Since GIF compression is pretty poor, GIFs require additional optimizations like frame cropping and alpha optimizations. This takes some time too.
- Encoding to GIF is poorly optimizable. Most steps can't be parallelized so using such things as SIMD instructions is simply impossible in most cases.
- GIFs may contain many frames. The image you provided contains 250 frames, which means that imgproxy in fact needs to process and encode 250 images.
- Resizing of GIFs usually produces larger files. GIF images may have 256 colors at the max, but resizing produces new colors. This leads to additional dithering and this leads to worse compression.
Considering all these points, the best way to optimize GIF processing is to not touch GIFs at all unless you resize them to a much smaller size. I know that some of our users just set IMGPROXY_SKIP_PROCESSING_FORMATS=gif
.
As an alternative, I could recommend to convert animations to MP4. This produces much smaller files, and encoding to MP4 is much faster. However, this requires a special treatment of animations as you can't put video in the <img>
tag.
Also, though we host our demo instances of imgproxy on GCP ourselves, Google Cloud Run's performance is far from being the best on the market. It's enough for processing static images, but large GIFs may be a problem as you noticed. I tested processing of pretty large GIFs on Amazon's c7g instances, and it was able to chew GIFs that GCR chokes with.
Sorry for not bringing any good news here, but GIF is a real headache 😓
from imgproxy.
Thank you for your comprehensive explanation and for presenting the available solutions!
from imgproxy.
We also ran into gif performance issues and took the "just skip it" path. In our case, it was a fairly large (2k x 2k) 100 frame animation. We wanted to resize it to something more reasonable. At the time (and it's been ~1 year), it seemed like it was the memory pressure and that libvips was decompressing the whole thing into a very large filmstrip before resizing and re-encoding.
In our use case, we typically want to resize them fairly small, so I'd expect the encoding time to be less of an issue.
Also, we'd happily consider some monetary sponsorship to help move this along!
from imgproxy.
Memory shouldn't be an issue since libvips doesn't decode the whole "filmstrip" into memory. Libvips stores only a single frame in the memory. I guess, the issue in your case is the resizing itself since imgproxy has to resize 100 2K images. However, things changed a lot in the last year: resizing was optimized with SIMD intrinsics and became much faster.
from imgproxy.
BTW: can confirm that 3.21.0 is ~2x faster than 3.10.0 based on some fairly crude benchmarks. I also can confirm that, yes, the gif encoding speed is a major factor.
Thanks @DarthSim !
from imgproxy.
Related Issues (20)
- Issues in conversion of SVG to PNG HOT 3
- invalid source on mp4 when using video thumbnail extraction HOT 2
- Promethues exporter HOT 3
- Can't download source image: Can't allocate input format context: Server returned 400 Bad Request HOT 2
- Link to Documentation is down HOT 1
- Feature request: add support for APNG animated images HOT 3
- Monochrome thumbnails from latest release HOT 13
- There is an error in the image file name that contains the '@' character. HOT 1
- Feature request: animated AVIF HOT 4
- Allow gravity to be relative HOT 4
- Will chrome automatically convert webp to avif? HOT 2
- Feature request: Video thumbnail tile behaviour HOT 1
- Provide a more detailed error message why local:// is not available when IMGPROXY_LOCAL_FILESYSTEM_ROOT is not set
- GIF gint is invalid or out of range HOT 2
- Can't connect to firebase local emulator
- Priority of /format: %format/ and @ HOT 1
- Crop Area with focus point HOT 5
- Im Confused on how to code HOT 4
- ThumbHash support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imgproxy.