Class: Jani::StripMaker::Movie

Inherits:
Object
  • Object
show all
Includes:
Magick
Defined in:
lib/jani/strip_maker/movie.rb

Constant Summary collapse

FILE_NAME_PATTERN =
"frame%4d"
FILE_NAME_EXTENTION =
"jpg"

Instance Method Summary collapse

Constructor Details

#initialize(movie_filepath: "", transcode_options: nil) ⇒ Movie

Returns a new instance of Movie.



10
11
12
13
14
15
16
# File 'lib/jani/strip_maker/movie.rb', line 10

def initialize(movie_filepath: "", transcode_options: nil)
  raise "Specify file path of movie and transcode options" if movie_filepath.empty? || transcode_options.nil?

  @movie_filepath = (movie_filepath)
  @transcode_options = transcode_options
  @_frame_list = []
end

Instance Method Details

#to_frame_listObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jani/strip_maker/movie.rb', line 18

def to_frame_list
  return @_frame_list unless @_frame_list.empty?
  movie_full_path = movie_full_path()
  Dir.mktmpdir do |tmp_dir|
    Dir.chdir(tmp_dir) do |dir|
      execute_ffmpeg_command(movie_full_path)
      images = ImageList.new(*Dir.glob("*\.#{FILE_NAME_EXTENTION}")).sort_by(&:filename)
      # TODO: raise error if images is empty
      @_frame_list = Jani::StripMaker::FrameList.new(images: images)
    end
  end
end

#to_stripsObject



31
32
33
# File 'lib/jani/strip_maker/movie.rb', line 31

def to_strips
  to_frame_list().to_strips()
end