我正在尝试从 UIImage 的数组中制作一个 15 秒的视频,该数组的内容编号将发生变化。
NSUInteger fps = 30;
int frameCount = 0;
float numberOfSecondsPerFrame = 15/[imageArray count];
float frameDuration = fps * numberOfSecondsPerFrame;
NSLog(@"**************************************************");
for(UIImage * img in imageArray)
{
buffer = [self pixelBufferFromCGImage:[img CGImage]];
BOOL append_ok = NO;
int j = 0;
while (!append_ok && j < 30) {
if (adaptor.assetWriterInput.readyForMoreMediaData) {
//print out status:
NSLog(@"Processing video frame (%d,%d)",frameCount,[imageArray count]);
CMTime frameTime = CMTimeMake(frameCount*frameDuration,(int32_t) fps);
NSLog(@"seconds = %f, %u, %d", CMTimeGetSeconds(frameTime),fps,j);
append_ok = [adaptor appendPixelBuffer:buffer withPresentationTime:frameTime];
if(!append_ok){
NSError *error = videoWriter.error;
if(error!=nil) {
NSLog(@"Unresolved error %@,%@.", error, [error userInfo]);
}
}
}
else {
printf("adaptor not ready %d, %d\n", frameCount, j);
[NSThread sleepForTimeInterval:0.1];
}
j++;
}
if (!append_ok) {
printf("error appending image %d times %d\n, with error.", frameCount, j);
}
frameCount++;
}
我需要使每张图片的持续时间显示时间 = 15/[imageArray count] 但我无法弄清楚这个 CMTimeMake 是如何工作的
我知道解决我的问题很简单,但我想不通
任何提示或帮助将不胜感激