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

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?

With java media framework JMF or FMJ
Here is an example with JVM

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/

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.

I'd use flex. It can be relatively easily integrated with java backend.
UPD:
Pure Java needed
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.

Related

Java WebRTC video streaming

I want to get some advice. I have to implement java server which will stream video from user to other clients. On client side will be using WebRTC. Can you give me some ideas how to implement this? Thank you)
You should use a media server that has WebRTC capabilities to do that. Don't try to write one on your own.
Here are a few open source alternatives: Janus, Jitsi, Kurento, mediasoup
If you plan on using an open source one, then I suggest you also understand the realities of these options - some got acquired, which changed a bit how they operate and how solid a solution they may be for you: https://bloggeek.me/twilio-acquires-kurento/
Janus video room demo is doing that. Although Janus is not written in Java, and I would say it is less than rock solid, it works quite well for this purpose.
We could not make Kurento working (last year). It seemed having odd requirements of a specific Linux distribution and version, and even once it was working fine, it just stopped working for no reason a month after.
Kurento does offer a lot more than Janus, OTOH you don't need those features. Using simple WebRTC and Janus makes this use case possible.
There is no need to write any Java server. Clients can send the video stream right from a HTML5 webpage, and viewers can view it right in HTML5. Janus examples show the actual code.

how to capture a video from /dev port in linux using java

i am trying to capture video from my /dev/video1 usb camera using java, i was wondering as to how to actually do this? my project is supposed to capture the video and stream it to another computer. is it also possible to set up an avconv server using java?
Java does not have an extensive support for media. You can use GStreamer JNI bindings for this or switch to QT or native C/C++ GStreamer.
It's already been done for you so you might take a look into the existing projects.
v4l4j wouble be a great place to start.
update
As Andy Ross commented the library I linked is very low level and you may be looking into something more easy to use as gstreamer-java.

What should I use to build RTSP server, should it be vlcj or xuggler?

I have a plan to develop RTSP streaming server with java. Now I have to decide with library used to decode media and stream data in rtp format. I am looking into vlcj and xuggler for video decoding and streaming. I did some research about differences of these library but I cannot make a decision yet. So I would like to ask you guys if I want to build a server which provide following feature. Do you think which one is better?
1. can stream video on demand to multiple users
2. can receive stream in mms format and restream it to rtsp format
Initially, I try ffmpeg and ffserver but there is audio out of sync problem so I decide to make my own server. the good way to use vlcj is to use out-of-process but I am afraid about performance in video on demand. I think about xuggler but I am afraid that it will have the same problem as I have in ffmpeg.
Could you throw me your opinion which one is appropriate on this situation?
With VLCJ (or Xuggler) depend that the machine has run the necessary libraries installed. Also, personally, I could not do a pilot with VLCJ Streaming server (and I've tried for a long time).
Java SE provides a framework called JMF (Java Media Framework) for developing, among other things, a streaming server
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
This framework is not the best there is, but it's work.
As a final note, I can say that I have developed a streaming server in Java with JMF, you can see it here http://code.google.com/p/servidor-streaming-rtp-rstp-java/ to give you a reference.
Regards!

Best ways to stream live video to a webpage using Python/C++/Java

I want to read in a live video stream, like RTSP, run some basic processing on it, and display it on a website. What are some good ways to do this? I have used OpenCV for Python before but found it to be a hassle. I am also familiar with Java and C++ if there are better libraries available. I haven't done a lot of web development before either.
What kind of live video source that you mean? If you don't intend to do this code-wise, you can use the free VLC Player to act as a streaming service in between any kind of media stream source (file, network, capture device, disc) and your web video client.
But, if you intend to do this code-wise, you can you VLCJ library. Other options can be Xuggler or FMJ.

Which Java library to use for record a video from a connected camera?

You would have thought that tere is a simple solution to this but there isn't :(
My application needs to capture a stream from a USB/firewire (or whatever is the connection) connected camera (result would be a file like output.flv). I would prefer that I can detect all connected cameras and choose which one to use (one or more at the same time --> one or more output files). Application has to be cross platform.
Found libraries:
Xuggle - not very good camera support. Good for manipulating over images and video.
JMF - an old API but if I can use it, I will. I don't see a MAC OS X link on downloads page.
FMJ - looks like a better version of JMF but a can't find a way of installing it.
LTI-CIVIL - FMJ uses it. It looks like it only captures images from camera (not video). I could use Xuggle to create a video from images taken from LTI-CIVIL. And like FMJ, it is difficult to install.
What are your suggestions on this one?
I'd recommend VLCj for this - it should be able to stream from webcams onto a Java canvas without any difficulties. It uses native code so you need to provide libvlc.so / dll but from there on it should work on all the major platforms (Windows, Mac, Linux).
You may need to look at out of process players for complete reliability which is a bit more complex (see here for my efforts so far) but once you've got that in place it should work fine.
There really is no good camera support for Java. You will have to use native code, tailored for each platform, through JNI to get video capture for your project.
There's a related question here. Basically they're suggesting OpenCV wrapped with JNI.

Categories

Resources