Reputation: 8323
I have recorded live video from the camera using AVCaptureVideoDataOuput
and AVAssetWriter
but the resulting video has no duration. Can anyone give a brief idea or a point in the general direction to get the duration working?
Upvotes: 0
Views: 866
Reputation: 3596
This is what I do which is similar to NebulaFox's answer. This code is in the callback for the capturing of video data. The writer has already been initialized and setup.
switch (writer.status) {
case AVAssetWriterStatusUnknown:
startTime = CMSampleBufferGetPresentationTimeStamp(sample);
[writer startWriting];
[writer startSessionAtSourceTime:startTime];
if (writer.status != AVAssetWriterStatusWriting) {
break ;
}
....
Upvotes: 0
Reputation: 8323
What needs to be done is define an initial CMTime
.
self.time = CMMakeTime( 0, 30 /* some frame time */ );
then
[instanceAVAssetWriter setSessionAtSourceTime:self.time];
on captureOutput:didOutputSampleBuffer:fromConnection:
CMSampleBufferRef sb;
CMSampleTimingInfo sampleTimingInfo;
sampleTimingInfo.duration = CMTimeMake(1,30);
sampleTimingInfo.presentationTimeStamp = self.time;
sampleTimingInfo.decodeTimeStamp = kCMTimeInvalid;
CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, sampleBuffer, 1, &sampleTimingInfo, &sb);
and the end
CFRelease( sb );
self.time.value += 1;
Upvotes: 2