From 4cc810d372e1cc5285dc2d9140f5c3abe15f05c0 Mon Sep 17 00:00:00 2001 From: asonix Date: Sat, 4 Feb 2023 17:52:23 -0600 Subject: [PATCH] Add control over gif frame count --- defaults.toml | 1 + pict-rs.toml | 8 ++++++++ src/config/commandline.rs | 6 +++--- src/config/defaults.rs | 2 ++ src/config/file.rs | 2 ++ src/ffmpeg.rs | 1 + 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/defaults.toml b/defaults.toml index 7757ca3..cd28a2c 100644 --- a/defaults.toml +++ b/defaults.toml @@ -39,6 +39,7 @@ cache_duration = 168 max_width = 128 max_height = 128 max_area = 16384 +max_frame_count = 100 [repo] type = "sled" diff --git a/pict-rs.toml b/pict-rs.toml index 7afa71d..50f1d0b 100644 --- a/pict-rs.toml +++ b/pict-rs.toml @@ -224,6 +224,14 @@ max_height = 128 # depending on whether video uploads are enabled max_area = 16384 +# Optional: Maximum number of frames permitted in uploaded gifs +# environment variable: PICTRS__MEDIA__GIF__MAX_FRAME_COUNT +# default: 100 +# +# If a gif does not fit within this bound, it will either be transcoded to a video or rejected, +# depending on whether video uploads are enabled +max_frame_count = 100 + ## Database configuration [repo] diff --git a/src/config/commandline.rs b/src/config/commandline.rs index 02c2b15..327ff57 100644 --- a/src/config/commandline.rs +++ b/src/config/commandline.rs @@ -462,19 +462,19 @@ struct Run { media_max_frame_count: Option, /// Maximum width allowed for gif uploads. /// - /// If an upload exceeds this value, it will be transcoded to a video format or aborted, + /// If an upload exceeds this value, it will be transcoded to a video format or rejected, /// depending on whether video uploads are enabled. #[arg(long)] media_gif_max_width: Option, /// Maximum height allowed for gif uploads /// - /// If an upload exceeds this value, it will be transcoded to a video format or aborted, + /// If an upload exceeds this value, it will be transcoded to a video format or rejected, /// depending on whether video uploads are enabled. #[arg(long)] media_gif_max_height: Option, /// Maximum area allowed for gif uploads /// - /// If an upload exceeds this value, it will be transcoded to a video format or aborted, + /// If an upload exceeds this value, it will be transcoded to a video format or rejected, /// depending on whether video uploads are enabled. #[arg(long)] media_gif_max_area: Option, diff --git a/src/config/defaults.rs b/src/config/defaults.rs index 86c642f..a1e68e1 100644 --- a/src/config/defaults.rs +++ b/src/config/defaults.rs @@ -81,6 +81,7 @@ struct GifDefaults { max_height: usize, max_width: usize, max_area: usize, + max_frame_count: usize, } #[derive(Clone, Debug, serde::Serialize)] @@ -187,6 +188,7 @@ impl Default for GifDefaults { max_height: 128, max_width: 128, max_area: 16384, + max_frame_count: 100, } } } diff --git a/src/config/file.rs b/src/config/file.rs index 1a74a44..67efcb0 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -128,6 +128,8 @@ pub(crate) struct Gif { pub(crate) max_height: usize, pub(crate) max_area: usize, + + pub(crate) max_frame_count: usize, } impl Media { diff --git a/src/ffmpeg.rs b/src/ffmpeg.rs index f57e379..6c26f4b 100644 --- a/src/ffmpeg.rs +++ b/src/ffmpeg.rs @@ -33,6 +33,7 @@ impl TranscodeOptions { if details.width <= media.gif.max_width && details.height <= media.gif.max_height && details.width * details.height <= media.gif.max_area + && details.frames.unwrap_or(1) <= media.gif.max_frame_count { return Self { input_format,