试图做一个15秒的视频CMTimeMake



我正在尝试做一个15秒的视频从一个UIImage的数组数组的内容数将改变。

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, %dn", frameCount, j);
            [NSThread sleepForTimeInterval:0.1];
        }
        j++;
    }
    if (!append_ok) {
        printf("error appending image %d times %dn, with error.", frameCount, j);
    }
    frameCount++;
}

我需要让每个图片持续时间show time = 15/[imageArray count],但我不知道这个CMTimeMake是如何工作的

我知道解决我的问题很简单,但我无法解决

任何提示或帮助都将非常感谢

最后我自己弄明白了

这是15秒视频的更正版本:D

CMTime frameTime = CMTimeMake(frameCount*15, [imageArray count]);

最新更新