简体   繁体   中英

how to get/set frame position in vlcj?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM