如何使用Java从网络摄像头获取视频和音频流?
如何使用 Java(以跨平台方式)从网络摄像头获取视频和音频流?
例如,我们有一台带有3-4个USB网络摄像头的计算机;我们希望获取它们的流并使它们在用户界面中可见。我们怎样才能做到这样的事情呢?我需要一个简单应用程序的代码,该应用程序可以找到计算机上的所有摄像头,并让我们选择要观看的摄像头。有谁可以分享一下这样的吗?
How can I get video and audio streams from web cameras with Java (in a cross-platform way)?
For example, we have a computer with 3-4 USB web cameras; we want to get their streams and make them visible in the user interface. How can we perform such a thing? I need code for a simple app which would find ALL cameras on the computer and let us select camera to wach. Can any one, please share such one?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 Java 媒体框架 JMF 或 FMJ
这里< /a> 是 JVM 的示例
With java media framework JMF or FMJ
Here is an example with JVM
我看到你关于解决方案需要“纯”java的评论,但这确实“几乎”不可能。您将需要使用某种本机库来访问设备,如上所述;我建议您将 Xuggler 作为您的解决方案。 Xuggler 支持 Windows、Mac 和 Linux,它们还提供用于处理音频和视频的示例代码。最后,图书馆是免费的。
网络摄像头捕获示例: http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler/src/com/xuggle/xuggler/demos/DisplayWebcamVideo.java
虽然 Xuggle 没有麦克风捕获示例,但您可以在邮件列表中查找示例,或者您可以使用此处找到的 packet-multibroadcaster 项目编写的代码: https://code.google.com/p/packet-multibroadcaster/
I see your comment about the solution needing to be "pure" java, but this is really "nearly" impossible. You will need to use some sort of native library for accessing the devices, with that being stated; I suggest that you look at Xuggler as your solution. Xuggler supports Windows, Mac, and Linux and they also offer example code for handling audio and video. Lastly the library is FREE.
Webcam capture example: http://xuggle.googlecode.com/svn/trunk/java/xuggle-xuggler/src/com/xuggle/xuggler/demos/DisplayWebcamVideo.java
While Xuggle does not have an example of microphone capture, you can find samples on the mailing list or you could use code written by the packet-mulitbroadcaster project found here: https://code.google.com/p/packet-multibroadcaster/
您可以尝试我的解决方案。它使用 OpenCV 捕获图像,并使用 jetty 服务器通过 WebSocket 传输图像。该示例分为三个类,很容易理解。
现在我只能发送视频,但我也在处理音频。
You can try my solution. It uses OpenCV to capture the image and jetty server to transmit it via WebSocket. The example has three classes and it will be easy to understand.
Now I can send only video, but I'm working on audio aswell.
我会使用柔性。它可以相对容易地与java后端集成。
更新:
那么您应该考虑 JavaFX 解决方案。我不是 javafx 方面的大专家,我只编写了一些基本的测试应用程序,但我确信这是使用纯 java 解决所描述问题的现代方法。
I'd use flex. It can be relatively easily integrated with java backend.
UPD:
Then you should consider JavaFX solutions. I'm not a big expert in javafx, I've only written some basic test applications, but I'm sure it's a modern way of solving described problem with pure java.