我很难理解如何使用 AVAssetWriter 将 30fps 的运动 JPEG 流转换为视频文件。我没有得到的部分是 [adaptor appendPixelBuffer:buffer withPresentationTimeresentTime] 方法。
如果我想输出 30fps mpeg4 视频,如何计算 withPresentationTime 值?
视频源是一个实时传输 30fps 运动 JPEG 的摄像机。
欣赏任何想法。
谢谢
我很难理解如何使用 AVAssetWriter 将 30fps 的运动 JPEG 流转换为视频文件。我没有得到的部分是 [adaptor appendPixelBuffer:buffer withPresentationTimeresentTime] 方法。
如果我想输出 30fps mpeg4 视频,如何计算 withPresentationTime 值?
视频源是一个实时传输 30fps 运动 JPEG 的摄像机。
欣赏任何想法。
谢谢
您将需要使用 CMTimeMake 生成一个 CMTime 结构。您需要将每一帧的时间增加 1/30 秒。
这是一个草图:
CMTime time = CMTimeMake(0, 30); // (time, time_scale)
for(each image) {
[adaptor appendPixelBuffer:buffer withPresentationTime:time]
time.value += 1;
}
使用如图所示的时间设置,最小时间分辨率为 1/30 秒。时间 / time_scale = 1 秒。我不确定是否对 H.264 有特定要求。AVFoundation 在捕获时使用 1000000000(1,000,000,000 或 10 亿)的时间尺度(根据我的经验)。
更新:
只是为了回顾。从 CMTime 结构:
CMTimeValue value; /*! @field value The value of the CMTime. value/timescale = seconds. */
CMTimeScale timescale; /*! @field timescale The timescale of the CMTime. value/timescale = seconds. */
整个视频的时基将保持不变。假设您的当前值为 10,时间刻度为 30。当前时间(以秒为单位)为 10/30 = 0.33333 秒。影片第 40 帧的时间值为 40/30 = 1.33333。所以第 40 帧应该在 1.3333 秒处渲染到电影中。
我不确定这个时基是否适合 H.264 视频。我不熟悉规范。我知道在捕获视频时,视频帧的呈现时间基数是 1000000000。从技术上讲,这应该无关紧要。时间是一个有理数——1000000000 / 1000000000 = 1 秒,30 / 30 = 1 秒。