【发布时间】:2013-03-09 18:12:22
【问题描述】:
我正在开发一个 iOS 应用程序,它从互联网连接随机获取 UIImages,并在图像进入时逐步从它们构建一个视频文件。我让它工作了一点,但图像没有到达的事实以相同的速度一直在弄乱视频。
当每个新的 UIImage 到达时,我如何重新计算 CMTime,以便它针对到达的 UIImage 的不同帧速率进行调整,这些帧速率可以在毫秒到秒之间的任何时间到达??
这是我到目前为止所做的,一些代码没有显示,但这是基本的东西
.
.
adaptor = [AVAssetWriterInputPixelBufferAdaptor
assetWriterInputPixelBufferAdaptorWithAssetWriterInput: videoStream
sourcePixelBufferAttributes:attributes];
CMTime frameTime=CMTimeMake(1,10); // assumed initial frame rate
.
.
-(void)addImageToMovie:(UIImage*)img {
append_ok=FALSE;
buffer = [self pixelBufferFromCGImage:[img CGImage] andSize:img.size];
while (!append_ok) {
if (adaptor.assetWriterInput.readyForMoreMediaData){
frameTime.value +=1;
append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
[NSThread sleepForTimeInterval:0.01];
} else {
[NSThread sleepForTimeInterval:0.01];
}
}
if(buffer) {
CVBufferRelease(buffer);
}
}
【问题讨论】:
标签: ios video uiimage recording