0

我正在尝试从 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 是如何工作的

我知道解决我的问题很简单,但我想不通

任何提示或帮助将不胜感激

4

1 回答 1

2

最后我自己想通了

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

CMTime frameTime = CMTimeMake(frameCount*15, [imageArray count]);
于 2014-06-20T03:58:20.730 回答