【问题标题】:Issue while scrubbing video using AVPlayer使用 AVPlayer 擦洗视频时出现问题
【发布时间】:2015-08-19 11:07:40
【问题描述】:

我正在使用 AVPlayer 从本地读取视频。当我浏览视频时,有时我会看到几秒钟的像素化视频或出现一段时间的绿屏。

以下是我的擦洗代码:

 - (void)playerControlView:(PlayerControlView *)playerControlView beganScrubbingAtPercent:(float)timePercent
{
    if (_avPlayer.rate > 0) {
        _resumePlayAfterScrub = YES;
    } else {
        _resumePlayAfterScrub = NO;
    }
}

- (void)playerControlView:(PlayerControlView *)playerControlView scrubbedToPercent:(float)timePercent
{
    if (_avPlayer.rate > 0) {
        [_avPlayer pause];
        [_loadingView startAnimating];
    }

    float durationSeconds = CMTimeGetSeconds(_avPlayerItem.duration);
    CMTime cmTime = CMTimeMakeWithSeconds(durationSeconds * timePercent, NSEC_PER_SEC);
    [_avPlayer seekToTime:cmTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];

    [_hideControlsTimer invalidate];
}

- (void)playerControlView:(PlayerControlView *)playerControlView finishedScrubbingAtPercent:(float)timePercent
{
    if (_resumePlayAfterScrub) {
        [_avPlayer play];
    }
    [self resetCurrentEventWithCopy:YES];
}

上面的代码我可以优化什么?

【问题讨论】:

    标签: ios video avplayer


    【解决方案1】:

    这可能是连续 IDR 帧之间的间隙很大的情况,因此当您搜索时,需要一段时间才能到达最近的 IDR 帧并清除图片缓冲区。在播放器到达 IDR 帧之前,它将无法正确解码流,这将导致您看到绿屏和像素化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2017-06-04
      • 1970-01-01
      • 2019-04-05
      相关资源
      最近更新 更多