UIPanGesture 电影控制 Laggy
我有一个播放视频的应用程序。我想通过手势控制视频,即从左到右前进,从右到左后退。
我一直在使用 UIPanGesture,它允许我使用左/右平移手势来推进视频。唯一的问题是它非常慢,并且不会经常推进视频;尽管我的 NSLog 每秒触发大量次(取决于手势的速度和时间)。
这是我的手势处理程序代码:
- (void) handlePanGesture:(UIPanGestureRecognizer*)pan{
CGPoint translate = [pan translationInView:self.view];
CGFloat xCoord = translate.x;
double diff = (xCoord - currentTranslate);
currentTranslate = xCoord;
NSLog(@"%F",diff);
if (diff>=0) {
//If the difference is positive
moviePlayer.currentPlaybackTime = [moviePlayer currentPlaybackTime] + (diff/10);
} else {
//If the difference is negative
moviePlayer.currentPlaybackTime = [moviePlayer currentPlaybackTime] - (diff/10);
}
}
我不确定现在该去哪里,如何使该功能平滑并以不那么滞后的方式控制播放头?
I have an app that plays a video. I want to control the video by Gesture i.e. left-to-right for forwards and right-to-left for backwards.
I have been working with a UIPanGesture and it's allowing me to advance the video with a left/right pan gesture. The only issue is that it's very slow, and doesn't advance the video very often; despite my NSLog firing loads of times per second (depending on the speed and time of the gesture).
Here is my code for the gesture handler:
- (void) handlePanGesture:(UIPanGestureRecognizer*)pan{
CGPoint translate = [pan translationInView:self.view];
CGFloat xCoord = translate.x;
double diff = (xCoord - currentTranslate);
currentTranslate = xCoord;
NSLog(@"%F",diff);
if (diff>=0) {
//If the difference is positive
moviePlayer.currentPlaybackTime = [moviePlayer currentPlaybackTime] + (diff/10);
} else {
//If the difference is negative
moviePlayer.currentPlaybackTime = [moviePlayer currentPlaybackTime] - (diff/10);
}
}
I'm not sure where to go from here now, how do I make this function smooth and control the playhead in a less laggy manner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,使用FFMPEG对视频文件进行编码。根据我的经验,它的结果优于任何其他解决方案(我认为这一事实很奇怪)。
当涉及到搜索时,请确保编码的 GOP 长度没有设置得太高。大 GOP 使编码更加高效,但也使解码器的搜索变得困难。换句话说,您的编码拥有的 I 帧越多,您的搜索就越顺畅。
有关在 iPhone 上使用的视频编码的一些常规参数,请参阅 Rodrigo Polo 的 ffmpeg 备忘单 。
有关编码 H264 时 FFMPEG 参数的强大功能的详细信息,请参阅 libx264 映射和选项指南。
First of all, use FFMPEG for encoding the video files. From my experience, its results are superior to any other solution (a fact that I thought was bizarre).
When it comes to seeking, make sure the GOP-length of your encodings is not set too high. A large GOP makes encoding more efficient but also makes seeking hard for the decoder. In other words, the more I-frames your encodings have, the smoother you will be able to seek around.
For some general parameters on encoding video's for use on an iPhone, see the ffmpeg cheat sheet by Rodrigo Polo.
For some details on the mighty power of FFMPEGs parameters when encoding H264, see the libx264 mapping and options guide.