Tag: cmtime

如何从iOS的ALAsset获取video的缩略图图像?

我想从video中获取每帧的缩略图图像,然后将这些图像保存在可变数组图像中。 我想用这个图像作为animation播放。 NSURL* assetURL = [self.asset valueForProperty:ALAssetPropertyAssetURL]; NSDictionary* assetOptions = nil; AVAsset* myAsset = [[AVURLAsset alloc] initWithURL:assetURL options:assetOptions]; self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset]; int duration = CMTimeGetSeconds([myAsset duration]); for(int i = 0; i<duration; i++) { CGImageRef imgRef = [self.imageGenerator copyCGImageAtTime:CMTimeMake(i, duration) actualTime:NULL error:nil]; UIImage* thumbnail = [[UIImage alloc] initWithCGImage:imgRef scale:UIViewContentModeScaleAspectFit orientation:UIImageOrientationUp]; [thumbnailImages addObject:thumbnail]; } 我使用上面的代码来获取缩略图图像,但问题是如果有一个2秒的video,我只得到2个缩略图,但我想要20个缩略图(10个缩略图每秒)。 那么,如何使用CMTimeMake来获取每一秒的缩略图

CMTime和AVFoundation中的单帧移动

我试图用AVFoundation播放video。 我正在使用下面的代码为一个button提前播放一帧。 它间歇地工作,在一些执行中,它会做正确的事情,并提前一帧,但大多数时间,我将不得不按下button3或4次,才会推进一个框架。 这让我觉得这是一个精确的问题,但我无法弄清楚它是什么。 每次运行时,新的CMTime似乎都以相同的数量前进。 我的另一个理论是,它可能是由于currentTime没有被设置为一个精确的帧边界在我的帧速率(通过寻找video)。 但是我不知道如何以我的帧率“捕捉”到最近的帧。 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]; 谢谢你的帮助!

AVAssetWriterInputPixelBufferAdaptor和CMTime

我正在用AVAssetWriterInputPixelBufferAdaptor写一些帧到video,而行为与时间不是我所期望的。 如果我只写一帧: [videoWriter startSessionAtSourceTime:kCMTimeZero]; [adaptor appendPixelBuffer:pxBuffer withPresentationTime:kCMTimeZero]; 这给我一个长度为零的video,这是我所期望的。 但是如果我继续添加第二帧: // 3000/600 = 5 sec, right? CMTime nextFrame = CMTimeMake(3000, 600); [adaptor appendPixelBuffer:pxBuffer withPresentationTime:nextFrame]; 我得到了十秒的video,我期待五个。 这里发生了什么? withPresentationTime是否以某种方式设置了帧的开始和持续时间? 请注意,我没有调用endSessionAtSourceTime ,只是finishWriting 。

试图了解CMTime

我已经看到CMTime的一些例子 (三个单独的链接),但我仍然不明白。 我使用AVCaptureVideoDataOutput AVCaptureSession和我想设置输出的最大和最小帧速率。 我的问题是我只是不明白的CMTime结构。 显然CMTimeMake(价值,timeScale)应该给我价值帧每1 / timeScale秒为总价值/ timeScale秒,或者我得到那个错误? 为什么不把这个logging下来以解释这是什么? 如果真的这样工作,我怎么会得到它有无限的帧数? 如果真的很简单,我很抱歉,但没有任何点击。