<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>
<chapter name="Tutorial 23: Controlling Your FireWire Camera">
<setdocpatch name="23jFWCameraControl" patch="23jFWCameraControl.maxpat"/>

<previous name="jitterchapter22">Working with Video Output Components</previous>
<next name="jitterchapter24">QuickTime Effects</next>
<parent name="jitindex">Jitter Tutorials</parent>



<h1>Tutorial 23: Controlling Your FireWire Camera</h1>
<techdetail>
	With Apple's withdrawal of support for quicktime, jit.avc is no longer available on Mac platforms.
</techdetail>
<p>This Tutorial describes how to use Jitter to control the transport of a FireWire-based DV camera or deck using the <o>jit.avc</o> object. This object provides a simple interface for communicating between Jitter and your DV device, and lets you control and automate your FireWire DV device using the Max interface.</p>


<p>AV/C  (an abbreviation for <i>A</i>udio <i>V</i>ideo <i>C</i>ontrol) is the official name for the protocol that communicates between a computer and an external device such as a DV camera. The exact specification used is called the AV/C Tape Recorder / Player Subunit. You can find a copy of the entire specification online at <a href="http://1394ta.org">http://1394ta.org</a>. </p>

<p>The specification breaks the different types of transport controls you can use into three main groups:</p>

<p>1.   The <i>WIND</i> group is used to move the media forward and backward, without playing it. WIND group commands include stop, fast forward and rewind.</p>

<p>2.   The <i>PLAY</i> group contains commands used to play media while moving forward or backward at various speeds. Examples include play, pause, slow forward and slow reverse.</p>

<p>3.   The <i>RECORD</i> group is used to insert data on media.</p>

<p>These three groups are fully implemented in the <o>jit.avc</o> object. Additionally, the object supports a <m>custom</m> message, which lets you send <i>any</i> command to your hardware, even those not directly supported by the <o>jit.avc</o> object. </p>

<div>
<techdetail>The patch examples in this Tutorial assume that you have a DV camera or deck attached to your computer&#x2019;s FireWire port and powered on.</techdetail>
</div>
<h2>Plug and Play</h2>
<p>The <o>jit.avc</o> object&#x2019;s hardware connection has to be explicitly opened and closed, as is the case for the <o>jit.grab</o> and <o>jit.qt.videoout</o> objects we've used in the previous tutorials. Using the <o>jit.avc</o> object is a little simpler, though -- it communicates only with a single type of device.</p>

<h2>Basics</h2>
<p>Open the tutorial and double-click on the <m>p example_1</m> subpatch to open it.</p>

<illustration><img src="images/jitterchapter23a.png"/><o>jit.avc</o> and friends</illustration>

