我开发了一款iOS应用程序,可以将捕获的相机数据保存到文件中,并且我使用了
(void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
为了捕获CMSampleBufferRef并将其编码为H264格式,帧将使用AVAssetWriter
保存到文件中。
我按照示例源代码创建了此应用:
现在我想获取保存的视频帧的时间戳以创建新的电影文件。 为此,我已经完成了以下工作:
定位文件并创建
AVAssestReader
来读取文件
CMSampleBufferRef sample = [asset_reader_output copyNextSampleBuffer];
CMSampleBufferRef buffer;
while ([assestReader status] == AVAssetReaderStatusReading) {
buffer = [asset_reader_output copyNextSampleBuffer];
// CMSampleBufferGetPresentationTimeStamp(buffer);
CMTime presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(buffer);
UInt32 timeStamp = (1000 * presentationTimeStamp.value) / presentationTimeStamp.timescale;
NSLog(@"timestamp %u", (unsigned int) timeStamp);
NSLog(@"reading");
// CFRelease(buffer);
}
打印的值给了我一个错误的时间戳,我需要获取帧捕获的时间。
有没有办法获取帧捕获的时间戳?
我读了一个答案来获取它的时间戳但是它并没有很好地说明我的问题。上面的链接在这里an answer。
更新:
在将样本写入文件之前,我读取了样本时间戳,它给了我一个 xxxxx
的值 (33333.23232
)。 但是尝试读取文件后却得到了不同的值。 这是什么原因?