Tutorial 4: Controlling Movie Playback
This tutorial expands on what we've learned thus far about playing back movies in Jitter. We'll learn how to get some useful information about the movie that you're playing, as well as how to manipulate the playback of the movie by changing its speed, volume, and loop points.
The two Jitter objects in this patch should already be familiar to you: jit.movie and jit.pwindow. The rest of the patch will let you experiment with changing the playback behavior of the movie you have loaded into the jit.movie object.
The left side of the patch should seem very familiar to you from the very first tutorial:
The movie clip should begin playing as soon as it is read into the jit.movie object. Since this movie has a soundtrack, you should begin to hear some music as soon as the movie is loaded. The movie soundtrack will come out of computer's built-in sound system, not MSP. If you do not wish to hear the soundtrack, you can change the number above the message box that says vol $1 to .
You won't see anything in the jit.pwindow because, even though the movie is playing, the jit.movie object needs a message to send a matrix out to the jit.pwindow. Start the metro object by clicking on the toggle box connected to its inlet. You will see the movie's image appear in the jit.pwindow object. Don't worry about the message yet; we'll get to that below.
Obtaining Some Information About the Movie
When a jit.movie object opens a new movie, it reads in a lot of information (contained in the movie's header) about the movie, including how long it is, how many frames of video are in the movie, and how fast it is meant to be played. We will use this metadata to control the movie's playback.
The first thing we want to do with this movie is read the metadata attributes. It can be retrieved by sending jit.movie. We then parse the messages the object sends out its rightmost outlet in response. The information we need is the frame rate, the time scale (how many "QuickTime time units" in a second), the duration (in QuickTime units), the playback rate, and the volume. This is all gathered by a message box with .messages to
When you tell a jit.movie to open a movie for playback (by sending it the message), the object sends a message out its right outlet to tell you that it has found your movie and understood how to play it. If you were to connect a print object to the right outlet of the jit.movie in the patch and reload the movie in the patch, you would see the following printed in the Max Console: . In this patch, there is a route object connected to the right outlet of jit.movie. That route will catch a read message and pass it to an unpack and select that will trigger the message after a successful load. If for some reason the object can't locate the crashtest.mov file, you will see a number other than 1 after the name of the file, and no request will be made.
In addition to catching the route object distributes the movie information as it arrives. Jitter attributes are always output by objects in the same format that you would set them with in your patch: the name of the attribute followed by whatever information the object needs to set that attribute.There are number boxes attached to the route outlets to display the requested values. We don't know what those mean yet, but this mechanism will display the attributes every time we successfully load in a new movie into the jit.movie object.message the
Starting, Stopping, and Slowing Down
The top of the tutorial patch contains some controls to change the playback behavior of the jit.movie object. Sending a message to jit.movie will freeze the movie's playback at the current point in the movie. Sending a message will resume playback where you last left off. Any soundtrack that exists in the movie file will stop playing when the movie's playback is halted. Stopping and starting the movie has no effect on the jit.movie object's matrix output, which is still controlled by the metro object. If you the movie with the metro on, you will still receive a new matrix at the rate of the metro object (in this case, 25 times per second), even though all the matrices will be the same.
Changing the jit.movie object takes a floating-point number as the argument to its attribute, so a value of will make the movie play at half speed, and a value of will make the movie play backwards at a bit more than double speed. If you play around with this value, you will note that the soundtrack will speed up, slow down, and play backwards to remain in sync with the video. Once the movie reaches its last frame (or first frame, if you're playing it backwards), it will to the opposite end of the file. This behavior can be changed by setting the attribute of the jit.movie object with a value of (no looping), (regular looping), or (palindrome looping).of the movie will change the speed at which it plays back its video and audio content. Positive values will make the movie go forward, with a value of signifying normal playback speed. Negative values will make the movie go backwards. A rate of will stop the movie. The
Theattribute controls the volume (loudness) of any soundtrack component the movie has. A value of equals full volume, and a value of will turn the sound off.
In this patch, both the message box in the middle of the patch when the film is loaded. This way they will reflect the values stored in each new movie.and the attributes are initialized by the
Time is on My Side
The first three attributes we queried, jit.movie object the (1200 time units divided by a of 600 units/second gives us 2 seconds)., , and , tell us about how the movie file deals with timing. The attribute tells us the total length of the movie. This value is not expressed in milliseconds or frames, but in QuickTime time units. The actual length of each time unit depends on the of the movie. The movie's is the timing resolution of the movie per second. Dividing the of a movie by its will tell you the approximate length of the movie, in seconds. Our crashtest.mov file, for example, has a of 2836 time units and a of 600. The movie should run for about 4.73 seconds. If we want to move two seconds into the movie, we could set the
The jit.movie object with the message, but then we wouldn't get to do the fun math!, or frames per second, of a movie tells us how many individual video images are shown every second. The higher the of a movie, the smoother the apparent motion of the movie will be (assuming, that is, that the individual frames are all in some way unique). Some common rates are 15, 24, 29.97, and 30. Our movie file in this example runs at 15 frames per second, which works out to a new frame of video every 40 time units, or about every 66.7 milliseconds. If we divide the duration of crashtest.mov by the number of time units per frame in the movie, we can determine that the movie file has 70 frames. If we wanted to, we could get the total number of frames in the movie by querying the
Scrubbing and Looping
The area at the bottom of the patch contains two controls for further manipulating the movie's playback. The number box on the left displays the frame that the movie is currently playing. This value is being updated by the message sent into the jit.movie object by the metro object at the top of the patch; each time a new frame is output the time is updated. If you stop the movie's transport (by sending jit.movie a message), you can "scrub" through the movie by dragging on the number box. The movie will jump to the frame specified as an argument to the message.
Loop points (pairs of time values which specify the beginning and end of a loop) can be sent to a jit.movie object by setting the attribute with two integer arguments. The rslider in the tutorial patch lets you select regions of the movie that the jit.movie object will loop between. The size of the rslider has been set to the of the movie through the attribute query we performed when the movie was loaded. You can reset loop points by sending jit.movie a message with no arguments (an example of this is at the top of the patch, along with a query message that highlights the entire rslider).
The jit.movie object offers a number of simple attributes that allow you to change the way QuickTime content is played. You can and movie playback with those messages. The attribute lets you change the speed and direction of movie playback. You can control the volume of a movie's soundtrack with the attribute.
You can get important information about the current movie loaded into the jit.movie object by querying attributes such as , , and . You can go to specific frames in a movie with the message, and you can set and retrieve for the movie. You can query the current time position of a movie by sending jit.movie a message.
More powerful functions, such as editing and saving movies, can be accomplished and will be discussed in later tutorials.
|Working with Video in Jitter||Working with Video in Jitter|
|Video and Graphics 01: Display a Video||Video and Graphics 1: Display a Video|
|jit.movie||Play a movie|
|metro||Output a bang message at regular intervals|
|pack||Create a list|
|route||Select outlet based on input matching|
|unpack||Break a list into individual messages|