<bullet>Click the <m>getdevice</m> <o>message</o> box. This causes the <o>jit.avc</o> object to look for a compatible device attached to your computer. If it finds one, the object sends the device&#x2019;s name from its outlet, preceded by the symbol <m>device</m>. With our Sony DV camera attached, <o>jit.avc</o> sends the message <m>device Sony DV</m>.</bullet>
<bullet>In the patch, we&#x2019;re using the <o>route</o> and <o>prepend</o> objects to set the contents of the blank <o>message</o> box to the name of the located device. If <o>jit.avc</o> cannot find any compatible devices, an error message will be posted to the Max Console.</bullet>
<div>
<techdetail>If you receive an error message, double-check your cable connections between your camera/deck and computer, and make sure that the device is powered on.</techdetail>
</div>
<bullet>Click the <o>message</o> box that says <m>open</m>. This causes <o>jit.avc</o> to open a connection to the device it found.</bullet>
<div>
<techdetail>Technical note: We don't need to do any configuration prior to sending the <m>open</m> message to the <o>jit.avc</o> object. Unlike objects like <o>jit.grab</o> and <o>jit.qt.videoout</o>, which can switch between multiple input or output devices, <o>jit.avc</o> communicates with a single &#x201C;device&#x201D; -- the DV component -- which supports a single piece of hardware (this is a MacOS limitation).</techdetail>
</div>
<h2>PLAY and WIND groups (VTR mode)</h2>
<div>
<techdetail>This portion of the tutorial assumes that you have a DV cassette (with data already recorded on it) loaded in your device, and that you are in VTR mode.</techdetail>
</div>
<bullet>Use the <m>play</m>, <m>stop</m>, <m>pause</m>, <m>rewind</m> and <m>ff</m> <o>message</o> boxes (one at a time) and observe the behavior of your FireWire device. It should be responding as if you&#x2019;d pressed those buttons on the unit itself.</bullet>
<bullet>Click on the <o>umenu</o> object to view a partial list of PLAY group messages. These messages consist of the word <m>play</m> followed by an additional symbol describing the specific type of PLAY group operation. Double-click on the <link name="patcher" type="refpage">p</link> <m>avc_play_commands</m> subpatch to see brief descriptions of the messages we&#x2019;ve placed in the <o>umenu</o>. A full list of supported messages can be found in the Object Reference entry for <o>jit.avc</o>. Use the <o>umenu</o> to send a few of these messages to <o>jit.avc</o> to check their effect.</bullet>
<bullet>To check the current tape time, click the <m>gettime</m> <o>message</o> box. This causes the <o>jit.avc</o> object to send the current time from its outlet as a list of four integers preceded by the symbol <m>time</m>. We&#x2019;re using <o>route</o> and <o>unpack</o> objects to display those integers in the <o>number</o> boxes at the bottom of the patch. The numbers represent <i>hours</i>, <i>minutes</i>, <i>seconds</i> and <i>frames</i>, respectively.</bullet>
<bullet>Click the <o>message</o> box that says <m>close</m> to turn off the connection between <o>jit.avc</o> and your DV device.</bullet>

<h2>Avez-vous le temps?</h2>
<p>The following patch uses the <m>gettime</m> message to do something useful -- it causes an attached DV device to play the first minute of a loaded tape, and then rewinds and starts over. You might use a patch like this to automate a video installation, for example. </p>

<p>Open the tutorial and double-click on the <m>p example_2</m> subpatch to open it.</p>

<illustration><img src="images/jitterchapter23b.png"/>automating DV transport with <o>jit.avc</o></illustration>

