Class: Kithe::FfmpegExtractJpg

Inherits:
Object
  • Object
show all
Defined in:
app/derivative_transformers/kithe/ffmpeg_extract_jpg.rb

Overview

Creates a JPG screen capture using ffmpeg, by default with the thumbnail filter to choose a representative frame from the first minute or so.

the derivative created, ffmpeg version and args:

@example tempfile = FfmpegExtractJpg.new(start_seconds: 10, width_pixels: 420).call(shrine_uploaded_file, add_metadata: my_hash)

Examples:

tempfile = FfmpegExtractJpg.new.call(shrine_uploaded_file)


tempfile = FfmpegExtractJpg.new.call(url)


tempfile = FfmpegExtractJpg.new(start_seconds: 60).call(shrine_uploaded_file)


tempfile = FfmpegExtractJpg.new(start_seconds: 10, width_pixels: 420).call(shrine_uploaded_file)


you can also provide a Hash which will be mutated with metadata relevant to


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_seconds: 0, frame_sample_size: false, width_pixels: nil) ⇒ FfmpegExtractJpg

Returns a new instance of FfmpegExtractJpg.

Parameters:

  • start_seconds (Integer) (defaults to: 0)

    seek to this point to find thumbnail. If it’s after the end of the video, you won’t get a thumb back though! [Default 0]

  • frame_sample_size (Integer, false, nil) (defaults to: false)

    argument passed to ffmpeg thumbnail filter, how many frames to sample, starting at start_seconds, to choose representative thumbnail. If set to false, thumbnail filter won’t be used. If this one goes past the end of the video, ffmpeg is fine with it. Set to false to disable use of ffmpeg sample feature, and just use exact frame at start_seconds.

    NOTE: This can consume significant RAM depending on value and video resolution.

    Default false, not operative


36
37
38
39
40
# File 'app/derivative_transformers/kithe/ffmpeg_extract_jpg.rb', line 36

def initialize(start_seconds: 0, frame_sample_size: false, width_pixels: nil)
  @start_seconds = start_seconds
  @frame_sample_size = frame_sample_size
  @width_pixels = width_pixels
end

Instance Attribute Details

#frame_sample_sizeObject (readonly)

Returns the value of attribute frame_sample_size.



17
18
19
# File 'app/derivative_transformers/kithe/ffmpeg_extract_jpg.rb', line 17

def frame_sample_size
  @frame_sample_size
end

#start_secondsObject (readonly)

Returns the value of attribute start_seconds.



17
18
19
# File 'app/derivative_transformers/kithe/ffmpeg_extract_jpg.rb', line 17

def start_seconds
  @start_seconds
end

#width_pixelsObject (readonly)

Returns the value of attribute width_pixels.



17
18
19
# File 'app/derivative_transformers/kithe/ffmpeg_extract_jpg.rb', line 17

def width_pixels
  @width_pixels
end

Instance Method Details

#call(input_arg, add_metadata: nil) ⇒ Object

Parameters:

  • input_arg (String, File, Shrine::UploadedFile)

    local File; String that can be URL or local file path; or Shrine::UploadedFile. If Shrine::UploadedFile, we’ll try to get a URL from it if we can, otherwise use or make a local tempfile. Most efficient is if we have a remote URL to give ffmpeg, one way or another!



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/derivative_transformers/kithe/ffmpeg_extract_jpg.rb', line 50

def call(input_arg, add_metadata:nil)
  if input_arg.kind_of?(Shrine::UploadedFile)
    if input_arg.respond_to?(:url) && input_arg.url&.start_with?(/https?\:/)
      _call(input_arg.url, add_metadata: )
    else
      Shrine.with_file(input_arg) do |local_file|
        _call(local_file.path, add_metadata: )
      end
    end
  elsif input_arg.respond_to?(:path)
    _call(input_arg.path, add_metadata: )
  else
    _call(input_arg.to_s, add_metadata: )
  end
end