Class: Jwthumbs::Vtt

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

Instance Method Summary collapse

Constructor Details

#initialize(movie, spritefile, images_count, coords, gridsize) ⇒ Vtt

Returns a new instance of Vtt.



4
5
6
7
8
9
# File 'lib/vtt.rb', line 4

def initialize(movie, spritefile, images_count, coords, gridsize)
	@movie = movie
	create(movie, spritefile, images_count, coords, gridsize)
	clear_files if @movie.clear_files

end

Instance Method Details

#create(movie, spritefile, images_count, coords, gridsize) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vtt.rb', line 11

def create(movie, spritefile, images_count, coords, gridsize)
	whxy = coords.split(/\+([^.]*)$/)
	w,h = whxy.first.split("x").map {|x| x.to_i}
	x,y = whxy.last.split("+").map {|x| x.to_i}
	thumb_rate = movie.seconds_between
	count = images_count

	vtt = ["WEBVTT",""]
	clipstart = 0
	clipend = clipstart + thumb_rate
	
	count.times do |x|
		x = x+1
		xywh = get_grid_coordinates(x,gridsize,w,h)
		start = get_time_str(clipstart)
		clip_end = get_time_str(clipend)
		vtt.push("#{start} --> #{clip_end}")
		vtt.push("#{spritefile}#xywh=#{xywh}")
		vtt.push("")
		clipstart = clipend
		clipend = clipend + thumb_rate
	end
	 
		vtt_path = movie.outdir+"/"+movie.vttfile
		File.open(vtt_path, 'w+') do |f|
		 	f.write(vtt.join("\n")) 
  
	end
 
end