-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
[performance] move thumbnail generation to go code where possible #3183
[performance] move thumbnail generation to go code where possible #3183
Conversation
…quality for both webp and jpeg generation
internal/media/thumbnail.go
Outdated
} | ||
|
||
// Apply orientation | ||
// BEFORE any resize. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for this btw? Cheaper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a case of our image dimensions already taking orientation into account, so we need to reorient the image first before applying the new dimensions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added a code comment to make it a bit clearer too
Looks good :) :) :) |
Description
While ffmpeg is great for thumbnail generation, and we do like using webps (pee hehe), it comes with a lot of extra overhead. This updates our media processing code to use ffmpeg as a fallback, which ends up being with the majority of media types, but primarily resorting to our own Go thumbnail generation code if possible. this results in JPEG, PNG, GIF, Webps without transparency layers being thumbnailed using Go code, and all else resorting to ffmpeg. unfortunately there is no Go support for Webp encoding, so those thumbnailed with Go code are encoded to JPEGs, hence the restriction on transparency layers.
This also updates ffmpeg to maintain the pixel colorspace where possible (credit largely to @tsmethurst for this, even if the investigation ended a bit oddly 🥲), updates our metadata cleaning to fallback to ffmpeg when exif-terminator fails (thank you @tsmethurst), updates our handling of image rotation to instead use the "orientation" flag which is both much more flexible (supporting mirroring) and much easier to work with, reduces the number of frames we page through with the ffmpeg thumbnail filter (which reduces memory usage, marginally), and finally updates our thumbnail quality setting to the defaults for both webp / jpeg (75%) which looks much nicer on the frontend while not causing much of a size increase (once again, thank you @tsmethurst)
This PR is a result of multiple days of digging and experimentation by both myself and @tsmethurst, this absolutely was a joint effort :p
Checklist
go fmt ./...
andgolangci-lint run
.