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)
- Resizing with "fit" mode leads to blurry images in some cases HOT 2
- invalid TIFF format: image dimensions are not specified HOT 6
- Support EPS files HOT 1
- "is not a video" error when trying to source PSD file HOT 2
- How to get width and height of original img? HOT 1
- Feature request: support using data urls as watermarkurl HOT 1
- Feature request: Gradient improvements HOT 5
- Text is illegible when a PDF has non-embedded CID TrueType and no character map HOT 4
- Feature Request: Option to limit max dimension of output image HOT 4
- Error: heifsave: image too large HOT 2
- Using imgproxy via Proxy for Amazon S3 HOT 3
- Option to report source image errors HOT 4
- Style transformation for SVG broken since 3.23 HOT 3
- Error: SVG detection does not work when it uses namespaces HOT 2
- Can't download source image: invalid JPEG format: missing SOF marker HOT 2
- ERROR png2vips: unable to read source source HOT 2
- Produces invalid SVG when namespaced attributes appear before namespace declaration HOT 1
- Support for external IDs when using S3 with assumed roles HOT 3
- Error: store of inconsistently typed value into Value HOT 1
- Requests to `imgproxy` randomly start timing out HOT 20
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.