首页 文章

iOS AVFoundation如何使用CMTime每秒转换相机帧以创建游戏中时光倒流?

提问于
浏览
0

我有一个iPhone相机附件,可以9FPS捕获视频并将其作为单独的UIImages提供 . 我正在尝试将这些图像拼接在一起以创建使用AVFoundation相机所看到的内容的间隔拍摄视频 .

我不确定如何正确转换帧和时间来实现我想要的时间压缩 .

例如 - 我希望将1小时的真实片段转换为1分钟的时间间隔 . 这告诉我,我需要捕获每个第60帧并将其附加到游戏中时光倒流 .

Does the code below accomplish 60 seconds to 1 second time lapse conversion? 或者我需要通过 kRecordingFPS 添加一些乘法/除法?

#define kRecordingFPS 9
#define kTimelapseCaptureFrameWithMod 60
//frameCount is the number of frames that the camera has output so far
if(frameCount % kTimelapseCaptureFrameWithMod == 0)
{
    //...
    //convert image and prepare it for recording
    [self appendImage:image 
               atTime:CMTimeMake(currentRecordingFrameNumber++, kRecordingFPS)];
}

1 回答

  • 1

    你的代码每隔1/9会在你的电影中制作1帧,每次增加一帧frameIndex .

    结果应该是[frameCount的最大值] /(60 * 9)的影片 . 如果你有32400帧(1小时的胶片,9fps),这部电影将是{540:9 = 60s} .

    尝试在每次调用 appendImage:atTime: 时使用CMTimeShow()打印CMTime以进行检查 .

    //at 5 fps, 300 frames recorded per 60 seconds
    //to compress 300 frames into 1 second at 5 fps, we need to take every 300/5 = 60th frame
    //to compress 300 frames into 1 second at 15 fps, take every 300/15 = 20th frame
    //to compress 300 frames into 1 sec at 30 fps, take every 300/30 = 10th frame
    
    #define kReceivedFPS 9
    #define kStoreFPS 9
    #define kSecondsPerSecondCompression 60
    
    #define kTimelapseCaptureFrameWithMod (kSecondsPerSecondCompression * kReceivedFPS) / kStoreFPS
    

相关问题