class ActiveStorage::Previewer::VideoPreviewer

Public Class Methods

accept?(blob) click to toggle source
# File lib/active_storage/previewer/video_previewer.rb, line 5
def self.accept?(blob)
  blob.video?
end

Public Instance Methods

preview() { |io: output, filename: "#{filename.base}.png", content_type: "image/png"| ... } click to toggle source
# File lib/active_storage/previewer/video_previewer.rb, line 9
def preview
  download_blob_to_tempfile do |input|
    draw_relevant_frame_from input do |output|
      yield io: output, filename: "#{blob.filename.base}.png", content_type: "image/png"
    end
  end
end

Private Instance Methods

draw_relevant_frame_from(file, &block) click to toggle source
# File lib/active_storage/previewer/video_previewer.rb, line 18
def draw_relevant_frame_from(file, &block)
  draw ffmpeg_path, "-i", file.path, "-y", "-vcodec", "png",
    "-vf", "thumbnail", "-vframes", "1", "-f", "image2", "-", &block
end
ffmpeg_path() click to toggle source
# File lib/active_storage/previewer/video_previewer.rb, line 23
def ffmpeg_path
  ActiveStorage.paths[:ffmpeg] || "ffmpeg"
end