media: generate blurhashes for video thumbnails

This commit is contained in:
Tulir Asokan 2024-12-05 19:47:39 +02:00
parent fa80c1adc0
commit f180077f0a

View file

@ -570,12 +570,18 @@ func (gmx *Gomuks) generateVideoThumbnail(ctx context.Context, filePath string,
if err != nil { if err != nil {
return fmt.Errorf("failed to seek to start of file: %w", err) return fmt.Errorf("failed to seek to start of file: %w", err)
} }
cfg, _, err := image.DecodeConfig(tempFile) img, _, err := image.Decode(tempFile)
if err != nil { if err != nil {
zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to decode thumbnail image config") zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to decode thumbnail image config")
} else { } else {
thumbnailInfo.Width = cfg.Width bounds := img.Bounds()
thumbnailInfo.Height = cfg.Height thumbnailInfo.Width = bounds.Dx()
thumbnailInfo.Height = bounds.Dy()
hash, err := blurhash.Encode(4, 3, img)
if err != nil {
zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to generate image blurhash")
}
thumbnailInfo.AnoaBlurhash = hash
} }
_ = tempFile.Close() _ = tempFile.Close()
checksum := hasher.Sum(nil) checksum := hasher.Sum(nil)