gpt4 book ai didi

avfoundation - 帮助我理解 AVAssetWriter 中的 CMTime

转载 作者:行者123 更新时间:2023-12-04 04:16:35 25 4
gpt4 key购买 nike

我很难理解如何使用 AVAssetWriter 将 30fps 的运动 JPEG 流转换为视频文件。我没有得到的部分是[适配器 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 秒。

关于avfoundation - 帮助我理解 AVAssetWriter 中的 CMTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5396800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com