java FMJ 网络摄像头捕获示例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1277604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FMJ Webcam capture example
提问by Alexander Stolz
I've been searching for while now and I can't find a simple example of how to capture a webcam stream with FMJ. Are there any tutorials or examples available which could help me?
我一直在寻找一段时间,但找不到一个简单的示例来说明如何使用 FMJ 捕获网络摄像头流。是否有任何可用的教程或示例可以帮助我?
采纳答案by panete
I have been working with FMJ for a while and I haven't found many examples to start with either. What I would do is to explore the FmjStudio class that has the webcam functionality integrated and its pretty straight forward.
我已经与 FMJ 合作了一段时间,但我也没有找到很多例子。我要做的是探索 FmjStudio 类,它集成了网络摄像头功能并且非常简单。
For bob:
对于鲍勃:
What you want is FMJ. FMJ uses an DataSource implementation for civil to use it with JMF. I would recommend you to go to http://fmj-sf.net/download the latest source and explore FmjStudio aswell since it uses civil to capture.
你想要的是FMJ。FMJ 使用了一个 DataSource 实现,将其与 JMF 一起使用。我建议你去http://fmj-sf.net/下载最新的源代码并探索 FmjStudio,因为它使用 Civil 捕获。
For theDude:
对于花花公子:
You are right, you can use JMF aswell but the same code you use for JMF will most likely work with FMJ (maybe with a coupla changes) and the performance will be much better, specially if you want a wide range of different webcams to work with your software.
您是对的,您也可以使用 JMF,但是您用于 JMF 的相同代码很可能可以与 FMJ 一起使用(可能会有 coupla 更改)并且性能会好得多,特别是如果您想要各种不同的网络摄像头工作用你的软件。
回答by thedude19
I know this isn't what you want to hear, but I've used JMF for this task and it works very well. There are enough examples online to get a simple web cam capture app running pretty easily. I'll post more if you're interested.
我知道这不是您想听到的,但我已将 JMF 用于此任务,并且效果很好。网上有足够多的例子可以让一个简单的网络摄像头捕获应用程序很容易地运行。如果你有兴趣,我会发布更多。
回答by hoymkot
The following code would get you started.
以下代码将帮助您入门。
GlobalCaptureDevicePlugger.addCaptureDevices();
Vector<CaptureDeviceInfo> audioCapDevList = CaptureDeviceManager.getDeviceList(null);
if (audioCapDevList.size() != 0) {
for (int i = 0; i < audioCapDevList.size(); i++) {
audioCapDevInfo = audioCapDevList.elementAt(i);
Format[] videoFormats = audioCapDevInfo.getFormats();
System.out.println(audioCapDevInfo);
if (audioCapDevInfo.getName().startsWith("vfw:")) { // assume the name of the webcam starts with vfw:
for (int j = 0; j < videoFormats.length; j++) {
if (videoFormats[j] instanceof VideoFormat) {
currentFormat = (VideoFormat) videoFormats[i];
break;
}
}
System.out.println(currentFormat);
if (currentFormat == null) {
System.err.println("Search for VideoFormat failed");
System.exit(-1);
}
audioCapDevLoc = audioCapDevInfo.getLocator();
}
}
}
Please make sure the native libraries (civil.dll and jdshow.dll) are loaded into the JVM. Otherwise, you would get an java.lang.UnsatisfiedLinkError. The following code may do the job for you.
请确保本地库(civil.dll 和 jdshow.dll)已加载到 JVM 中。否则,您会得到 java.lang.UnsatisfiedLinkError。以下代码可以为您完成这项工作。
System.setProperty("java.library.path", "D:/fmj-sf/native/win32-x86/");
Field fieldSysPath;
try {
fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
} catch (Exception e) {
e.printStackTrace();
}

