<?xml version='1.0' encoding='UTF-8'?>

<?xml-stylesheet href="./_c74_tut.xsl" type="text/xsl"?>
<chapter name="Tutorial 21: Working With Live Video Input">
<setdocpatch name="21jSequenceGrabbers" patch="21jSequenceGrabbers.maxpat"/>

<previous name="jitterchapter20">Importing and Exporting Single Matrices</previous>
<next name="jitterchapter22">Working with Video Output Components</next>
<parent name="jitindex">Jitter Tutorials</parent>



<h1>Tutorial 21: Working With Live Video and Audio Input</h1>
<p>This tutorial demonstrates how to use Jitter in conjunction with an image capture device&#x2014;such as a webcam, a DV camera, or a PCI video input card&#x2014;to grab video sequences and use them as matrices, or record them directly to disk. We can also use Jitter to record sound directly to disk as a movie. </p>


<div>
<techdetail>The patch examples in this Tutorial assume that you have an appropriate image capture device powered on and attached to your computer. </techdetail>

</div>
<h2>The Basics of Sequence Grabbing</h2>
<p>When we capture video images from an input device, we are actually working with a sequence of images. In Tutorial 20, we created a sequence of images using the <m>export</m> operation of the <o>jit.movie</o> object. This time, we'll use the <o>jit.grab</o> object to grab a sequence of images. </p>

<h3>First grab</h3>
<bullet>Open the tutorial patch.</bullet>

<illustration><img src="images/jitterchapter21a.png"/>grab it like you want it</illustration>

<p>Notice that the <o>jit.grab</o> object takes two arguments (<m>320</m> and <m>240</m>) that specify the width and height of the matrix output by the object. They also represent the dimensions of the internal buffer into which any captured data will be placed. The matrix will always be a 4-plane <i>char</i> matrix.</p>

<bullet>Click the <o>message</o> box that says <m>getvdevlist</m>. This message causes the <o>jit.grab</o> object to search for available video capture devices. The <o>jit.grab</o> object will then send the names of any devices it finds out the right outlet in the form of a list preceded by the symbol <m>vdevlist</m>. In our patch, we're using <o>iter</o> to break the list up, and placing the device names in an <o>umenu</o>. Our list only has one item, <i>Dispaly iSight</i>, but yours may include different items.</bullet>

<bullet>Click on the <o>umenu</o> and select the device you'd like to use. This causes the <o>message</o> box that says <m>vdevice $1</m> to send the index of the selected video capture device (which is the same as its position in the <o>umenu</o>) to <o>jit.grab</o>. If you don't explicitly choose a <m>vdevice</m>, <o>jit.grab</o> defaults to the first selection in the list (equivalent to sending a <m>vdevice 0</m> message) when it opens the component connection.</bullet>

<bullet>Click on the <o>message</o> box that says <m>open</m>. The <m>open</m> message tells <o>jit.grab</o> to open a connection to the video capture device you've selected. Until you send the <m>open</m> message, <o>jit.grab</o> will simply output its last matrix when you send it a <m>bang</m> or <m>outputmatrix</m> message&#x2014;no sequence grabbing will occur.</bullet>

<bullet>Click on the <o>toggle</o> attached to the <o>metro</o> object, to start sending <m>bang</m>s to <o>jit.grab</o>. You should now see your captured video signal in the <o>jit.pwindow</o>.</bullet>
<div>
	
<techdetail>If you don't see your video signal, check the Max Console and see if <o>jit.grab</o> reported any errors. It may be possible that your device is in use by another application, or that it has gone to sleep (our video camera sleeps after about 3 minutes of non-use, for example). If your device supports multiple inputs, read on.</techdetail>
</div>

<bullet>If you have multiple devices connected to your computer, you can use the <m>vdevice</m> attribute to switch between them, even after sending the <m>open</m> message to <o>jit.grab</o>.</bullet>
<bullet>To close the component connection, click on the <o>message</o> box that says <m>close</m>. Leave this patch open; we'll return to it in a moment.</bullet>

<h3>Switching between inputs</h3>
<p>The video capture device you're using may support several different inputs. For instance, a CapSure Card supports s-video and composite inputs, and an ATI Rage 128 Pro supports s-video, composite and tuner inputs. FireWire DV generally supports a single input. In this section, we'll learn how to list those inputs and switch between them.</p>

<bullet>Re-open the <o>jit.grab</o> object's component connection by clicking on the <o>message</o> box that says <m>open</m>.</bullet>
<bullet>Click on the <o>message</o> box that says <m>getinputlist</m>. This causes <o>jit.grab</o> to send a list of available inputs for your chosen device out the right outlet preceded by the symbol <m>inputlist</m>. The patch breaks this list up using the <o>iter</o> object and sends it to the <o>umenu</o> on the right of the patch.</bullet>
<bullet>Click on the rightmost <o>umenu</o> to see a list of inputs available to your device. </bullet>

<!--><illustration><img src="images/image145.gif"/>setting device inputs</illustration>-->

<bullet>To change your input, select an item from the <o>umenu</o>. This causes the <o>message</o> box that says <m>input $1</m> to send the index of the selected input (which is the same as its position in the <o>umenu</o>) to <o>jit.grab</o>, which will switch to your selection. If you don't explicitly choose an <m>input</m>, <o>jit.grab</o> defaults to the first selection in the list (equivalent to sending an <m>input 0</m> message) when it opens the component connection.</bullet>
<bullet>You should now see your captured video signal (from your chosen input) in the <o>jit.pwindow</o>.</bullet>
<bullet>When you're done, click the <o>message</o> box that says <m>close</m> to close the component connection.</bullet>


<!-- discussion of vmode deleted 2014 pqe-->


<h2>Summary</h2>
<p>The <o>jit.grab</o> object allows you to grab images from any QuickTime-compatible video input device. The object offers both Max-based and Dialog Box interfaces for listing devices and inputs, switching between them, and controlling image quality.  </p>

	<seealsolist>
		<seealso display="Video and Graphics Tutorial 2: Live Capture" module="Video and Graphics" name="jitterchapter00d_Live Capture" type="tutorial" />
		<seealso display="Video Engines" module="core" name="jitter_video_engines" type="vignette" />		
		<seealso name="jit.pwindow">In-Patcher Window</seealso>
		<seealso name="jit.grab">Digitize video from an external source</seealso>
		<seealso name="jit.movie">Play or edit a movie</seealso>
	</seealsolist>
	</chapter>
