问题描述
packagecom.jake.camera.test;importjava.io.IOException;importjava.util.Vector;importjavax.media.CaptureDeviceInfo;importjavax.media.CaptureDeviceManager;importjavax.media.DataSink;importjavax.media.Manager;importjavax.media.MediaLocator;importjavax.media.Processor;importjavax.media.control.StreamWriterControl;importjavax.media.format.AudioFormat;importjavax.media.format.VideoFormat;importjavax.media.protocol.DataSource;importjavax.media.protocol.FileTypeDescriptor;importnet.sf.fmj.media.RegistryDefaults;importnet.sf.fmj.media.cdp.GlobalCaptureDevicePlugger;publicclassCaptureAll{/**<一句话功能简述>*<功能详细描述>*@paramargs*@see[类、类#方法、类#成员]*/publicstaticvoidmain(String[]args){ProcessorrecordProcessor=null;StateHelpersh=null;//查询CaptureDeviceManager,来定位你需要使用的媒体采集设备。//FMJRegistryDefaults.registerAll(RegistryDefaults.FMJ|RegistryDefaults.FMJ_NATIVE);GlobalCaptureDevicePlugger.addCaptureDevices();Vector<CaptureDeviceInfo>audioDeviceList=CaptureDeviceManager.getDeviceList(newAudioFormat(AudioFormat.LINEAR,44100,16,2));CaptureDeviceInfoaudioDevice=audioDeviceList.get(0);Vector<CaptureDeviceInfo>videoDeviceList=CaptureDeviceManager.getDeviceList(newVideoFormat(VideoFormat.RGB));CaptureDeviceInfovideoDevice=(CaptureDeviceInfo)videoDeviceList.get(0);try{MediaLocatoraudioMediaLocator=audioDevice.getLocator();MediaLocatorvideoMediaLocator=videoDevice.getLocator();DataSourceaudioDataSource=Manager.createDataSource(audioMediaLocator);DataSourcevedioDataSource=Manager.createDataSource(videoMediaLocator);DataSource[]sources=newDataSource[2];sources[0]=audioDataSource;sources[1]=vedioDataSource;DataSourcemergeSource=Manager.createMergingDataSource(sources);recordProcessor=Manager.createProcessor(mergeSource);//获得MediaLocator,并由此创建一个Processor。sh=newStateHelper(recordProcessor);}catch(Exceptione){e.printStackTrace();System.exit(-1);}//Configuretheprocessorif(!sh.configure(10000)){System.out.println("configurewrong!");System.exit(-1);}VideoFormatvfmt=newVideoFormat(VideoFormat.RGB);AudioFormatafmt=newAudioFormat(AudioFormat.LINEAR);(recordProcessor.getTrackControls())[0].setFormat(afmt);(recordProcessor.getTrackControls())[0].setEnabled(true);(recordProcessor.getTrackControls())[1].setFormat(vfmt);(recordProcessor.getTrackControls())[1].setEnabled(true);//定义待存储该媒体的内容类型(contenttype)。recordProcessor.setContentDescriptor(newFileTypeDescriptor(FileTypeDescriptor.WAVE));//realizetheprocessor.if(!sh.realize(10000)){System.out.println("realizewrong!");System.exit(-1);}//获取音频数据流DataSourcesource=recordProcessor.getDataOutput();//定义存储该媒体的文件。MediaLocatordest=newMediaLocator(newjava.lang.String("file:///E:/video.wav"));//创建一个数据池DataSinkfilewriter=null;try{filewriter=Manager.createDataSink(source,dest);filewriter.open();}catch(Exceptione){e.printStackTrace();System.exit(-1);}//获取音频录制流StreamWriterControlswc=(StreamWriterControl)recordProcessor.getControl("javax.media.control.StreamWriterControl");recordProcessor.start();//限制录制音频的大小//swc.setStreamSizeLimit();//开始录制try{filewriter.start();}catch(IOExceptione){e.printStackTrace();System.exit(-1);}//Capturefor5seconds设置录制sh.playToEndOfMedia(60000);sh.close();filewriter.close();System.out.println("CaptureAudiosuccess.");}}报错:2011-9-1013:42:10net.sf.fmj.ffmpeg_java.FFMPEGParser<init>警告:Unabletoinitializeffmpeglibraries:java.lang.UnsatisfiedLinkError:Cannotlocatelibraryavformat-51Java_com_lti_civil_impl_jni_NativeCaptureStream_stop,stopping...DSCaptureStream::stop,stopping...DSCaptureStream::stop,stopped.Java_com_lti_civil_impl_jni_NativeCaptureStream_stop,stopped.Unabletohandleformat:LINEAR,44100.0Hz,16-bit,Stereo,LittleEndian,SignedUnabletohandleformat:RGB,640x480,FrameRate=30.0,24-bit,Masks=3:2:1,PixelStride=3,LineStride=1920Failedtorealize:com.sun.media.ProcessEngine@1e0ff2fError:Unabletorealizecom.sun.media.ProcessEngine@1e0ff2frealizewrong!请问什么原因?谢谢。