Class: Editframe::VideoClip

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ VideoClip

Returns a new instance of VideoClip.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/editframe/video/clip.rb', line 6

def initialize(source, options = {})
  @id = Util.uuid
  @form = {}
  @filters = []
  @layers = []
  @options = options || { }
  @resolution = { width: nil, height: nil }
  @trim = { start: 0, end: nil }
  @volume = 1.0
  configure_source source
end

Instance Attribute Details

#layersObject (readonly)

Returns the value of attribute layers.



4
5
6
# File 'lib/editframe/video/clip.rb', line 4

def layers
  @layers
end

Instance Method Details

#encodeObject



60
61
62
63
# File 'lib/editframe/video/clip.rb', line 60

def encode
  @form[:config] = Faraday::ParamPart.new(generate_config, 'application/json')
  Editframe::Video.encode_from_clip(@form)
end

#filter(name, options = {}) ⇒ Object



18
19
20
21
# File 'lib/editframe/video/clip.rb', line 18

def filter(name, options = {})
  @filters.push({ :name => name, :options => { **options } })
  self
end

#muteObject



55
56
57
58
# File 'lib/editframe/video/clip.rb', line 55

def mute 
  set_volume 0 
  self
end

#resize(resolution) ⇒ Object



23
24
25
26
27
# File 'lib/editframe/video/clip.rb', line 23

def resize(resolution)
  return unless !resolution.nil?
  set_resolution resolution
  self
end

#set_resolution(resolution) ⇒ Object



29
30
31
32
33
34
# File 'lib/editframe/video/clip.rb', line 29

def set_resolution(resolution)
  return unless !resolution.nil?
  values = resolution.split('x')
  @resolution = { width: values[0].to_i, height: values[1].to_i }
  self
end

#set_volume(volume) ⇒ Object



36
37
38
39
40
41
# File 'lib/editframe/video/clip.rb', line 36

def set_volume(volume)
  @volume = volume.to_f
  if volume > 1 then @volume = 1.0 end
  if volume < 1 then @volume = 0.0 end
  self
end

#trim(trim_start, trim_end) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/editframe/video/clip.rb', line 43

def trim(trim_start, trim_end)
  @trim[:start] = trim_start
  @trim[:end] = trim_end
  if @trim[:start] < 0 
    @trim[:start] = 0
  end
  if @trim[:end] < 0 
    @trim.delete(:end)
  end
  self
end