帮助我理解 AVAssetWriter 中的 CMTime
我很难理解如何使用 AVAssetWriter 将 30fps 的运动 JPEG 流转换为视频文件。我没有得到的部分是 [适配器appendPixelBuffer:buffer withPresentationTimeresentTime]方法。
如果我想输出 30fps mpeg4 视频,如何计算 withPresentationTime 值?
视频源是实时传输 30fps 运动 JPEG 的摄像机。
欣赏任何想法。
谢谢
I'm having a hard time understanding how to convert a stream of motion JPEG at 30fps using the AVAssetWriter to a video file. The part I'm not getting is the
[adaptor appendPixelBuffer:buffer withPresentationTimeresentTime] method.
How do I calculate the withPresentationTime value if I want to output 30fps mpeg4 video?
The video source is a camera that streams 30fps motion JPEG in real time.
Appreciate any idea.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将需要使用 CMTimeMake 生成 CMTime 结构。您需要将每一帧的时间增加 1/30 秒。
这是一个示意图:
时间设置如图所示,最小时间分辨率为 1/30 秒。时间 / time_scale = 1 秒。我不确定 H.264 是否有具体要求。 AVFoundation 在捕获时使用 1000000000(1,000,000,000 或 10 亿)的时间尺度(根据我的经验)。
更新:
只是为了回顾。从 CMTime 结构来看:
时基在整个视频中保持不变。假设当前值为 10,时间刻度为 30。当前时间(以秒为单位)为 10/30 = 0.33333 秒。影片第 40 帧的时间值为 40/30 = 1.33333。因此,第 40 帧应在影片的 1.3333 秒处渲染。
我不确定这个时基是否适合 H.264 视频。我对规格不熟悉。我知道在捕获视频时,视频帧的呈现时间基数是 1000000000。从技术上讲,这应该不重要。时间是一个有理数——1000000000 / 1000000000 = 1 秒,30 / 30 = 1 秒。
You will need to generate a CMTime structure using CMTimeMake. You will need to increment the time by 1/30 of a second for each frame.
Here is a sketch:
With the time setup as shown,the smallest time resolution is 1/30 of a second. time / time_scale = 1 second. I am not certain if there is a specific requirement for H.264. AVFoundation uses a time scale of 1000000000 (1,000,000,000 or 1 billion) when capturing (in my experience).
Update:
Just to review. From the CMTime struct:
The timebase would stay the same throughout the video. Let say you have a current value of 10 with a time scale of 30. The current time in seconds is 10/30 = 0.33333 seconds. The time value for the 40th frame of your movie is 40/30 = 1.33333. So the 40th frame should render at 1.3333 seconds into the movie.
I am not sure if this time base is appropriate for an H.264 video. I am not familiar with the spec. I know when capturing video the presentation time base for video frames is 1000000000. Technically it should not matter. The time is a rational number -- 1000000000 / 1000000000 = 1 second and 30 / 30 = 1 second.