123456789_123456789_123456789_123456789_123456789_

Class: ActiveStorage::Previewer::VideoPreviewer

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveStorage::Previewer
Defined in: activestorage/lib/active_storage/previewer/video_previewer.rb

Class Attribute Summary

Class Method Summary

::ActiveStorage::Previewer - Inherited

.accept?

Implement this method in a concrete subclass.

.new

Instance Attribute Summary

Instance Method Summary

::ActiveStorage::Previewer - Inherited

#preview

Override this method in a concrete subclass.

#download_blob_to_tempfile

Downloads the blob to a tempfile on disk.

#draw

Executes a system command, capturing its binary output in a tempfile.

#logger, #tmpdir

Constructor Details

This class inherits a constructor from ActiveStorage::Previewer

Class Attribute Details

.ffmpeg_exists?Boolean (readonly)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/previewer/video_previewer.rb', line 12

def ffmpeg_exists?
  return @ffmpeg_exists if defined?(@ffmpeg_exists)

  @ffmpeg_exists = system(ffmpeg_path, "-version", out: File::NULL, err: File::NULL)
end

Class Method Details

.accept?(blob) ⇒ Boolean

[ GitHub ]

  
# File 'activestorage/lib/active_storage/previewer/video_previewer.rb', line 8

def accept?(blob)
  blob.video? && ffmpeg_exists?
end

.ffmpeg_path

[ GitHub ]

  
# File 'activestorage/lib/active_storage/previewer/video_previewer.rb', line 18

def ffmpeg_path
  ActiveStorage.paths[:ffmpeg] || "ffmpeg"
end

Instance Method Details

#preview(**options)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/previewer/video_previewer.rb', line 23

def preview(**options)
  download_blob_to_tempfile do |input|
    draw_relevant_frame_from input do |output|
      yield io: output, filename: "#{blob.filename.base}.jpg", content_type: "image/jpeg", **options
    end
  end
end