使用 AVAssetreader 从文件中读取样本缓冲区时遇到问题。读取的样本的时间戳似乎是乱序的。这是预期的结果还是我做错了什么。下面是我正在使用的读写代码——
[assetWriterInput requestMediaDataWhenReadyOnQueue:serializationQueue usingBlock:^{
if (finished)
return;
BOOL completedOrFailed = NO;
// Read samples in a loop as long as the asset writer input is ready
while ([assetWriterInput isReadyForMoreMediaData] && !completedOrFailed)
{
CMSampleBufferRef sampleBuffer = [assetReaderOutput copyNextSampleBuffer];
CMTime originalTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
if (sampleBuffer != NULL)
{
CMTime cmm1 = CMSampleBufferGetOutputDuration(sampleBuffer);
NSLog(@"Timestamps == %f",time);
CMSampleBufferRef newSampleBuffer;
CMSampleTimingInfo sampleTimingInfo;
sampleTimingInfo.duration = cmm1;
float milliseconds = videoPTM * 600;
sampleTimingInfo.presentationTimeStamp = CMTimeMake((int)milliseconds, 600);
sampleTimingInfo.decodeTimeStamp = kCMTimeInvalid;
CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault,
sampleBuffer,
1,
&sampleTimingInfo,
&newSampleBuffer);
BOOL success = YES;
success = [assetWriterInput appendSampleBuffer:newSampleBuffer];
CFRelease(newSampleBuffer);
newSampleBuffer = NULL;
CFRelease(sampleBuffer);
sampleBuffer = NULL;
completedOrFailed = !success;
videoPTM+=CMTimeGetSeconds(cmm1);
}
else
{
completedOrFailed = YES;
}
}
if (completedOrFailed)
[self callCompletionHandlerIfNecessary];
当我打印读取的样本的时间戳时,它们的顺序不是这样......
Video Timestamps == 6.971667
Video Timestamps == 7.055000
Video Timestamps == 7.220000
Video Timestamps == 7.136667
Video Timestamps == 7.386667
Video Timestamps == 7.303333
Video Timestamps == 7.470000
Video Timestamps == 7.635000
请让我知道相同的原因以及如何创建具有不同演示时间的示例副本。