-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_videos.lua
More file actions
197 lines (164 loc) · 5.15 KB
/
module_videos.lua
File metadata and controls
197 lines (164 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
local utils = require "utils"
local raw = sys.get_ext "raw_video"
local M = {}
local video_idx = 0
local black = resource.create_colored_texture(0,0,0,1)
local videos = {}
local vidlist = {}
local function update_list()
vidlist = {}
for filename, file in pairs(videos) do
vidlist[#vidlist+1] = file
end
pp(vidlist)
end
local function updated_content(filename)
if filename:sub(1, 4) == "vid_" then
videos[filename] = resource.open_file(filename)
update_list()
end
end
local hid_update = node.event("content_update", updated_content)
local hid_remove = node.event("content_remove", function(filename)
if videos[filename] then
videos[filename]:dispose()
videos[filename] = nil
update_list()
end
end)
function M.unload()
node.event_remove(hid_update)
node.event_remove(hid_remove)
end
function M.can_schedule(options)
return #options.videos > 0
end
function M.prepare(options)
local video
video, video_idx = utils.cycled(options.videos, video_idx)
return video.duration, {
file = resource.open_file(video.file),
raw = video.raw,
text = video.text,
}
end
function M.run(duration, args, fn)
local text_size = 70
local text_w = res.font:width(args.text, text_size)
local text_x = utils.make_smooth{
{t = 0, val = WIDTH-200},
{t = 1, val = WIDTH - text_w - 200},
{t = duration-1, val = WIDTH - text_w - 200},
{t = duration, val = WIDTH - text_w},
}
local text_y = utils.make_smooth{
{t = 0, val = HEIGHT},
{t = 1, val = 90},
{t = duration-1, val = 90},
{t = duration, val = -500},
}
local text_r = utils.make_smooth{
{t = 0, val = 90},
{t = 1, val = 10},
{t = 2, val = 10},
{t = duration-1, val = 5},
{t = duration, val = 180},
}
if args.raw then
local vid = raw.load_video{
file = args.file:copy(),
paused = true,
}
for now in fn.wait_next_frame do
local state, err = vid:state()
if state == "loaded" then
break
elseif state == "error" then
error("preloading failed: " .. err)
end
end
local _, w, h = vid:state()
local x = utils.make_smooth{
{t = 0, val = WIDTH},
{t = 1, val = (WIDTH-w)/2, ease='step'},
{t = duration-1, val = (WIDTH-w)/2},
}
local y = utils.make_smooth{
{t = 0, val = 300},
{t = 1, val = (HEIGHT-h)/2, ease='step'},
{t = duration-1, val = (HEIGHT-h)/2},
{t = duration, val = HEIGHT+100},
}
fn.wait_t(0)
Sidebar.hide(duration-1)
-- Fadeout.fade(duration-1)
for now in fn.upto_t(duration) do
if now > 1 then
vid:start()
end
local x, y = x(now), y(now)
vid:target(x, y, x+w, y+h):layer(-1)
gl.pushMatrix()
gl.translate(text_x(now), text_y(now))
gl.rotate(text_r(now), 0, 1, 0)
black:draw(-10, -10, text_w+10, text_size+10, 0.6)
res.font:write(0, 0, args.text, text_size, 1,1,1,1)
gl.popMatrix()
end
vid:dispose()
return true
else
local x = utils.make_smooth{
{t = 0, val = 600},
{t = 1, val = 50},
{t = duration-1, val = 50},
{t = duration, val = -1000},
}
local y = utils.make_smooth{
{t = 0, val = 300},
{t = 1, val = 0},
{t = duration-1, val = 20},
{t = duration, val = 900},
}
local rotate = utils.make_smooth{
{t = 0, val = 90},
{t = 1, val = -10},
{t = 2, val = -10},
{t = duration-1, val = -5},
{t = duration, val = -180},
}
local scale = utils.make_smooth{
{t = 0, val = 0},
{t = 1, val = 0.94},
{t = duration-1, val = 0.90},
{t = duration, val = 0},
}
local vid = resource.load_video{
file = args.file:copy(),
paused = true,
}
fn.wait_t(0)
Sidebar.hide(duration-1)
-- Fadeout.fade(duration-1)
for now in fn.upto_t(duration) do
if now > 1 then
vid:start()
end
gl.pushMatrix()
gl.rotate(rotate(now), 0, 1, 0)
gl.translate(x(now), y(now))
local scale = scale(now)
util.draw_correct(vid, 0, 0, WIDTH*scale, HEIGHT*scale)
gl.popMatrix()
gl.pushMatrix()
gl.translate(text_x(now), text_y(now))
gl.rotate(text_r(now), 0, 1, 0)
black:draw(-10, -10, text_w+10, text_size+10, 0.5)
res.font:write(0, 0, args.text, text_size, 1,1,1,1)
gl.popMatrix()
end
vid:dispose()
return true
end
end
return M