From 9ffdd0432f512f0552f8d75b41f4509f326b24be Mon Sep 17 00:00:00 2001 From: asonix Date: Sun, 24 Sep 2023 12:37:43 -0500 Subject: [PATCH] Infer video thumbnail format from image format --- src/generate.rs | 10 ++++++++-- src/generate/ffmpeg.rs | 16 ++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/generate.rs b/src/generate.rs index 28a9d16..d3303cc 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -201,7 +201,7 @@ where let (reader, media_type) = if let Some(processable_format) = original_details.internal_format().processable_format() { - let thumbnail_format = ImageFormat::Jpeg; + let thumbnail_format = media.image.format.unwrap_or(ImageFormat::Webp); let reader = magick::thumbnail( store, @@ -215,7 +215,13 @@ where (reader, thumbnail_format.media_type()) } else { - let thumbnail_format = ffmpeg::ThumbnailFormat::Jpeg; + let thumbnail_format = match media.image.format { + Some(ImageFormat::Webp | ImageFormat::Avif | ImageFormat::Jxl) => { + ffmpeg::ThumbnailFormat::Webp + } + Some(ImageFormat::Png) => ffmpeg::ThumbnailFormat::Png, + Some(ImageFormat::Jpeg) | None => ffmpeg::ThumbnailFormat::Jpeg, + }; let reader = ffmpeg::thumbnail( store.clone(), diff --git a/src/generate/ffmpeg.rs b/src/generate/ffmpeg.rs index 7a9bf6c..3e2464d 100644 --- a/src/generate/ffmpeg.rs +++ b/src/generate/ffmpeg.rs @@ -8,35 +8,39 @@ use crate::{ #[derive(Clone, Copy, Debug)] pub(super) enum ThumbnailFormat { Jpeg, - // Webp, + Png, + Webp, } impl ThumbnailFormat { const fn as_ffmpeg_codec(self) -> &'static str { match self { Self::Jpeg => "mjpeg", - // Self::Webp => "webp", + Self::Png => "png", + Self::Webp => "webp", } } const fn to_file_extension(self) -> &'static str { match self { Self::Jpeg => ".jpeg", - // Self::Webp => ".webp", + Self::Png => ".png", + Self::Webp => ".webp", } } const fn as_ffmpeg_format(self) -> &'static str { match self { - Self::Jpeg => "image2", - // Self::Webp => "webp", + Self::Jpeg | Self::Png => "image2", + Self::Webp => "webp", } } pub(crate) fn media_type(self) -> mime::Mime { match self { Self::Jpeg => mime::IMAGE_JPEG, - // Self::Webp => crate::formats::mimes::image_webp(), + Self::Png => mime::IMAGE_PNG, + Self::Webp => crate::formats::mimes::image_webp(), } } }