From 75ee73f237ab12d0b5f3187fcb5f68b010320b44 Mon Sep 17 00:00:00 2001 From: bajankristof Date: Fri, 29 Nov 2024 16:13:08 +0100 Subject: [PATCH] refactor(scale-filter): introduce constants for magic scale filter dimensions Refs: ARC-9901 --- lib/ffmpeg/filters/scale.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ffmpeg/filters/scale.rb b/lib/ffmpeg/filters/scale.rb index b61daa0..f6b4541 100644 --- a/lib/ffmpeg/filters/scale.rb +++ b/lib/ffmpeg/filters/scale.rb @@ -16,6 +16,9 @@ def scale(width: nil, height: nil, force_original_aspect_ratio: nil, flags: nil) # The Scale class uses the scale filter # to resize a multimedia stream. class Scale < Filter + NEAREST_DIMENSION = -1 + NEAREST_EVEN_DIMENSION = -2 + class << self # Returns a scale filter that fits the specified media # within the specified maximum width and height, @@ -44,11 +47,11 @@ def contained(media, max_width: nil, max_height: nil) return unless max_width || max_height if media.rotated? - width = max_height || -2 - height = max_width || -2 + width = max_height || NEAREST_EVEN_DIMENSION + height = max_width || NEAREST_EVEN_DIMENSION else - width = max_width || -2 - height = max_height || -2 + width = max_width || NEAREST_EVEN_DIMENSION + height = max_height || NEAREST_EVEN_DIMENSION end if width.negative? || height.negative?