-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Animated User Asset Processing #12
Comments
With the new user asset multi-versioning system, encoding GIFs to other formats is an option. Sadly, AVIF is not ideal for animations. WebM/VP9+Alpha works well via The A dedicated asset processing queue may be needed for WebM/APNG encoding, as any blocking solution may result in HTTP request timeouts when trying to apply profile data. Anything more than |
and
are pretty close to optimal. Lantern must use the standard io streams for communication, so that's how they're designed here. VP9 encoding is very slow, but quite efficient, and supports transparency. GIFs suck all-around, but The denoising and deflickering are to remove artifacts from previous dithering as well as a small attempt to avoid seizure-warning GIFs. My initial testing showed rather nice file size reduction once the jittering from previous dithering was removed. These will have to be tuned for banners as well. |
these can be used on banners. Since GIFs will always be the fallback, we can avoid minutes of processing by generating the banner at half or perhaps even a quarter of the full resolution. Perhaps some kind of heuristic could be used based in the incoming file type and size. Might also be better to increase the Both of these banner commands take 1-2.5x media duration to encode on my PC. Will be even slower on the server. This will likely mean animated banners will be a premium offering out of sheer necessity. |
An additional step to detect transparency in the source media might be a good idea, probably through |
As it turns out, ffmpeg requires So my plan of just using stdin/stdout without any intermediate file is out the window. One solution would be to make use of tmpfs, as like the opposite of mmapping. Store the file in tmpfs and that will allow ffmpeg to seek around to its heart's content. tmpfs does not preallocate, and Docker has native support for it for easy deployment. With tmpfs, I can also use ffprobe to make more intelligent decisions about how to encode the asset. For example, very small GIFs can suffer from re-encoding, so we can change either the dither pattern to |
Can also generate low-quality banner GIFs using something like:
Fewer colors, more deflicker, lower fps, no dithering, very lossy post-processing |
After more thought and experimentation, my current plans are to do the following: If the source file's mime type is detected to be a GIF:
If the source file's mime type was incorrect, but ffprobe detects it as a GIF, the system will treat it as an opaque GIF. Less work for a bad file. If the source file is not a GIF, but still has an alpha channel, ffprobe will detect that and we can choose the appropriate formats. Only GIFs require the heavy denoising filters, though. Knowing if the GIF is actually transparent on any frame is important for the selection algorithm, as formats with alpha channel are given priority. VP9 WebM support may be made optional, though, as it takes significantly longer to encode than all the other formats combined. It's even tempting to not use WebM if the animation is opaque. Furthermore, it will likely be necessary to create a "job" system within the API to track the progress of encoding jobs. It may be too long to wait for a single HTTP POST request, so instead the frontend can poll the job system for a specific job ID (provided by the API), and display a progress-bar in the GUI. We can give the |
GIFs for avatars and banners will be quite popular, and need to be cropped, scaled and optimized like still images.
Currently, the "standard"
image
library has rather poor GIF support, drastically increasing file size in some cases, and is also quite slow based on issues.https://github.com/ImageOptim/gifski has a better encoder, but is more focused in extracting the highest quality from video, rather than optimizing existing GIFs. Likely not a good fit.
ImageMagick may be the only solution, by spawning a subprocess and passing the image data through stdin. https://github.com/zshipko/image2-rs is notable for this, but lacks apparent GIF support. Custom routines would likely be needed.
The text was updated successfully, but these errors were encountered: