【发布时间】:2020-12-07 19:25:50
【问题描述】:
我开发了一个 iOS 应用程序,它将捕获的相机数据保存到一个文件中,我使用了
(void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
捕获 CMSampleBufferRef 并将其编码为 H264 格式,并使用 AVAssetWriter 将帧保存到文件中。
我关注the sample source code创建了这个应用:
现在我想获取保存的视频帧的时间戳来创建一个新的电影文件。为此,我做了以下几件事
-
找到文件并创建
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)。在我尝试读取文件后,它给了我不同的价值。有什么具体原因吗??
【问题讨论】:
-
@fireclaw48 我找到了这个链接,但它没有给出正确的答案,我认为这是设置新的时间戳
-
我也遇到了同样的问题,你得到答案了吗?
标签: ios objective-c avfoundation cmsamplebufferref