Results 1 to 3 of 3
  1. #1
    Shurukan's Avatar
    Shurukan is offline Member
    Join Date
    Mar 2011
    Rep Power

    Default Capturing video from webcam with JMF

    Hi, I want to learn to use jmf for working with my webcam, and I've found a simple code in the internet for grabbing an image and saving it on the hard drive.
    Java Code:
    public class JMF {
        public static void main(String[] args) throws Exception 
            CaptureDeviceInfo deviceInfo = CaptureDeviceManager.getDevice("vfw:Microsoft WDM Image Capture (Win32):0");
            Player player = null; 
            player = Manager.createRealizedPlayer(deviceInfo.getLocator());
            FrameGrabbingControl frameGrabber = (FrameGrabbingControl)player.getControl("");
            Buffer buf = frameGrabber.grabFrame();
            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);
            g.setFont(new Font("Verdana", Font.BOLD, 16));
            g.drawString((new Date()).toString(), 10, 25);
            ImageIO.write(buffImg, "png", new File("c:\\webcam.png"));
    Well it gives me a NullPointerException on player = Manager.createRealizedPlayer(deviceInfo.getLocator ());
    My webcam is recognized by JMStudio.

  2. #2
    Shurukan's Avatar
    Shurukan is offline Member
    Join Date
    Mar 2011
    Rep Power


    I have a 64-bit Windows 7, maybe jmf doesn't work too well on 64-bit systems? Or maybe it's a webcam driver problem? But in that case I don't understand why JMStudio recognizes my camera and can capture video from it. Please help me, I've googled this problem quite a lot and haven't found any solution.

  3. #3
    Mr777 is offline Devil
    Join Date
    Nov 2011
    Rep Power

    Default Re: Capturing video from webcam with JMF

    Well, jmf works with 32 bit java, so are you sure you have 32 bit java configured in your system?
    Also before creating a player, i will recommend you to find the devices, may be your code is not detecting any device (Video Capturing) and hence causing a null pointer exception.

Similar Threads

  1. Replies: 0
    Last Post: 07-01-2010, 04:56 PM
  2. Replies: 0
    Last Post: 04-23-2010, 08:10 PM
  3. JMF: capturing built in webcam
    By Perre in forum Advanced Java
    Replies: 0
    Last Post: 02-20-2010, 11:58 AM
  4. Replies: 0
    Last Post: 11-20-2008, 12:03 PM
  5. Capturing video with Robot
    By russ2620 in forum AWT / Swing
    Replies: 0
    Last Post: 06-03-2008, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts