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:
parent
6c921817e1
commit
9ffdd0432f
2 changed files with 18 additions and 8 deletions
|
@ -201,7 +201,7 @@ where
|
||||||
let (reader, media_type) = if let Some(processable_format) =
|
let (reader, media_type) = if let Some(processable_format) =
|
||||||
original_details.internal_format().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(
|
let reader = magick::thumbnail(
|
||||||
store,
|
store,
|
||||||
|
@ -215,7 +215,13 @@ where
|
||||||
|
|
||||||
(reader, thumbnail_format.media_type())
|
(reader, thumbnail_format.media_type())
|
||||||
} else {
|
} 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(
|
let reader = ffmpeg::thumbnail(
|
||||||
store.clone(),
|
store.clone(),
|
||||||
|
|
|
@ -8,35 +8,39 @@ use crate::{
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub(super) enum ThumbnailFormat {
|
pub(super) enum ThumbnailFormat {
|
||||||
Jpeg,
|
Jpeg,
|
||||||
// Webp,
|
Png,
|
||||||
|
Webp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThumbnailFormat {
|
impl ThumbnailFormat {
|
||||||
const fn as_ffmpeg_codec(self) -> &'static str {
|
const fn as_ffmpeg_codec(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Jpeg => "mjpeg",
|
Self::Jpeg => "mjpeg",
|
||||||
// Self::Webp => "webp",
|
Self::Png => "png",
|
||||||
|
Self::Webp => "webp",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn to_file_extension(self) -> &'static str {
|
const fn to_file_extension(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Jpeg => ".jpeg",
|
Self::Jpeg => ".jpeg",
|
||||||
// Self::Webp => ".webp",
|
Self::Png => ".png",
|
||||||
|
Self::Webp => ".webp",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn as_ffmpeg_format(self) -> &'static str {
|
const fn as_ffmpeg_format(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::Jpeg => "image2",
|
Self::Jpeg | Self::Png => "image2",
|
||||||
// Self::Webp => "webp",
|
Self::Webp => "webp",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn media_type(self) -> mime::Mime {
|
pub(crate) fn media_type(self) -> mime::Mime {
|
||||||
match self {
|
match self {
|
||||||
Self::Jpeg => mime::IMAGE_JPEG,
|
Self::Jpeg => mime::IMAGE_JPEG,
|
||||||
// Self::Webp => crate::formats::mimes::image_webp(),
|
Self::Png => mime::IMAGE_PNG,
|
||||||
|
Self::Webp => crate::formats::mimes::image_webp(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue