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?
Asked
Active
Viewed 851 times
0

NebulaFox
- 7,813
- 9
- 47
- 65
-
Are you setting [AVAssetWriter startSessionAtSourceTime] to the first sample buffer's PTS? Are you calling [AVAssetWriter finishWriting]? You should show some code. – Rhythmic Fistman May 18 '12 at 09:17
2 Answers
2
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;

NebulaFox
- 7,813
- 9
- 47
- 65
-
Can't even describe the frustration this answer brought an end to. Thanks! – Clay Garrett Nov 24 '15 at 19:56
0
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 ;
}
....

Steve McFarlin
- 3,576
- 1
- 25
- 24