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 Core Image. Furthermore, you can use the library to play audio in PlotDevice, make audio selections, and control the volume and rate from your script.
Last updated for NodeBox 1.9.0
Author: Tom De Smedt
Put the downloaded quicktime folder in ~/Library/Application Support/PlotDevice/ or in the same folder as your script so PlotDevice can find the library. Then import the library in your script:
quicktime = ximport("quicktime")
The library has a movie() command that opens a movie from a given location. You can open any type of movie you could normally open with the Quicktime application:
The command returns a Movie object with a number of useful properties:
The returned movie object has two methods to grab image frames:
movie.frames(n=10, start=0, stop=None)
The frame() method returns a MovieFrame object with image data at the given time (in seconds) in the movie. The frames() command returns a list of n MovieFrame objects between the given start and stop time (in seconds). The start and stop parameters are optional.
A movie frame object has the following properties:
Displaying frames in PlotDevice is really very easy. The following script loops through all the frames in an animation:
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)
The Quicktime library and the Core Image library play really well together. A MovieFrame object returned from movie.frame() or the movie.frames() list can be passed to the canvas.layer() method in Core Image. Then you can apply all sorts of filters and effects to it:
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()
The library has an audio() command that opens a sound from a given location. You can open any type of sound you could normally open with the Quicktime application:
The command returns an Audio object with a number of useful properties:
The returned audio object also has a number of methods that control the playback:
The audio.is_playing() method returns True as long as the sound is playing in PlotDevice. While the sound is playing you can adjust its volume and rate. It will begin playing at its time property. The audio.reset() method resets the volume, time and rate to the default values (0, 0 and 1 respectively).
The library does not have any functionality to export audio from PlotDevice.
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 Movie and the Audio object have a selection() method:
It returns a new movie or a new audio object ranged between the given start and stop time. For example, here’s how to create a short loop from an audio fragment:
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()