0
在AVPlayer中播放視頻時,逐幀提取所有圖像。想要在AVPlayer中播放視頻時逐幀提取所有圖像
例如,如果視頻速度爲30 fps,視頻持續時間爲10秒,那麼我應該可以從視頻中獲得300幅圖像。使用此代碼
目前我提取圖像:
[self.player addPeriodicTimeObserverForInterval:CMTimeMake(1,fps)的隊列:dispatch_get_main_queue()usingBlock:
^(CMTime time) {
[weakSelf readNextMovieFrame];
}];
(void) readNextMovieFrame {
CMTime outputItemTime = [[self playerItem] currentTime];
CMTime t = [[self playerItem] currentTime];
CMTime d = [[self playerItem] duration];
if ([_output hasNewPixelBufferForItemTime:outputItemTime]) {
CVPixelBufferRef buffer = [_output copyPixelBufferForItemTime:outputItemTime itemTimeForDisplay:nil];
CIImage *image = [CIImage imageWithCVPixelBuffer:buffer];
UIImage *imageUI = [self makeUIImageFromCIImage:image];
[self saveImage];
//CFRelease(sampleBuffer);
CVBufferRelease(buffer);
}
}