Video - sound - sensor capture in Java - java

I would like to develop an application which would be able to capture video from a webcam, capture sound from a mic and capture movement if a proximity sensor is available.
Initially I want it to run on windows but if able I might want to make it work on android later on.
I'm looking for something pretty straight forward and easy to understand.
My research has led me to Java Media Framework but it is too old and abandoned.
FMJ seems also old.
JavaCV appears to have poor documentation available.
My goal is to make a home detection app which uses the camera imagery, mic sound and sensors to detect and analyze home invasion.
I might take a leap and do it in .NET or other object oriented programming languages if
easier solutions present themselves.
How should I approach this, what are your suggestions?

One Solution is use JavaCV. So you can develop your desktop application using java and later can be ported in to android with fewer changes. As you said JavaCV haven't rich documentation. But JavaCV is just a wrapper to a OpenCV. So you can read OpenCV documentaion and find the relevant method(function) names. The methods in JavaCV has almost same names as OpenCV. So you can try those methods in JavaCV.
Next solution is use .NET to develop the system. There you can use
AForge.NET a rich library for .NET or Emgu CV .NET wrapper
for OpenCV. But you will be facing a problem when creating the
android app. Because you have to build it from scratch.

Related

How to write iOS backend like (Game Center, IAP etc.) with libGDX?

I write game on libGdx and testing it on Android. All code I write on Java, because libGDX use Java language. How can I write iOS backend on Objective C and link it with Java libGDx core? Is any tutorial?
I don't know how you would accomplish what you are after, the primary problem being the lack of a JVM on iOS. The recommended way to get a libGDX game to run on iOS is by using MonoTouch from Xamarin.
See this blog-post from libGDX's Mario on libGDX and MonoTouch licensing
Unfortunately, it's not free, nor open-source. There are some other projects in the pipeline to get a JVM on iOS, via open-source project, like RoboVM, but they aren't fully implemented for libGDX use yet.
Good luck!

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.

Video Camera Controls API

I'm writing an Eclipse RCP that takes photographs with a movie camera. I'm getting the video feed using the Java Media Framework (JMF).
The camera I'm using is the Microsoft Lifecam Cinema camera. Edited to add: I'm developing on a Windows XP workstation.
The camera has pan, zoom, and tilt controls.
My question is, do these camera controls have an Application Programming Interface (API)?
I couldn't find anything with an Internet search. JMF doesn't have any methods for controlling a video camera that I could find.
While I'm using Java, I can wrap an API in another language using the Java Native Interface (JNI) if I must.
Before going the raw JNI way, i would instead suggest you take the jUSB route or the javax.usb one. From what I understand, your camera is a pure USB one, so it should be possible to drive it from such an API, no ?
Unfortunatly, as I'm unable to find any kind of reverse protocol infos, it seems like you'll have to guess how to drive it by yourself.

How to get video and audio streams from web cameras with 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.

Video playback in Java ( JMF, Fobs4JMF, Xuggler, FMJ )

I need simple video playback in Java.
Here are my requirements:
PRODUCTION QUALITY
Open and decode video files whose video and audio codecs can be chosen by me. I.E I can pick well behaving codecs.
Be able to play, pause, seekToFrame OR seekToTime and stop playback. Essentially I wish to be able to play segments of a single video file in a non linear fashion. For example I may want to play the segment 20.3sec to 25.6sec, pause for 10 seconds and then play the segment 340.3sec to 350.5sec, etc.
During playback, video and audio must be in sync.
The video must be displayed in a Swing JComponent.
Must be able to use in a commercial product without having to be open source (I.E. LGPL or Comercial is good)
My research has led me to the following solutions:
Use Java Media Framework + Fobs4JMF
http://fobs.sourceforge.net/f4jmf_first.html
I have implemented a quick prototype and this seems to do what I need. I can play a segment of video using:
player.setStopTime(new Time(end));
player.setMediaTime(new Time(start));
player.start();
While Fobs4JMF seems to work, I feel the quality of the code is poor and the project is no longer active. Does anyone know of any products which use Fobs4JMF?
Write a Flash application which plays a video and use JFlashPlayer to bring it into my Java Swing application
Unlike Java, Flash is brilliant at playing video. I could write a small Flash application with the methods:
open(String videoFile),
play(),
pause(),
seek(int duration),
stop()
Then bring it into Java using JFlashPlayer which can call Flash functions from Java.
What I like about this solution is that video playback in Flash should be rock solid. Has anyone used JFlashPlayer to play video in Java?
Write a simple media player on top of Xuggler
Xuggler is an FFMpeg wrapper for Java which seems to be a quite active and high quality project. However, implementing the simple video playback described in the requirements is not trivial (Seeking in particular) but some of the work has been done in the MediaTools MediaViewer which would be the base upon which to build from.
Use FMJ
I have tried to get FMJ to work but have had no sucess so far.
I would appreciate your opinions on my problem.
Can a brother get a shout out for Xuggler?
In my mind, VLCJ is the way forward for this type of thing. I love Xuggler for encoding / transcoding work, but unfortunately it's just so complicated to do simple playback and solve all the sync issues and suchlike - and it does very much feel like reinventing the wheel doing so.
The only thing with VLCJ is that to get it to work reliably with multiple players I've had to resort to out of process players. The framework wasn't the simplest thing in the world to get in place, but when it's there it works beautifully. I'm currently running 3 out of process players in my app side by side with no problems whatsoever.
The other caveat is that the embedded media player won't work with a swing component, just a heavyweight canvas - but that hasn't proven a problem for me at all. If it does, then you can use the direct media player to get a bufferedimage and display that on whatever you choose, but it will eat into your CPU a bit more (though no more than other players that take this approach.)
JavaFX has a number of working video and audio codecs builtin. It's likely to be the solution with the broadest support at the moment.
I've been using jffmpeg in the same way you use FOBS, it works pretty well, although I haven't compared them.
I would also love to see an easy way to interface with native codecs the way that JavaFX does, but there doesn't seem to be real integration between JavaFX and Java.
There has also been some work trying to get the VLC library libvlc into java. I haven't tried it yet and would be interested to hear back from anyone who has.
haven't tried Xuggler (which i'm interested in) but I'm having a good time with VLCJ. The drawback I find in it is only that you have to have VLC installed prior to your application.
I'd recommend using MPV. You can use it in combination with JavaFX quite easily, see this example.
In short, you use a little JNA magic to use the MPV native libaries directly, and then let the video display on a JavaFX stage. If you use a child stage, you can even overlay JavaFX controls on top of the video (with full transparancy support).
VLC (with VLCJ) can be used in a similar fashion, but I find that the MPV solution performs better (faster seek and start times).

Categories

Resources