Class: WGif::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/wgif/video.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, filepath) ⇒ Video

Returns a new instance of Video.



8
9
10
11
12
13
14
# File 'lib/wgif/video.rb', line 8

def initialize(name, filepath)
  @name = name
  @clip = FFMPEG::Movie.new(filepath)
  FileUtils.mkdir_p '/tmp/wgif/'
  @logger = Logger.new("/tmp/wgif/#{name}.log")
  FFMPEG.logger = @logger
end

Instance Attribute Details

#clipObject

Returns the value of attribute clip.



6
7
8
# File 'lib/wgif/video.rb', line 6

def clip
  @clip
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/wgif/video.rb', line 6

def logger
  @logger
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/wgif/video.rb', line 6

def name
  @name
end

Instance Method Details

#to_frames(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/wgif/video.rb', line 26

def to_frames(options = {})
  make_frame_dir
  if options[:frames]
    framerate = options[:frames] / @clip.duration
  else
    framerate = 24
  end
  transcode(@clip, "/tmp/wgif/frames/\%5d.png", "-vf fps=#{framerate}")
  open_frame_dir
end

#trim(start_timestamp, duration) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/wgif/video.rb', line 16

def trim(start_timestamp, duration)
  options = {
    audio_codec: 'copy',
    video_codec: 'copy',
    custom: "-ss #{start_timestamp} -t 00:00:#{format('%06.3f', duration)}"
  }
  transcode(@clip, "/tmp/wgif/#{@name}-clip.mov", options)
  WGif::Video.new "#{@name}-clip", "/tmp/wgif/#{@name}-clip.mov"
end