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

标签 ios objective-c video avfoundation cmtime

我有一个 iPhone 摄像头附件,可以以 9FPS 的速度捕捉视频,并将其作为单独的 UIImages 提供。我正在尝试将这些图像拼接在一起,以使用 AVFoundation 创建相机所见内容的延时视频。

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

例如 - 我想将 1 小时的真实生活片段转换为 1 分钟的延时摄影。这告诉我我需要每 60 帧捕捉一次并将其附加到延时摄影。

下面的代码是否完成了 60 秒到 1 秒的延时转换?还是我需要通过 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/9 秒将 60 帧中的 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

关于iOS AVFoundation 如何转换每秒的相机帧数以使用 CMTime 创建游戏中时光倒流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35042837/

相关文章:

iphone - 我想跟踪谁通过 ios 访问网站的电话号码

objective-c - 为什么 CGLayers 不混合?

objective-c - 更改空间后不显示 NSWindow 翻转动画

iphone - iPhone 4 中的多任务 Xcode 3.2 info.plist 中的 ,"application does not run in back ground"选项

iphone - 当用户在 iOS 5 上锁定屏幕时 applicationMusicPlayer 停止

ios - 核心数据支持的 UITableView 在删除单元格时出错

javascript - 使用 Javascript 或 PHP 更改视频的颜色类型

javascript - HTML 视频播放器时间隐藏控件

ios - 在静态 iOS 框架上执行 XCUITests

html - 如何在页面中嵌入 YouTube 视频并防止 URL 窃取