From b1fd7edf9fccd93c9a78c3ece757eeb297031844 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 30 Jan 2024 13:06:58 +0200 Subject: [PATCH 1/3] Allow shorter videos by default --- lib/paperclip/paperclip_processors/transcoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index d67efea..7f76f56 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -30,7 +30,7 @@ def initialize file, options = {}, attachment = nil @shrink_only = @keep_aspect && modifier == '>' end - @time = options[:time].nil? ? 3 : options[:time] + @time = options[:time].nil? ? 0 : options[:time] @auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate] @pad_color = options[:pad_color].nil? ? "black" : options[:pad_color] From 02d73e52e016f12fca5cb3a587d64a1d086a3af2 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 30 Jan 2024 13:17:46 +0200 Subject: [PATCH 2/3] mention :time in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a2673c..25fa10c 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ In your model: This will produce: 1. A transcoded `:medium` FLV file with the requested dimensions if they will match the aspect ratio of the original file, otherwise, width will be maintained and height will be recalculated to keep the original aspect ration. -2. A screenshot `:thumb` with the requested dimensions regardless of the aspect ratio. +2. A screenshot `:thumb` with the requested dimensions regardless of the aspect ratio and with `:time => 10`, it captures a frame from the 10th second of the video. ### Meta Data From 74b9ba64be271c9a098c68ca15996c2ce400bb1b Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 30 Jan 2024 14:38:02 +0200 Subject: [PATCH 3/3] better logic --- lib/paperclip/paperclip_processors/transcoder.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index 7f76f56..18ea0a8 100755 --- a/lib/paperclip/paperclip_processors/transcoder.rb +++ b/lib/paperclip/paperclip_processors/transcoder.rb @@ -30,7 +30,7 @@ def initialize file, options = {}, attachment = nil @shrink_only = @keep_aspect && modifier == '>' end - @time = options[:time].nil? ? 0 : options[:time] + @time = options[:time].nil? ? default_time : options[:time] @auto_rotate = options[:auto_rotate].nil? ? false : options[:auto_rotate] @pad_color = options[:pad_color].nil? ? "black" : options[:pad_color] @@ -105,6 +105,11 @@ def format_geometry geometry def output_is_image? !!@format.to_s.match(/jpe?g|png|gif$/) end + + def default_time + duration = @meta[:duration].to_f rescue 0 + duration < 3 ? 0 : 3 + end end class Attachment