Java 录制并显示视频JMF
我想从网络摄像机上录制一段视频,看看我在屏幕上录制了什么。 就个人而言,我可以在使用网络摄像机的屏幕上看到它,也可以录制视频,但不能两者兼而有之。录制时,jpanel不会更新。它完全不报告错误。 我该如何解决这个问题?非常感谢你。对不起我的英语Java 录制并显示视频JMF,java,jmf,Java,Jmf,我想从网络摄像机上录制一段视频,看看我在屏幕上录制了什么。 就个人而言,我可以在使用网络摄像机的屏幕上看到它,也可以录制视频,但不能两者兼而有之。录制时,jpanel不会更新。它完全不报告错误。 我该如何解决这个问题?非常感谢你。对不起我的英语 public class NewJFrame extends javax.swing.JFrame implements ActionListener { private static boolean debugDeviceList = fal
public class NewJFrame extends javax.swing.JFrame implements ActionListener {
private static boolean debugDeviceList = false;
private static String defaultVideoDeviceName = "Microsoft WDM Image Capture";
private static String defaultAudioDeviceName = "DirectSoundCapture";
private static String defaultVideoFormatString = "size=640x480, encoding=yuv, maxdatalength=614400";
private static String defaultAudioFormatString = "linear, 48000.0 hz, 16-bit, stereo, signed";
private Timer timer = new Timer(40, this);
private Player player;
public NewJFrame(){
initComponents();
MediaLocator videoMediaLocator = new MediaLocator("vfw://0");
DataSource myDataSource = Manager.createDataSource(videoMediaLocator);
player = Manager.createPlayer(myDataSource);
player.start();
DataSource videoDataSource = myDataSource;
MediaLocator audioMediaLocator = new MediaLocator("dsound://");
DataSource audioDataSource = null;
audioDataSource = Manager.createDataSource(audioMediaLocator);
DataSource dArray[] = new DataSource[2];
dArray[0] = videoDataSource;
dArray[1] = audioDataSource;
DataSource mixedDataSource = null;
mixedDataSource = Manager.createMergingDataSource(dArray);
FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.MSVIDEO);
Format outputFormat[] = new Format[2];
outputFormat[0] = new VideoFormat(VideoFormat.INDEO50);
outputFormat[1] = new AudioFormat(AudioFormat.GSM_MS);
processorModel = new ProcessorModel(mixedDataSource, outputFormat, outputType);
processor = Manager.createRealizedProcessor(processorModel);
source = processor.getDataOutput();
dest = new MediaLocator("file:.\\testcam.avi");
dataSink = null;
dataSinkListener = null;
dataSink = Manager.createDataSink(source, dest);
dataSinkListener = new MyDataSinkListener();
dataSink.addDataSinkListener(dataSinkListener);
dataSink.open();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
timer.start();
dataSink.start();
processor.start();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
timer.stop();
processor.stop();
processor.close();
dataSinkListener.waitEndOfStream(10);
dataSink.close();
Stdout.log("[all done]");
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
public BufferedImage grabFrameImage() {
Image image = null;
FrameGrabbingControl fGrabbingControl = null;
if (player != null) {
fGrabbingControl = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
}
javax.media.Buffer buffer = fGrabbingControl.grabFrame();
if (buffer != null) {
image = new BufferToImage((VideoFormat) buffer.getFormat()).createImage(buffer);
}
if (image != null) {
return (BufferedImage) image;
}
return null;
}
}
尝试使用jmapps jmstudio源代码,这是很好的代码。它是关于数据接收器和文件类型描述符的 概念:通过捕获设备从源记录,您需要一个数据接收器,然后加载系统,存储到文件,并从文件中加载播放器 如果不从播放器中读取文件,那么它在JMF中不起作用。已经在线14.5年了,JMF直播视频没有问题。当我写player.start()时;处理器之前=Manager.createRealizedProcessor(processorModel);录像,但jPanel没有重新上漆,它一直是白色的。当我写player.start()时;after processor=Manager.createRealizedProcessor(processorModel);我看到什么记录了网络摄像机(jPanel repait),但当我打开avi文件时,它是空的。请帮助我任何人。我做错了什么?