如何使用 Java 从网络摄像头获取视频和音频流?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2525278/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:50:35  来源:igfitidea点击:

How to get video and audio streams from web cameras with Java?

javavideoaudiostreamwebcam

提问by Rella

How can I get video and audio streams from web cameras with Java (in a cross-platform way)?

如何使用 Java(以跨平台方式)从网络摄像头获取视频和音频流?

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?

例如,我们有一台带有 3-4 个 USB 网络摄像头的计算机;我们想要获取他们的流并使它们在用户界面中可见。我们怎么能做这样的事情呢?我需要一个简单的应用程序代码,它可以找到计算机上的所有相机,让我们选择要观看的相机。有哪位可以分享一下这样的吗?

采纳答案by Enrique

With java media framework JMFor FMJ

使用java 媒体框架 JMFFMJ

Hereis an example with JVM

是 JVM 的示例

回答by Roman

I'd use flex. It can be relatively easily integrated with java backend.

我会使用弹性。它可以相对容易地与java后端集成。

UPD:

更新:

Pure Java needed

需要纯 Java

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.

那么您应该考虑 JavaFX 解决方案。我不是 javafx 的大专家,我只编写了一些基本的测试应用程序,但我确信这是用纯 java解决所描述问题的现代方法。

回答by Paul Gregtheitroade

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

我看到您对解决方案需要“纯”java 的评论,但这真的“几乎”不可能。您将需要使用某种本机库来访问设备,并说明了这一点;我建议您将 Xuggler 视为您的解决方案。Xuggler 支持 Windows、Mac 和 Linux,它们还提供处理音频和视频的示例代码。最后,图书馆是免费的。网络摄像头捕获示例: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/

虽然 Xuggle 没有麦克风捕获示例,但您可以在邮件列表中找到示例,或者您可以使用此处找到的 packet-mulitbroadcaster 项目编写的代码:https: //code.google.com/p/packet-multibroadcaster/

回答by Kanaris007

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.

你可以试试我的解决方案。它使用 OpenCV 捕获图像并通过码头服务器通过 WebSocket 传输它。该示例包含三个类,很容易理解。现在我只能发送视频,但我也在处理音频。