简体   繁体   English

如何在vlcj中获取/设置框架位置?

[英]how to get/set frame position in vlcj?

How to - 1.get the current frame position of an audio/video track ?? 如何-1.获取音频/视频轨道的当前帧位置? 2.how to go to a specific frame position of a track ?? 2.如何去一个轨道的特定帧位置? using vlcj sdk . 使用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() . VLCj允许您使用.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() . 此外,您可以使用.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. 然后,您可以使用.getPosition()以毫秒为单位找出当前位置 ,然后将其转换为帧。 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 . 现在,如果您要转到特定的帧,我们将其称为desired_frame You can use the .setPosition() which takes in a percentage. 您可以使用.setPosition()来获取百分比。 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. VLCJ并不是真正针对这种逐帧访问而直接设置的-您可以在mediaplayer对象上使用setTime()getTime() ,但这将从毫秒开始而不是从帧开始返回时间。 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. 如果您需要比VLCJ提供的操作低的操作,那么您可能需要看看Xuggler。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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