
(voID) captureOutput:(AVCaptureOutput *)captureOutput dIDOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
捕获CMSampleBufferRef,并将编码为H264格式,帧将使用AVAssetWriter保存到文件.
我遵循示例源代码来创建此应用程序:
http://www.gdcl.co.uk//2013/02/20/iOS-Video-Encoding.html
现在我想获得保存的视频帧的时间戳来创建一个新的电影文件,
为此我做了以下事情
1)找到文件并创建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); 打印值给我错误的时间戳,我需要获取帧的捕获时间.
有没有办法获得帧捕获的时间戳,
我已阅读以下链接以获取时间戳,但它没有正确地阐述我的问题在How to set timestamp of CMSampleBuffer for AVWriter writing以上
更新
在写入文件之前,我读取了时间戳,它给了我一个xxxxx值(33333.23232)
之后,我试图读取文件,它给了我不同的价值,这个的任何具体原因?
解决方法 文件时间戳与捕获时间戳不同,因为它们相对于文件的开头.这意味着它们是您想要的捕获时间戳,减去捕获的第一帧的时间戳记:presentationTimeStamp = fileFramePresentationTime + firstFrameCaptureTime
所以当从文件读取时,这应该计算你想要的捕获时间戳:
CMTime firstCaptureFrameTimeStamp = // the first capture timestamp you see CMTime presentationTimeStamp = CMTimeAdd(CMSampleBufferGetPresentationTimeStamp(buffer),firstCaptureFrameTimeStamp);
如果您在应用程序启动之间进行此计算,则需要对第一帧捕获时间进行序列化和反序列化,您可以使用CMTimecopyAsDictionary和CMTimeMakeFromDictionary进行 *** 作.
您可以通过AVAssetWriter的元数据属性将其存储在输出文件中.
总结以上是内存溢出为你收集整理的如何从iOS中的CMSampleBufferRef获取相机数据当前捕获的时间戳全部内容,希望文章能够帮你解决如何从iOS中的CMSampleBufferRef获取相机数据当前捕获的时间戳所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)