<bullet>Make sure that you have at least 1 minute of recorded material on your loaded DV cassette. Otherwise, the patch won&#x2019;t work properly. Modifying the patch to perform error checking would probably be an instructive exercise for the motivated reader.</bullet>
<bullet>Click on the <o>message</o> box that says <m>open</m> to open the connection between the <o>jit.avc</o> object and your device.</bullet>
<bullet>Click on the <o>toggle</o> attached to the <o>metro</o> object. This causes two things to happen: the <o>trigger</o> object causes a <m>rewind</m> message to be sent to your device, and the <o>metro</o> is turned on, sending a <m>gettime</m> message to <o>jit.avc</o> every 100ms.</bullet>
<bullet>We&#x2019;re using the <o>route</o> object to send <o>jit.avc</o> object&#x2019;s response message (<m>time [hour] [minute] [second] [frame]</m>) to the <o>unpack</o> object at the top of the patch. The individual time values are unpacked, multiplied and added to determine the total number of frames that the current time represents.</bullet>
<div>
<techdetail>Actually, our frame count is a little inaccurate. DV time has 29.97 frames per second, not 30. For simplicity, we&#x2019;ve rounded up. For the purposes of this exercise, the math is close enough.</techdetail>
</div>
<bullet>Next, we test the frame count against the numbers 0 and 18122115 using the <o>select</o> object. Why? When a DV device can&#x2019;t find time code (which is the case when it&#x2019;s fully rewound and stopped), it reports the current time as either <m>0 0 0 0</m> or <m>165 165 165 165</m>, depending on the device model. Since (0 * 10800) + (0 * 1800) + (0 * 30) + 0 = 0, and (165 * 10800) + (165 * 1800) + (165 + 30) + 165 = 1812215, we can use these numbers to determine if the tape has been fully rewound. If our frame count does equal 0 or 1812215, then we send a <m>bang</m> to the <m>play</m> <o>message</o> box to start playback.</bullet>
<div>
<techdetail>The <o>jit.avc</o> object also offers an advanced message called <m>gettransport</m> that reports the exact state of the device&#x2019;s transport using hexadecimal numbers, which we might have used in preference to the method above. For our purposes, though, this is fine, and a little bit cleaner. For more information on <m>gettransport</m>, refer to the Object Reference entry and help file for <o>jit.avc</o>.</techdetail>
</div>
<bullet>If our frame count does not equal 0 or 1812215, then we are either rewinding or playing. Now, we want to make sure that we stop playing after approximately one minute, or 1800 frames (60 seconds * 30 frames). We test the frame count against 1800 with the <o>&gt;</o> <m>1800</m> object and, if it sends out a <m>1</m>, the <link name="select" type="refpage">sel</link> <m>1</m> object will bang the <m>rewind</m> <o>message</o> box and start the process all over again -- that's all there is to it.</bullet>
<bullet>When you&#x2019;re ready, turn off the <o>toggle</o>. This will both disable the <o>metro</o> and send a final <m>rewind</m> message to your DV device, just for neatness. Click on the <o>message</o> box that says <m>close</m> to close the connection between <o>jit.avc</o> and your device.</bullet>
<div>
<techdetail>Some FireWire DV devices support an additional message, <m>time</m>, which causes the device to wind to the specified location on a loaded tape (the location is described by four integers, in the same format as noted above). DV cameras <i>do not</i> support this message, generally speaking. Please refer to the help file for <o>jit.avc</o> for an example of building an auto-wind function in Max.</techdetail>
</div>
<h2>RECORD group</h2>
<p>If your DV device is a camera, it likely has two modes of operation: VTR mode and Camera mode. VTR mode is used for tape playback and non-camera (line-level) recording. Camera mode is used for recording directly from the camera portion of the unit. In VTR mode, all of the PLAY and WIND group commands are available, plus the RECORD group. In Camera mode, only the RECORD group commands are available (since you can&#x2019;t rewind while recording!). You can use either mode for this portion of the tutorial.</p>

<p>The RECORD group provides two primary messages: <m>record</m> and <m>recpause</m>. The <m>record</m> message starts recording, while the <m>recpause</m> message places the unit into record pause mode.</p>

<illustration><img src="images/jitterchapter23c.png"/>time-lapse with <o>jit.avc</o></illustration>

<p>This simple little patch is all that&#x2019;s necessary to set up time-lapse recording with <o>jit.avc</o>. It records 1 second of material every 30 seconds. Let&#x2019;s go through it:</p>

<p>Open the tutorial and double-click on the <m>p example_3</m> subpatch to open it.</p>

<bullet>Click the <o>message</o> box that says <m>open</m> to start the connection between <o>jit.avc</o> and your DV device.</bullet>
<bullet>Before we turn it on, let&#x2019;s examine the patch to see what&#x2019;s going to happen. Every second, the <o>metro</o> object will send a <m>bang</m> to the <o>counter</o>. When the <o>counter</o> hits <m>0</m>, the <link name="select" type="refpage">sel</link> <m>0</m> object will output a <m>bang</m>, first to the <m>record</m> message, and then to the <o>delay</o> object. After the specified delay (we&#x2019;ve chosen 1000 ms.), the <m>recpause</m> message will be sent to <o>jit.avc</o>. We&#x2019;ve supplied some <o>number</o> boxes so that you can change the counter and delay values.</bullet>
<bullet>Make sure that your DV device is receiving input (either from its built-in camera, or from a line-level source). Then, turn on the <o>toggle</o> attached to the <o>metro</o>, and watch your DV device for a few minutes -- time-lapse videography was never so easy!</bullet>
<bullet>When you&#x2019;re ready, turn off the <o>toggle</o> and click the <o>message</o> box that says <m>close</m> to close the connection between <o>jit.avc</o> and your DV device.</bullet>

<h2>Summary</h2>
<p>The <o>jit.avc</o> object provides a way to control and automate your FireWire DV device, such as a DV camera or deck, using the Max interface. It offers complete control over the WIND, PLAY and RECORD group commands. </p>

	<seealsolist>
		<seealso name="jit.avc">FireWire VTR control</seealso>
	</seealsolist>
	</chapter>
