title: how to get video stream with java - imac webcam
body: <p>I'm trying to run the code below on my imac. Can anyone point what should be the line where it says:
  ("vfw:Microsoft WDM Image Capture (Win32):0");</p>
  
  <p>The video stream comes from the imac built in camera. what argument should come in the CaptureDeviceManager.getDevice?</p>
  
  <p>Thanks, 
  PS1
  My jmf.jar is located in Library/Java/Extensions </p>
  
  <p>PS2
  I also added this line of code: Vector deviceList = CaptureDeviceManager.getDeviceList(new RGBFormat());</p>
  
  <p>but the deviceList is empty  </p>
  
  <p>Thank you!!!</p>
  
  <p>reference: <a href="http://khemsoi.blogspot.com/2006/03/jmf-frame-grabber.html" rel="nofollow">http://khemsoi.blogspot.com/2006/03/jmf-frame-grabber.html</a></p>
  
  <pre><code>public static void main(String[] args) throws Exception
  { 
      // Create capture device
      CaptureDeviceInfo deviceInfo = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
  
  
      Player player = Manager.createRealizedPlayer(deviceInfo.getLocator());
      player.start();
  
      // Wait a few seconds for camera to initialise (otherwise img==null)
      Thread.sleep(2500);
  
      // Grab a frame from the capture device
      FrameGrabbingControl frameGrabber = (FrameGrabbingControl)player.getControl("javax.media.control.FrameGrabbingControl");
      Buffer buf = frameGrabber.grabFrame();
  
      // Convert frame to an buffered image so it can be processed and saved
      Image img = (new BufferToImage((VideoFormat)buf.getFormat()).createImage(buf));
      BufferedImage buffImg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
      Graphics2D g = buffImg.createGraphics();
      g.drawImage(img, null, null);
  
      // Overlay curent time on image
      g.setColor(Color.RED);
      g.setFont(new Font("Verdana", Font.BOLD, 16));
      g.drawString((new Date()).toString(), 10, 25);
  
      // Save image to disk as PNG
      ImageIO.write(buffImg, "png", new File("/Users/Dror/Desktop/webcam.png"));
  
      // Stop using webcam
      player.close();
      player.deallocate();
      System.exit(0);
  }
  </code></pre>