帮我了解AVAssetWriter中的CMTime [英] Help me understand CMTime in AVAssetWriter

查看:108
本文介绍了帮我了解AVAssetWriter中的CMTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难理解如何使用AVAssetWriter将30fps的运动JPEG流转换为视频文件.我没有得到的部分是 [adaptor appendPixelBuffer:带有PresentationTimeresentTime的缓冲区]方法.

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.

如果要输出30fps的mpeg4视频,如何计算withPresentationTime值?

How do I calculate the withPresentationTime value if I want to output 30fps mpeg4 video?

视频源是一台实时传输30fps动态JPEG的摄像机.

The video source is a camera that streams 30fps motion JPEG in real time.

欣赏任何想法.

谢谢

推荐答案

您将需要使用CMTimeMake生成CMTime结构.您需要将每一帧的时间增加1/30秒.

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.

这是草图:

CMTime time = CMTimeMake(0, 30); // (time, time_scale)

for(each image) {
  [adaptor appendPixelBuffer:buffer withPresentationTime:time]
  time.value += 1; 
}

使用如图所示的时间设置,最小时间分辨率为1/30秒. time/time_scale = 1秒.我不确定H.264是否有特定要求.捕获时(根据我的经验),AVFoundation使用的时间标度为1000000000(1,000,000,000或10亿).

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).

更新:

只需进行审查.从CMTime结构:

Just to review. From the CMTime struct:

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秒处呈现.

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.

我不确定此时基是否适合H.264视频.我对规范不熟悉.我知道在捕获视频时,视频帧的显示时基为1000000000.从技术上讲,这并不重要.时间是一个有理数-1000000000/1000000000 = 1秒和30/30 = 1秒.

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.

这篇关于帮我了解AVAssetWriter中的CMTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