Get current video duration from CMSampleBufferRef

1.5k Views Asked by At

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

1

There are 1 best solutions below

1
On

The details which you need is in the video meta data. To get the video meta data you may need to convert your CMSampleBuffer to CVPixelBuffer.

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 and CMSampleBufferGetDecodeTimeStamp respectively.

For more info read Representations of Media