我正在尝试使用 AVFoundation 播放视频。我将以下代码用于将播放推进一帧的按钮。
它间歇性地工作,在某些执行中它会做正确的事情并前进一帧,但大多数时候我必须按下按钮 3 或 4 次才能前进一帧。
这让我觉得这是某种精度问题,但我无法弄清楚它是什么。每次运行时,新的 CMTime 似乎都以相同的量前进。
我的另一个理论是,这可能是由于 currentTime 未按照我的帧速率设置为精确的帧边界(通过搜索视频引起的)。但我不知道如何以我的帧速率“捕捉”到最近的帧。
AVAssetTrack *videoTrack = ...;
Float64 frameRate = [videoTrack nominalFrameRate];
CMTime currentTime = [self.playerItem currentTime];
CMTime oneFrame = CMTimeMakeWithSeconds(1.0 / frameRate, currentTime.timescale);
CMTime added = CMTimeAdd(currentTime, oneFrame);
[self.player seekToTime:added toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
感谢您的帮助!
最佳答案
这不是很明显(因为奇怪的是它只在 AVPlayerItem 而不是 AVPlayer 中可用)但是如果 AVPlayerItem 为 canStepForward/canStepBackward
返回 YES 那么你可以调用 stepByCount:(NSInteger) stepCount:
向前或向后移动一定帧数。
关于ios - CMTime 和 AVFoundation 中的单帧移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6461789/