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 diff --git a/lib/paperclip/paperclip_processors/transcoder.rb b/lib/paperclip/paperclip_processors/transcoder.rb index d67efea..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? ? 3 : 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