Getting frame rate from AVCaptureVideoDataOutput
I'm using AVCaptureVideoDataOutput
to grab frames, process them, and then write them to a MOV file using AVAssetWriter
. I understand that to set the minimum frame rate for the data input, I need only write
myDataOutput.minFrameDuration = someCMTime;
How can I get the actual frame duration for a given cycle of
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputS开发者_Go百科ampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
I need the actual duration so that I can input an accurate duration time for the asset writer. I've been playing around with using CMSampleBufferGetDuration(sampleBuffer)
, but with limited success. Any idea how to get this value?
Here is my current captureOutput method implementation:
- (void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
if([writerInput isReadyForMoreMediaData])
{
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
if(imageBuffer){
totalTime = CMTimeAdd(totalTime, CMSampleBufferGetDuration(sampleBuffer));
if([adaptor appendPixelBuffer:imageBuffer withPresentationTime:totalTime]){
NSLog(@"frame added");
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
}else{
NSLog(@"frame NOT added");
}
}else{
NSLog(@"no buffer");
}
}else{
NSLog(@"writerinput not ready");
}
}
In the end, the problem was that I was using AVAssetWriterInputPixelBufferAdaptor
, which requires the user to set the presentation time. Instead, I ended up just adding frames directly by calling appendBuffer
on AVAssetWriterInput
精彩评论