-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQuicktime.html
More file actions
174 lines (145 loc) · 7.18 KB
/
Copy pathQuicktime.html
File metadata and controls
174 lines (145 loc) · 7.18 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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html><head>
<title></title>
</head><body>
<div class="article">
<h2>Description</h2>
<p>The PlotDevice Quicktime library adds movie (and audio) support to PlotDevice. You can use it to
grab image frames from a movie and display them in PlotDevice or manipulate them with <a href="Core_Image.html">Core Image</a>. Furthermore, you can use the library to play audio in
PlotDevice, make audio selections, and control the volume and rate from your script.<br/></p>
<h2>Download</h2>
<table border="0">
<tbody>
<tr>
<td><a href="http://plotdevice.io/extras/quicktime.zip"><img alt="download" height="20" src="../etc/lib/download.gif" width="20"/></a>
</td><td><a href="http://plotdevice.io/extras/quicktime.zip">quicktime.zip</a>
(1.5MB)<br/>
<em>Last updated for NodeBox 1.9.0<br/></em><em>Author: Tom De Smedt</em><br/>
</td></tr></tbody></table>
<h2>Documentation</h2>
<ul>
<li><a href="#load">How to get the library up and running</a>
</li><li><a href="#movie">Movie frames</a>
</li><li><a href="#coreimage">Movie frames in Core Image</a><br/>
</li><li><a href="#audio">Audio playback</a>
</li><li><a href="#selections">Copying and pasting selections</a>
</li></ul>
<p> </p>
<hr/>
<h2><a id="load" name="load" title="load"></a>How to get the library up and running</h2>
<p>Put the downloaded <em>quicktime</em> folder in <em>~/Library/Application
Support/PlotDevice/</em> or in the same folder as your script so PlotDevice can find the library.
Then import the library in your script:<br/></p>
<pre>quicktime = ximport("quicktime")
</pre>
<hr/>
<h2><a id="movie" name="movie" title="movie"></a>Movie frames</h2>
<p>The library has a <em>movie()</em> command that opens a movie from a given location. You can
open any type of movie you could normally open with the Quicktime application:</p>
<pre>movie(path)
</pre>
<p>The command returns a <em>Movie</em> object with a number of useful properties:</p>
<ul>
<li><em>movie.path</em>: the source path.<br/>
</li><li><em>movie.duration</em>: the length of the movie in seconds.
</li><li><em>movie.has_video</em>: <em>True</em> if the movie has a video track.
</li><li><em>movie.has_audio</em>: <em>True</em> if the movie has an audio track.<br/>
</li><li><em>movie.width</em>: the width of the movie in pixels.
</li><li><em>movie.height</em>: the height of the movie in pixels.
</li></ul>
<p>The returned movie object has two methods to grab image frames:</p>
<pre>movie.frame(time)
</pre>
<pre>movie.frames(n=10, start=0, stop=None)
</pre>
<p>The <em>frame()</em> method returns a <em>MovieFrame</em> object with image data at the
given <em>time</em> (in seconds) in the movie. The <em>frames()</em> command returns a list of
n <em>MovieFrame</em> objects between the given <em>start</em> and stop <em>time</em> (in
seconds). The start and stop parameters are optional.</p>
<p>A movie frame object has the following properties:</p>
<ul>
<li><em>frame.data</em>: the image data which can be passed to the <a href="../ref/Primitives.html#image()">image()</a> command.<br/>
</li><li><em>frame.time</em>: the time where the frame appears in the movie.
</li><li><em>frame.src</em>: the source path of the movie to which this frame belongs.
</li><li><em>frame.width</em>
</li><li><em>frame.height</em>
</li></ul>
<p>Displaying frames in PlotDevice is really very easy. The following script loops through all the
frames in an animation:</p>
<pre>movie = quicktime.movie("twisted_world.mp4")
size(movie.width, movie.height)
speed(50)
def draw():
frame = movie.frame(FRAME*0.1)
image(None, 0, 0, data=frame.data, width=frame.width)
</pre>
<hr/>
<h2><a id="coreimage" name="coreimage" title="coreimage"></a>Movie frames in Core Image</h2>
<p>The Quicktime library and the Core Image library play really well together. A MovieFrame
object returned from <em>movie.frame()</em> or the <em>movie.frames()</em> list can be passed
to the <em>canvas.layer()</em> method in Core Image. Then you can apply all sorts of filters
and effects to it:</p>
<pre>coreimage = ximport("coreimage")
quicktime = ximport("quicktime")
movie = quicktime.movie("twisted_world.mp4")
frame = movie.frame(1.0)
canvas = coreimage.canvas(movie.width, movie.height)
l = canvas.layer(frame)
l.filter_zoomblur()
canvas.draw()
</pre>
<p> </p>
<hr/>
<h2><a id="audio" name="audio" title="audio"></a>Audio playback</h2>
<p>The library has an <em>audio()</em> command that opens a sound from a given location. You
can open any type of sound you could normally open with the Quicktime application:</p>
<pre>audio(path)
</pre>
<p>The command returns an <em>Audio</em> object with a number of useful properties:</p>
<ul>
<li><em>audio.path</em>: the source path.<br/>
</li><li><em>audio</em><em>.duration</em>: the length of the movie in seconds.
</li><li><em>audio</em><em>.has_video</em>: <em>True</em> if the movie has a video track.
</li><li><em>audio</em><em>.has_audio</em>: <em>True</em> if the movie has an audio track.<br/>
</li><li><em>audio.volume</em>: the volume at which the audio is playing (between 0.0 and 2.0).
</li><li><em>audio.time</em>: the current time (in seconds) when the audio is playing.
</li><li><em>audio.rate</em>: the rate or speed at which the audio is playing (between 0.25 and
5.0).
</li><li><em>audio.paused</em>: True when the audio playback is paused, but not stopped.
</li></ul>
<p>The returned audio object also has a number of methods that control the playback:</p>
<pre>audio.play()
</pre>
<pre>audio.stop()
</pre>
<pre>audio.pause()
</pre>
<pre>audio.is_playing()
</pre>
<pre>audio.reset()
</pre>
<p>The <em>audio.is_playing()</em> method returns <em>True</em> as long as the sound is playing
in PlotDevice. While the sound is playing you can adjust its <em>volume</em> and <em>rate</em>. It
will begin playing at its <em>time</em> property. The <em>audio.reset()</em> method resets the
volume, time and rate to the default values (0, 0 and 1 respectively).</p>
<p>The library does not have any functionality to export audio from PlotDevice.</p>
<p> </p>
<hr/>
<h2><a id="selections" name="selections" title="selections"></a>Copying and pasting
selections</h2>
<p>Sometimes you may want to work with a selection of a movie instead of the whole movie, or a
one-second sample of the audio that you are going to loop. For these purposes, both the
<em>Movie</em> and the <em>Audio</em> object have a selection() method:</p>
<pre>media.selection(start=0, stop=None)
</pre>
<p>It returns a new movie or a new audio object ranged between the given <em>start</em> and
<em>stop</em> time. For example, here’s how to create a short loop from an audio fragment:<br/></p>
<pre>audio = quicktime.audio("modron_cube.mp3")
audio = audio.selection(start=0, stop=7.2)
speed(100)
def draw():
if not audio.is_playing:
audio.play()
</pre>
</div>
</body></html>