-
Notifications
You must be signed in to change notification settings - Fork 2
/
of.movietexture.pd
102 lines (102 loc) · 6.16 KB
/
of.movietexture.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#N canvas 232 23 922 755 12;
#X obj 15 3 inlet;
#X obj 15 1093 outlet;
#X obj 94 2 inlet;
#X obj 454 1091 outlet;
#X msg 94 23 frame \$1;
#X text 754 1092 RI;
#X obj 894 1092 outlet;
#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 obj 15 45 ofelia d -c13 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 \, vtex\$0 \, vpix\$0 = ofVideoPlayer() \, ofTexture()
\, ofPixels() \; function M.new() \; ofWindow.addListener("setup" \,
this) \; if ofWindow.exists then vtex\$0:allocate(1 \, 1 \, GL_RGBA)
end \; 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 M.update()
\; end \; function M.free() \; ofWindow.removeListener("setup" \, this)
\; videoplayer\$0:close() end \; \; function M.setup() if ofWindow.exists
then vtex\$0:allocate(1 \, 1 \, GL_RGBA) if filename ~= nil then M.open(filename)
M.update() 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.allocate(l) vtex\$0:allocate(table.unpack(l))
end \; function M.update() videoplayer\$0:update() end \; function
M.play() if speed > 0 then videoplayer\$0:setFrame(min) else videoplayer\$0:setFrame(max)
end \; function M.float(f) if f == 1 then M.play() else M.stop() end
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.speed(f) speed = f videoplayer\$0:setSpeed(speed)
end \; function M.frame(float) videoplayer\$0:setFrame(float) end \;
function M.position(f) position = f videoplayer\$0:setPosition(position)
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.volume(float)
videoplayer\$0:setVolume(float) end \; function M.loop(float) loop
= float end \; function M.close() videoplayer\$0:close() print ("[of.movie]
: Closed \, need to open a file...") end \; function M.fill(l) vpix\$0:setColor(ofColor(table.unpack(l)))
M.pix2tex() end \; function M.setimagetype(float) vpix\$0:setImageType(float)
end \; function M.draw(l) dimg = ofTable(table.unpack(l)) end \; function
M.drawsubsection(l) dsimg = ofTable(table.unpack(l)) end \; function
M.anchorpoint(l) vtex\$0:setAnchorPoint(table.unpack(l)) end \; function
M.mirror(l) vpix\$0:mirror(l[1]==1 \, l[2]==1) M.pix2tex() end \; function
M.rotate(i) vpix\$0:rotate90(i) M.pix2tex() end \; function M.pix2tex()
vpix\$0 = videoplayer\$0:getPixels() vtex\$0:loadData(vpix\$0) end
\; function M.resize(l) vpix\$0:resize(l[1] \, l[2]) M.allocate (ofTable(l[1]
\, l[2] \, GL_RGBA)) M.update() end \; function M.crop(l) vpix\$0:crop(table.unpack(l))
M.update() end \; function M.cropfrom(l) vpix\$0:cropfrom(image\$0
\, l[1] \, l[2] \, l[3] \, l[4]) end \; function M.setpixel(l) vpix\$0:setColor(l[1]
\, l[2] \, ofColor(table.unpack(l \, 3 \, #l))) M.pix2tex() end \;
function M.getpixel(l) local p = vpix\$0:getColor(l[1] \, l[2]) outlet:outletList(1
\, ofTable( p.r \, p.g \, p.b \, p.a)) end \; function M.get() outlet:outletList(2
\, 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 videoplayer\$0:isFrameNew() then
M.pix2tex() end \; 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 \; vtex\$0:bind() \; outlet:outletBang(0)
\; if dimg[1] == 1 then vtex\$0:draw(table.unpack(dimg \, 2 \, #dimg))
end \; if dsimg[1] == 1 then vtex\$0:drawSubsection(table.unpack(dsimg
\, 2 \, #dsimg)) end \; vtex\$0:unbind() \; end \;;
#X f 126;
#X connect 0 0 8 0;
#X connect 2 0 4 0;
#X connect 4 0 8 0;
#X connect 8 0 1 0;
#X connect 8 1 3 0;
#X connect 8 2 6 0;