如何使用java - imac webcam获取视频流

时间:2011-12-04 23:43:35

标签: java video-streaming video-capture jmf

我正在尝试在我的imac上运行下面的代码。任何人都可以指出它应该是什么线: (“vfw:Microsoft WDM Image Capture(Win32):0”);

视频流来自内置摄像头的imac。 CaptureDeviceManager.getDevice中应该包含哪些参数?

谢谢, PS1 我的jmf.jar位于Library / Java / Extensions

PS2 我还添加了这行代码:Vector deviceList = CaptureDeviceManager.getDeviceList(new RGBFormat());

但是deviceList为空

谢谢!!!

参考:http://khemsoi.blogspot.com/2006/03/jmf-frame-grabber.html

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);
}

0 个答案:

没有答案