-
Notifications
You must be signed in to change notification settings - Fork 2
/
of.movie.pd
84 lines (84 loc) · 4.92 KB
/
of.movie.pd
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
#N canvas 344 23 936 755 12;
#X obj 15 3 inlet;
#X obj 15 937 outlet;
#X obj 94 2 inlet;
#X obj 895 941 outlet;
#X msg 94 23 frame \$1;
#N canvas 212 320 563 390 Notes 0;
#X text 32 117 https://forum.openframeworks.cc/t/autoplay-behaviour-of-ofvideoplayer/35905
;
#X text 15 75 - Blank picture after windows re-creation (temp fix:
re-open in setup), f 70;
#X text 14 21 - Current frames returns a negative value on the last
frame (temp fix is to do ofClamp), f 71;
#X text 15 95 - Always autoplay after loading a file pb (OSX but not
on windows):, f 70;
#X text 14 56 - play backward have some jittery frames (might depends
on codec?), f 71;
#X text 10 253 With audio and smooth framerate:;
#X text 10 313 Without audio and smooth framerate:;
#X text 9 223 - Good ffmpeg encoding example:;
#X text 11 160 - For smooth playback and frame by frame \, set every
frame as keyframe in your video exporter or use PhotoJPG/Animation/Mjpeg
codec., f 72;
#X text 13 282 ffmpeg -i input.mp4 -vcodec libx264 -x264-params keyint=1
output.mp4, f 75;
#X text 10 332 ffmpeg -i input.mp4 -vcodec libx264 -an -x264-params
keyint=1 output.mp4, f 75;
#X restore 187 10 pd Notes;
#X text 831 929 RI;
#X obj 15 45 ofelia d -c12 videoplayer-\$0 \; local canvas = ofCanvas(this)
\; local args = canvas:getArgs() \; local outlet = ofOutlet(this) \;
local filename \, start \, loop \, speed \, position = args[1] \, args[2]
\, args[3] \, args[4] \, args[5] \; local loaded \, play \, min \,
max \, dimg \, dsimg = 0 \, 0 \, 0 \, 1 \, ofTable() \, ofTable() \;
\; local videoplayer\$0 = ofVideoPlayer() \; \; function M.new() \;
ofWindow.addListener("setup" \, this) \; if args[4] == nil then speed
= 1 end \; if args[1] == nil then print("[of.movie] : No file") else
M.open(filename) end \; if args[2] == nil then start = 0 end \; if
args[3] == nil then loop = 0 end end \; \; function M.free() \; videoplayer\$0:close()
\; ofWindow.removeListener("setup" \, this) end \; \; function M.setup()
if ofWindow.exists then if filename ~= nil then M.open(filename) end
end end \; \; function M.open(string) ofSetDataPathRoot(ofCanvas(this
\, 1):getDir()) filename = string \; if ofWindow.exists then videoplayer\$0:close()
videoplayer\$0:load(filename) end \; if start == 1 then print(speed)
videoplayer\$0:setSpeed(speed) else videoplayer\$0:setSpeed(0) end
\; if (videoplayer\$0:isLoaded()) then max = videoplayer\$0:getTotalNumFrames()
print("loaded " .. filename)end end \; function M.update() videoplayer\$0:update()
end \; function M.float(f) if f == 1 then M.play() else M.stop() end
end \; function M.play() if speed > 0 then videoplayer\$0:setFrame(min)
else videoplayer\$0:setFrame(max) end \; videoplayer\$0:setSpeed(speed)
videoplayer\$0:play() end \; function M.stop() videoplayer\$0:stop()
end \; function M.pause() videoplayer\$0:setPaused(true) end \; function
M.resume() videoplayer\$0:setPaused(false) end \; function M.speed(f)
speed = f if videoplayer\$0:isPlaying() then videoplayer\$0:setSpeed(speed)
else videoplayer\$0:setPaused(true) end end \; function M.frame(float)
videoplayer\$0:setFrame(float) end \; function M.range(list) min =
list[1] max = list[2] if videoplayer\$0:isPlaying() then videoplayer\$0:setFrame(min)
end end \; function M.fullrange() min = 0 max = videoplayer\$0:getTotalNumFrames()
end \; function M.position(f) position = f videoplayer\$0:setPosition(position)
end \; function M.volume(float) videoplayer\$0:setVolume(float) end
\; function M.loop(float) loop = float end \; function M.close() videoplayer\$0:close()
end \; function M.draw(l) dimg = ofTable(table.unpack(l)) end \; function
M.anchorpoint(l) videoplayer\$0:setAnchorPoint(table.unpack(l)) end
\; function M.get() outlet:outletList(1 \, ofTable(videoplayer\$0:isLoaded()
\, videoplayer\$0:isPlaying() \, ofClamp(videoplayer\$0:getCurrentFrame()
\, 0 \, videoplayer\$0:getTotalNumFrames()) \, videoplayer\$0:getTotalNumFrames()
\, videoplayer\$0:getWidth() \, videoplayer\$0:getHeight() \, videoplayer\$0:getWidth()/videoplayer\$0:getHeight()
\, videoplayer\$0:getDuration() \, videoplayer\$0:getTotalNumFrames()/videoplayer\$0:getDuration()))
end \; \; function M.bang() \; if loop == 0 then videoplayer\$0:setLoopState(OF_LOOP_NONE)
end \; if loop == 1 then videoplayer\$0:setLoopState(OF_LOOP_NORMAL)
end \; if loop == 2 then videoplayer\$0:setLoopState(OF_LOOP_PALINDROME)
end \; videoplayer\$0:update() \; if speed > 0 and videoplayer\$0:getCurrentFrame()
>= max then videoplayer\$0:setPaused(true) if loop == 1 then videoplayer\$0:setFrame(min)
videoplayer\$0:setPaused(false) end end \; if speed < 0 and videoplayer\$0:getCurrentFrame()
<= min then videoplayer\$0:setPaused(true) if loop == 1 then videoplayer\$0:setFrame(max)
videoplayer\$0:setPaused(false) end end \; videoplayer\$0:bind() \;
outlet:outletBang(0) \; if dimg[1] == 1 then videoplayer\$0:draw(table.unpack(dimg
\, 2 \, #dimg)) end \; videoplayer\$0:unbind() \; end \;;
#X f 126;
#X connect 0 0 7 0;
#X connect 2 0 4 0;
#X connect 4 0 7 0;
#X connect 7 0 1 0;
#X connect 7 1 3 0;