0

我已经使用相机录制了实时视频AVCaptureVideoDataOuputAVAssetWriter但生成的视频没有持续时间。任何人都可以给出一个简短的想法或大致方向的观点以使持续时间有效吗?

4

2 回答 2

2

需要做的是定义一个初始的CMTime.

self.time = CMMakeTime( 0, 30 /* some frame time */ );

然后

[instanceAVAssetWriter setSessionAtSourceTime:self.time];

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);

和结束

CFRelease( sb );
self.time.value += 1;
于 2012-05-18T11:36:10.317 回答
0

这就是我所做的,类似于 NebulaFox 的回答。此代码在用于捕获视频数据的回调中。编写器已经初始化和设置。

switch (writer.status) {
        case AVAssetWriterStatusUnknown:

            startTime = CMSampleBufferGetPresentationTimeStamp(sample);

            [writer startWriting];
            [writer startSessionAtSourceTime:startTime];

            if (writer.status != AVAssetWriterStatusWriting) {
                break ;
            }  
....          
于 2012-05-18T20:38:36.180 回答