Using JMF to get a frame from a video - java

I have to take in a video file (.mpg or .avi or .mov ect...) using JMF and where the user stops the video (or pauses) I need to get that frame. If I can get it into a frame buffer then I'm golden (or even save the frame as a image file like jpg). As once I have the frame I just need to get RGB values from the pixels in the frame.(which I already have made a method for)
My issue here is I have not got any experience in JMF, but I have a source file that opens a window and then I can browse for a video file which seems to only work half the time.
I gather this is a bit of a tall order as I am pretty much in the dark on how to do this, and everything I try looking up is not of any real help, if someone knows a link that has some example code that would be wonderful.
Thanks.

Related

Real time logo detection in live camera preview with OpenCV on Android

I am new to computer vision but I am trying to code an android app which does the following:
Get the live camera preview and try to detect one logo in that (i have the logo in my resources). In real-time. Draw a rect around the logo if found. If there is no match, dont draw the rectangle.
I already tried a couple of things including template-matching and feature detection using ORB.
Why that didnt work:
Template-matching:
Issues with scaling and rotation. I tried a multi scale variant of it but a) the performance was really bad and b) the rectangle was of course always shown trying to search for the image. There was no way to actually confirm in the code if the logo was found or not.
ORB feature detection:
Also pretty slow (5-6 fps) but it worked ok-ish. The other problem was that also i never could be sure if the logo was in the picture or not. ORB found random matches even if the logo was not in the picture.
Like I said, I am very new to this. I would appreciate the help on what would be the best way to achieve:
Confirm if a picture A (around 200x200 pixels) is in ROI of camera picture (around 600x600 pixels).
This shouldnt take longer than 50ms per frame. I dont know if thats even possible though. So if a correct way to do this would take a bit longer than that, I would just do the work in a seperate thread and only analyze like every fifth camera frame or so.
Would appreciate any hints or code examples on how to achieve that. Thank you!
With logo detection, I would highly recommend using OpenCV HaarClassifier. It is easy to generate training samples from a collection of images of the logo, or one logo image with many distortions.
If you can use a few rules like the minimum and maximum size of the logo to be detected, and possible regions on the image where it can appear, you can run the detector at a speed better than you mention with ORB.

Display animation in java?

I am very very new at java (as in, I took one beginner course) so please don't get super technical when answering me.
Earlier today I learned how you can load an image in java and display it in an applet.
I found a step-by-step youtube video that helped me do this.
Now I want to know how I can load an animation in java. Is that something that can be done? And can I get step-by-step instructions on how to do it? Basically, I already have a short .wmv file and I would like to display it when I run the program.
It also has audio that I would like to play along with it.
(i'm actually trying to make a video game with an animated character. java can be used to program games, so this should be doable, right? i don't care about making a game the "right" way or the way game developers usually do it, right now i just want to figure out the simple task of displaying an animation in java.)
thanks!
First of all, the wmv extension stands for video, and an animation is not a video. Its either a spritesheet, a gif image ect. In order to create a even simple animation, you must first learn some basic object oriented programming, become comfortable in creating and using classes, than you can advance to making your own class for taking care of sprites and cutting an image in a way that you can use it ect.
Example of a simple spriteshet:
This spritesheet is an simple image showing you one way to implement your 2d animation. You just have to cut the image parts from it using some rectangles. For 3d, you must use some other software and you must know that they use different kinds of extensions.
I wont dive into code, for the simple reason that I do not have time right now, but if you want further help, give my some contact like skype, facebook ect, I would love to help.
You could try the Java Media Framework javax.media.*. (caveat: rather old framework)
It appears you simply need to embed a media file such as video or audio into an applet. This can be achieved through a player embedded into an applet, similar to an individual frame or a .GIF file, that would be able to handle the .WMV extension.
Assuming awareness of the basic structure of a Java program, the main declaration to get an instance of a player is of the generic form, after:
player = Manager.createRealizedPlayer( mediaURL );
or
player = Manager.createPlayer( file.toURL() );
Good idea to go through the JMF documentation.

Open webcam and set as background (question)

Best reader,
I'm stuck on one of my concepts.
I'm making a program which classroom children can measure themselves with.
This is what the program includes;
- 1 webcam (only used for a simple webcam view.)
- 2 phidgets (don't mind these.)
So, this was my plan. I'll draw a rectangle on the webcamview and make it repaint itself constantly.
When the repainting is stopped by one of the phidgets, the rectangle's value will be returned in centimeters or meters.
I've already written the code of the rectangle that's repainting itself and this was my result:
(It's a roundRectangle, the lines are kind of hard to see in this image, sorry about that.)
As you can see, the background is now simply black.
I want to set the background of this JFrame as a webcam view (if possible) and then draw the
rectangle over the webcam view instead of the black background.
I've already looked into jmf, fmj and such but am getting errors even after checking my webcam path and adding the needed jar libraries. So I want to try other options.
So;
- I simply want to open my webcam, use it as background (yes live stream, if possible in some way).
And then draw this rectangle over it.
I'm thus wondering if this is possible, or if there's other options for me to achieve this.
Hope you understand my situation, and please ask if anything's unclear.
EDIT:
I got my camera to open now trough java. The running camera is of type "Process".
This is where I got the code for my camera to open: http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/
I adjusted mine a little so it'll open my camera instead.
But now I'm wondering; is it possible to set a process as background of a JFrame?
Or can I somehow add the process to a JPanel and then add it to a JFrame?
I've tried several things without any succes.
My program as it is now, when I run it, opens the measuring frame and the camera view seperatly.
But the goal is to fuse them and make the repainting-rectangle paint over the camera view.
Help much appreciated!
I don't think it's a matter of setting a webcam stream as the background for your interface. More likely, you need to create a media player component, add it to your GUI, and then overlay your rectangles on top of that component.
As you probably know from searching for Java webcam solutions in Stack Overflow already, it's not easy, but hopefully the JMF Specs and API Guide will help you through it. The API guide is a PDF and has sections on receiving media streams, as well as sample code.

How to read the video frame and frame time file simultaneously using vlcj

I am working on VLCJ. I want to play a video where every frame's duration time is recorded in an independent file. So I plan to modify the input module of VLCJ in order to read the video content file and frame time file at the same time. Finally, the result should be VLCJ playing the video frame by frame and frame time file decides how long a video frame is playing.
To implement this, anybody knows which modules of VLCJ source code should be modified?
I'm not even sure you can do this with libvlc - do you mean the amount of time the frame should display for on the screen or actually does? If you mean should, then you should just be able to calculate this from the frame rate.
If you mean does then you might want to look at an API such as Xuggler which works with each frame directly.

How can I programmatically extract a preview image - like the first frame - from an FLV file in Java?

Updated:
Since my original request appears to be almost impossible, what's the next simplest solution? Invoke the swftools app? Make a JNI call to the ffmpeg lib?
Original:
This is related to "how to extract flash frames programmatically" but I am constrained to Java libraries only (and no JNI calls to C please). This also implies no calls to console apps like swftools. I'm looking for a pure Java (or at least JVM) solution.
Or if you want to do it directly from Java, you can use this code. It uses Xuggler, an open-source library for encoding and decoding video from java. Xuggler does use JNI behind the scenes to FFmpeg, but when using it that's totally invisible to you. Hop that helps.
Art
It is possible... if you can accept the end result being one frame FLV file (and not a proper image, like PNG or JPEG.) What is a single frame video, really? It's an image! This may very well give you the functionality you are looking for although it might seem a bit strange.
What you need to do is parse the FLV file. It's actually a very simple format. First, read up on some basic video compression terms. Second, read up on the FLV File Format specification on Adobe's site.
Roughly, an example FLV file would look like this inside:
'FLV' header
Meta data
Frame 0 - Audio
Frame 1 - Video I-Frame (all information to create a full image)
Frame 2 - Video P-Frame (just differential from last frame)
Frame 3 - Video P-Frame (just differential from last frame)
Frame 1 - Video I-Frame (all information to create a full image)
Frame 2 - Video P-Frame (just differential from last frame)
Frame 3 - Video P-Frame (just differential from last frame)
Frame 0 - Audio
Frame 5
...
Frame n
EOF
So, you'll search for the video I-frame you want as a picture. That, along with a basic FLV file header, together is all you need. Our ouput (be it a socket or a file) will be just:
'FLV' header
Frame 0 - Video I-Frame (all information to create a full image)
This all can be done in Java without any special tools. I've done it myself. For real.
Note that this approach applies only to FLV files, and not F4V (or other MP4-based file formats.)
Note that playback in SWF is controlled by ActionScript and declarative transformations, so to view that "first frame" properly in all cases you'd need to emulate the whole player. I'd say -- call external tools. What's the problem with them anyway? Is it something religion-mandated?

Categories