UIPanGesture 电影控制 Laggy

发布于 2024-10-27 11:23:57 字数 794 浏览 9 评论 0原文

我有一个播放视频的应用程序。我想通过手势控制视频,即从左到右前进,从右到左后退。

我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彻夜缠绵 2024-11-03 11:23:57

首先,使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文