Sha256: 7fc87bf09eeafef13c2a1b4fb76c496c0a1f71fddd1588ccfbea4c21e2c98340

Contents?: true

Size: 948 Bytes

Versions: 21

Compression:

Stored size: 948 Bytes

Contents

# frozen_string_literal: true

require "shellwords"

module ActiveStorage
  class Previewer::VideoPreviewer < Previewer
    class << self
      def accept?(blob)
        blob.video? && ffmpeg_exists?
      end

      def ffmpeg_exists?
        return @ffmpeg_exists unless @ffmpeg_exists.nil?

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

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

    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

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

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
activestorage-8.0.1 lib/active_storage/previewer/video_previewer.rb
activestorage-8.0.0.1 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.2.1 lib/active_storage/previewer/video_previewer.rb
activestorage-8.0.0 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.2 lib/active_storage/previewer/video_previewer.rb
activestorage-8.0.0.rc2 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.1.2 lib/active_storage/previewer/video_previewer.rb
activestorage-8.0.0.rc1 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.1.1 lib/active_storage/previewer/video_previewer.rb
activestorage-8.0.0.beta1 lib/active_storage/previewer/video_previewer.rb
omg-activestorage-8.0.0.alpha9 lib/active_storage/previewer/video_previewer.rb
omg-activestorage-8.0.0.alpha8 lib/active_storage/previewer/video_previewer.rb
omg-activestorage-8.0.0.alpha7 lib/active_storage/previewer/video_previewer.rb
omg-activestorage-8.0.0.alpha4 lib/active_storage/previewer/video_previewer.rb
omg-activestorage-8.0.0.alpha3 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.1 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.0 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.0.rc1 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.0.beta3 lib/active_storage/previewer/video_previewer.rb
activestorage-7.2.0.beta2 lib/active_storage/previewer/video_previewer.rb