Class: FFMPEG::ActiveStorage::Previewer
- Inherits:
-
ActiveStorage::Previewer
- Object
- ActiveStorage::Previewer
- FFMPEG::ActiveStorage::Previewer
- Defined in:
- lib/ffmpeg/active_storage/previewer.rb
Overview
Active Storage Previewer for video files using FFMPEG
Generates video preview images (thumbnails) for Active Storage.
Class Method Summary collapse
-
.accept?(blob) ⇒ Boolean
Check if this previewer can process the blob.
Instance Method Summary collapse
-
#preview(**options) {|io, options| ... } ⇒ Object
Generate a preview image.
Class Method Details
.accept?(blob) ⇒ Boolean
Check if this previewer can process the blob
20 21 22 |
# File 'lib/ffmpeg/active_storage/previewer.rb', line 20 def accept?(blob) blob.video? end |
Instance Method Details
#preview(**options) {|io, options| ... } ⇒ Object
Generate a preview image
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ffmpeg/active_storage/previewer.rb', line 27 def preview(**) download_blob_to_tempfile do |input| media = FFMPEG::Media.new(input.path) # Extract frame at 10% into the video (avoid black frames at start) = (media.duration || 10) * 0.1 draw_frame(media, ) do |output| yield io: output, filename: "#{blob.filename.base}.jpg", content_type: "image/jpeg" end end end |