posts - 32,comments - 8,trackbacks - 0

 

Oops! JMF Video Cam Quick Start(Java摄像头抓取)

Reference:

Oops! JMF Quick Start

http://www.blogjava.net/pixysoft/archive/2007/09/07/143408.html

JMF应用篇 从摄像头捕获视频

http://blog.csdn.net/sunny3106/archive/2007/05/06/1598143.aspx



Quick Start

安装jmf-2_1_1e-windows-i586.exe,可以在我的第一个JMF教程里面下载。然后运行JMF Registry,选择Capture Devices里面的Detect capture Devices,得到以下结果:




eclipse里面新建一个Java Project,名字叫做Oops_JMFCam。项目添加引用jmf.jar,在安装目录下面的lib找到。



在项目的
src目录下面添加文件CaptureVideo.java

 

import javax.media.*;

import java.io.*;

import java.awt.*;

classCaptureVideoextendsFrameimplementsControllerListener

{

    privateCaptureDeviceInfo infor;

    privateMediaLocator mediaLocator;

    privateString url 
= "vfw:Microsoft WDM Image Capture (Win32):0";

    privateComponent com;

    privatePanel panel;

    Player player;

    
public CaptureVideo()

    {

        infor 
= CaptureDeviceManager.getDevice(url);

        mediaLocator 
= infor.getLocator();

    }

    publicvoid play()

    {

        
try

        {

            player 
= Manager.createPlayer(mediaLocator);// 利用mediaLocator创建Player

            player.addControllerListener(
this);

            player.realize();

            
// System.out.println("infor:"+infor);

            
// System.out.println("mediaLocator:"+mediaLocator);

        }

        
catch (NoPlayerException e)

        {

            
// TODO 自动生成 catch 块

            e.printStackTrace();

        }

        
catch (IOException e)

        {

            
// TODO 自动生成 catch 块

            e.printStackTrace();

        }

    }

    publicvoid createComponent()

    {

        setTitle(
"视频信号");

        
// addWindowListener(new WinClose());

        setBounds(
100100200200);

        panel 
= newPanel();

        
if ((com = player.getVisualComponent()) != null)

        {

            panel.add(com);

        }

        add(panel);

        setVisible(
true);

    }

    publicsynchronizedvoid controllerUpdate(ControllerEvent arg0)

    {

        
// TODO 自动生成方法存根

        
if (arg0 instanceofRealizeCompleteEvent)

        {

            System.out.println(
"realized");

            createComponent(); 
// 将播放器添加到Panel上

            player.prefetch();

        }

        
if (arg0 instanceofPrefetchCompleteEvent)

        {

            player.start();

            System.out.println(
"prefetched");

        }

    }

    publicstaticvoid main(String[] arg0)

    {

        CaptureVideo video 
= newCaptureVideo();

        video.play();

    }

}

 

Run as Java Application,得到结果

posted on 2007-09-09 23:52 张辰 阅读(1626) 评论(0)  编辑  收藏 所属分类: Dr. Oops

只有注册用户登录后才能发表评论。


网站导航: