how to get/set frame position in vlcj? - java

How to -
1.get the current frame position of an audio/video track ??
2.how to go to a specific frame position of a track ??
using vlcj sdk .
any code snippets would be highly appreciated !

Actually you can do this with a little math. It's not the cleanest way but it is kind of easy to understand.
VLCj allows you to get the length of your media using .getLength(). However, note that this returns the length of the media in milliseconds. Moreover, you can get the frames/second of your media using .getFPS().
So now you can get the total number of frames as:
total_frames = .getFPS * .getLength() /1000;
Then you can use .getPosition() to find out where you currently are in milliseconds, you can then translate that to a frame. This returns as a percentage.
current_frame = .getPosition() * total_frames;
Now, if you want to go to a specific frame let's call that desired_frame. You can use the .setPosition() which takes in a percentage. So you need to determine the percentage of the total that represents the frame you want to jump to.
.setPosition((float)desired_frame/total_frames);

VLCJ isn't really set up for this kind of frame by frame access directly - you can use setTime() and getTime() on the mediaplayer object, but that will return time from the beginning in milliseconds rather than the frame. Of course, if you know the frame rate it's then relatively trivial to convert from one to the other.
If you need lower level operations than VLCJ provides, then you may want to have a look at Xuggler.

Related

Understanding the Android Visualizer class

I'm new to Android development (though I know a decent amount of java) and I'm trying to make a very simple plugin that can pass some variables to tasker. The end goal is that I want to use them for a sort of bar visualizer for music in klwp. I want to use the Visualizer class for this, but I am having trouble making heads or tails of how to use it by looking at the official documentation and various questions on here and some example code.
Say the bar visualizer, like in the link above, has 64 bars. Essentially all I want to do is get an array of 64 integers with a relative value of say 1-100 based on the FFT data? of the playing audio and then update them a few times a second. So for example, cut the frequency band into 64 "slices" and then take the average intensity of each one to get essentially the height of the corresponding bar on the visualizer. I don't even need to draw them in java, I just need the integers.
I don't know if I am going about it all wrong but I am having serious trouble figuring out how to implement that using Visualizer, I was wondering if someone could give me an example of how to implement it or explain how I would go about it.
Thanks!
You can use these third party library for audio visualization:
1)https://android-arsenal.com/details/1/4892 ( SIRIWaveView)
2)https://android-arsenal.com/details/1/4622 (Audiogarm)

Skip frames in video playback with MediaExtractor and MediaCodec

I'm using MediaExtractor/MediaCodec to decode a video and render it to a TextureView. As a template, I've used the code from: https://github.com/vecio/MediaCodecDemo/blob/master/src/io/vec/demo/mediacodec/DecodeActivity.java
I'd like to be able to playback the video at 2x speed. Luckily, the media encoding/decoding is fast enough so that I can accomplish this by letting the MediaCodec decode every frame, and then only render every other frame to the screen. However this doesn't feel like a great solution, particularly if you want to increase playback by an arbitrary value. For example, at 10x speeds, the Codec is not able to decode frames fast enough to playback every 10th frame at 30 fps.
So instead I'd like control playback by calling MediaExtractor.advance() multiple times to skip frames that don't need to be decoded. For example:
...
mDecoder.queueInputBuffer(inIndex, 0, sampleSize, mExtractor.getSampleTime(), 0);
for (i = 0; i < playbackSpeedIncrease; i++) {
mExtractor.advance();
}
...
With this code, in theory the extractor should only extract every nth frame, where n is defined by the variable 'playbackSpeedIncrease'. For example, if n = 5, this should advance past frames 1-4 and only extract frame 5.
However, this does not work in practice. When I run this code, the image rendered to the screen is distorted:
Does anyone know why this is? Any suggestions for better ways to playback videos at an arbitrary speed increase?
You can't generally do this with AVC video.
The encoded video has "key" (or "sync" or "I") frames that hold full images, but the frames between key frames hold "diffs" from the previous frames. You can find some articles at wikipedia about video encoding methods, e.g. this one. You're getting nasty video because you skipped a key frame and now the diffs are being computed against the wrong image.
If you've ever seen video fast-forward smoothly but fast-reverse clunkily, e.g. on a TiVo, this is why: the video decoder plays forward quickly, but in reverse it just plays the I-frames, holding them on screen long enough to get the desired rate. At "faster" forward/reverse it evens out because the device is just playing I-frames. You can do something similar by watching for the SAMPLE_FLAG_SYNC flag on the frames you get from MediaExtractor.
In general you're limited to either playing the video as fast as the device can decode it, or playing just the key frames. (If you know enough about the layout of a specific video in a specific encoding you may be able to do better, e.g. play the I and P but not the B, but I'm not sure that's even possible in AVC.)
The frequency of I frames is determined by the video encoder. It tends to be one or two per second, but if you get videos from different sources then you can expect the GOP size (group-of-pictures, i.e. how many frames there are between I-frames) to vary.

Screen recorder, issue when converting

I'm using BufferedImage to capture the screen images and then JpegImagesToMovie class to convert it to .mov, which I found online.
When I run the output file, it's at a super speed and not the original speed I recorded at. Can someone tell me what need to do in order to get a real-time speed video?
You probably need to put in Thread.sleep(1 / fps). Try to see if that works.
You are possibly using the Oracle's example to convert images to .mov. The problem is that the size of the file generated is very very large. You need to move to something more efficient and something with a little bit more abstraction. How about using Xuggler for making screen recorder ?
Now, to the question of making the movie slower. You need to reduce the frame rate. If you have need 60 fps, your 1 second will need to be shared by 60 frames. So for n fps, you need to have (1/n) sleep duration for your thread.

Graphics Jittering in Java 2D game

I am making a game and have currently run into a problem where the graphics jitter. It starts to jitter from the top when you press the AWSD keys. The jittering starts from the top and spreads to the whole screen.
Here is a video file: https://dl.dropboxusercontent.com/u/94218355/javaw%202013-08-30%2010-36-45-171.avi
Here is the game file:https://dl.dropboxusercontent.com/u/94218355/Game.rar
The game file is so you can test it out yourself.
Please look at Screen.java as I think this is where the error is hiding.
You should use double buffering or page flipping to avoid jitter.
This is an educated guess since no source is available. It is likely the issue is related to how you handle input, there is a common bug with input on java2d games due to the fact that there is an inherent latency between keypresses if the keys are registered through KeyListener interface. If you hold down a key (a) what you would expect would be aaaaa.. but what you actually get is a|inputlag|a|inputlag|... this latency is quite big (much higher than usual 60 FPS) and so when you hold down keys to move the camera about the camera seems jittery.
The simple solution is to use boolean flags for keys and set them to true once a key is pressed down and false once it is released, see my sample code here. or use keybindings.

Java Bot get values from window/screen

ok this is my first time ever posting. Sorry if i am not specific enough.
i am trying to make a bot using java coding, using eclipse. the game i am playing(dark summoner) does not have status bars but, fractions such as 23/47 energy 240/300 battle points. i can't find a way to get the values from the top or the screen into my code. also to make this easier i thought i could get my code to focus on the window opened with the game in it, and can not find a way to do that.
the idea behind the bot so far is to have it attack when i reach enough battle points. when this is achieved i plan on making it usable on any or most energy based games like mafia wars age of baymont millions to list
so in short my question is how do i get values from a specific area of an image, to my code using java
oh yeah i am a noob
You cannot get the number from the image, but you can assign number to the image. After displaying proper image, you will know what number is connected with it. Divide whole number into digits and display each digit alone, composing the whole number.
If the only aim of the application is to get text from a image, you can think about image processing and some algorithms, but it time consuming.

Categories