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.

#capture,
#download_blob_to_tempfile

Downloads the blob to a tempfile on disk.

#draw

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

#instrument, #logger, #open_tempfile, #service_name, #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 unless @ffmpeg_exists.nil?

  @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

#draw_relevant_frame_from(file, &block) (private)

[ GitHub ]

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

def draw_relevant_frame_from(file, &block)
  draw self.class.ffmpeg_path, "-i", file.path, *Shellwords.split(ActiveStorage.video_preview_arguments), "-", &block
end

#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