-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Video thumbnails
ImageMagick, the processor library used to process attachments for alternate attachment styles (e.g. thumbnails) contains support for capturing a still image from a video file.
To create an attachment style from a video using paperclip, define your styles as usual, via the has_attached_file
call. ImageMagick will handle extraction of the the still image automatically. By default, the first frame of the video will be used for the still image.
class User < ActiveRecord::Base
# Paperclip
has_attached_file :media,
:styles => {:thumb => ["400x400#", :jpg]}
end
In the example above, for a .mp4
file saved as a media attachment, the following convert command will be executed and logged in your IO stream. The (file).mp4[0]
indicates the first frame is being extracted.
convert '/var/folders/j2/3rc4mp5j52lg7ps1y2twv2hm0000gn/T/9f7e6ab891348cac0c44db725c6887a520150904-5040-1v5q6mo.mp4[0]' -auto-orient -resize "400x" -crop "410x410+0+102" +repage '/var/folders/j2/3rc4mp5j52lg7ps1y2twv2hm0000gn/T/9f7e6ab891348cac0c44db725c6887a520150904-5040-1v5q6mo20150904-5040-6wnvnr.jpg'
For more on thumbnail styles see Thumbnail Generation.
Note: ImageMagick does not handle the thumbnail extraction directly. It delegates the extraction to the ffmeg library. If ffmpeg is not available paperclip will raise
Validation failed: Asset Paperclip::Errors::NotIdentifiedByImageMagickError
.