how to get/set frame position in vlcj?

为君一笑 提交于 2019-12-08 01:36:14

问题


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 !


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/13765681/how-to-get-set-frame-position-in-vlcj

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!