2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-12-22 19:31:35 +00:00

Infer video thumbnail format from image format

This commit is contained in:
asonix 2023-09-24 12:37:43 -05:00
parent 6c921817e1
commit 9ffdd0432f
2 changed files with 18 additions and 8 deletions

View file

@ -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(),

View file

@ -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(),
}
}
}