捕获视频的代码经过调试已经成功,就是保存的时候不行,
捕获视频的代码如下:
import javax.media.CaptureDeviceInfo;
import javax.media.CaptureDeviceManager;
import javax.media.NoDataSinkException;
import javax.media.NoPlayerException;import java.awt.*;
import java.io.*;
import java.util.*;
import javax.media.*;
import javax.media.control.StreamWriterControl;
import javax.media.format.*;
import javax.media.protocol.ContentDescriptor;
import javax.media.protocol.DataSource;
import javax.media.protocol.FileTypeDescriptor;
import javax.swing.*;
public class SaveVod{
Vector list=null;
CaptureDeviceInfo cdi=null;
MediaLocator ml=null;
String name=null;
Player player;

public void init() throws NoPlayerException, IOException
{
list=CaptureDeviceManager.getDeviceList(new VideoFormat(VideoFormat.RGB));

cdi=(CaptureDeviceInfo) list.elementAt(0);

name=cdi.getName();

if(name.startsWith("vfw:"))
ml=cdi.getLocator();

player=Manager.createPlayer(ml);

player.start();

}

public static void main(String[] args) throws NoPlayerException, IOException {

SaveVod sv=new SaveVod();
sv.init();

}
}
我在这个捕捉摄像头视频的代码上想把捕获的视频保存到本地硬盘,不过调试很很久都不行。我的代码如下:
public class SaveVod{
Vector list=null;
CaptureDeviceInfo cdi=null;
MediaLocator ml=null;
String name=null;
Player player;
Processor processor=null;
DataSource ds=null;
DataSink dataSink=null;


public void init() throws NoPlayerException, IOException
{
list=CaptureDeviceManager.getDeviceList(new VideoFormat(VideoFormat.RGB));

cdi=(CaptureDeviceInfo) list.elementAt(0);

name=cdi.getName();

if(name.startsWith("vfw:"))
ml=cdi.getLocator();

player=Manager.createPlayer(ml);

player.start();

processor=Manager.createProcessor(ml);

processor.configure();

processor.setContentDescriptor(new FileTypeDescriptor(FileTypeDescriptor.MPEG));

ds=processor.getDataOutput();

MediaLocator dest=new MediaLocator("file://test.mepg");

try {
dataSink = Manager.createDataSink(ds, dest);
dataSink.open();

} catch (NoDataSinkException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

StreamWriterControl swc = (StreamWriterControl)
processor.getControl ("javax.media.control.StreamWriterControl"); if(swc!=null)
{
swc.setStreamSizeLimit(2000000);

}

processor.start();
        dataSink.open();
        dataSink.start();

}

public static void main(String[] args) throws NoPlayerException, IOException {

SaveVod sv=new SaveVod();
sv.init();

}
}请做过jmf多媒体开发的能帮我解决,万分感激!
希望能附上源代码。

解决方案 »

  1.   

    public void video() {

    System.out.println("ppfmjfdsdf");
    try {// player用cloneabledatasource数据源,processor用cloneddatasource的数据源
    processor = Manager.createProcessor(cloneddatasource);
    sh = new StateHelper(processor);
    } catch (IOException ez5) {
    ez5.printStackTrace();
    System.exit(-1);
    } catch (NoProcessorException ez6) {
    ez6.printStackTrace();
    System.exit(-1);
    }
    // Configure the processor,让processor进入configured状态
    if (!sh.configure(10000)) {
    System.out.println("configure wrong!");
    System.exit(-1);
    }
    System.out.println("222");
    // 设置视频输出格式
    processor.setContentDescriptor(new FileTypeDescriptor(
    FileTypeDescriptor.QUICKTIME));
    // realize the processor,让processor进入realized状态
    if (!sh.realize(10000)) {
    System.out.println("realize wrong!");
    System.exit(-1);
    }
    // get the output of the processor,并且启动processor
    DataSource outsource = processor.getDataOutput();
    File videofile = new File(videoname);
    // 创建新文件
    try {
    videofile.createNewFile();
    } catch (IOException e2) {
    // TODO Auto-generated catch block
    e2.printStackTrace();
    }
    MediaLocator dest = new MediaLocator(new String("file:///" +videoname)); processor.start();


    /*
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }*/
    try {
    dataSink = Manager.createDataSink(outsource, dest);
    dataSink.open();
    } catch (NoDataSinkException ez1) {
    ez1.printStackTrace();
    System.exit(-1);
    } catch (IOException ez2) {
    ez2.printStackTrace();
    System.exit(-1);
    } catch (SecurityException ez3) {
    ez3.printStackTrace();
    System.exit(-1);
    }
    try {
    dataSink.start();
    } catch (IOException ez4) {
    ez4.printStackTrace();
    System.exit(-1);
    }
    if(dataSink!=null){
    System.out.println("xxx!");

    }
    }