Class: VideoScreenshoter::Hls

Inherits:
Abstract
  • Object
show all
Defined in:
lib/video_screenshoter/hls.rb

Instance Attribute Summary

Attributes inherited from Abstract

#duration, #exact, #ffmpeg, #imagemagick, #input, #offset_end, #offset_start, #output_dir, #output_file, #presets, #size, #times, #verbose

Instance Method Summary collapse

Methods inherited from Abstract

#ffmpeg_command, #ffmpeg_run, #imagemagick_command, #imagemagick_run, #output_fullpath, #output_with_preset

Constructor Details

#initialize(params) ⇒ Hls

Returns a new instance of Hls.



6
7
8
# File 'lib/video_screenshoter/hls.rb', line 6

def initialize params
  super
end

Instance Method Details

#runObject Also known as: make_screenshots, make_thumbnails



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/video_screenshoter/hls.rb', line 10

def run
  chunk_limits = []
  chunks.inject(0.0) do |time, chunk|
    chunk_limits.push({:start => time, :end => time + chunk.first, :path => chunk.last})
    time + chunk.first
  end
  threads = []
  times.each do |time|
    threads << Thread.new do
      if chunk_limit = chunk_limits.select { |c| time >= c[:start] && time <= c[:end] }.first
        path = File.join(File.dirname(input), chunk_limit[:path])
        rel_time = time - chunk_limit[:start]
        cmd = ffmpeg_command(path, output_fullpath(time), rel_time)
        puts cmd if verbose
        `#{cmd}`
        imagemagick_run output_fullpath(time)
      else
        puts "Time #{time} is incorrect" if verbose
      end
    end
  end
  threads.each { |t| t.join  }
end