How can I get current recorded video duration from CMSampleBufferRef in delegate method
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;
Please guide with sample code
The details which you need is in the video meta data. To get the video meta data you may need to convert your
CMSampleBuffer
toCVPixelBuffer
.CMSampleBuffer
is a Core Foundation-style opaque type; an instance contains the sample buffer for a frame of video data.CVPixelBuffer
is core video pixels from the Sample Buffer.You can get the Pixel buffer from sample buffer by using the below
CMSampleBufferGetImageBuffer:
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(<#A CMSampleBuffer#>);
Once you got the pixel buffer you can get the video meta datas like timing and format informations.
To get timing informations use
CMSampleBufferGetPresentationTimeStamp
andCMSampleBufferGetDecodeTimeStamp
respectively.For more info read Representations of Media