Ger*_*man 2 avfoundation avassetwriter
我很难理解如何使用AVAssetWriter将动态JPEG流以30fps转换为视频文件.我没有得到的部分是[adapter 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;
}
Run Code Online (Sandbox Code Playgroud)
通过如图所示的时间设置,最小时间分辨率为1/30秒.time/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. */
Run Code Online (Sandbox Code Playgroud)
时基在整个视频中保持不变.假设您的当前值为10,时间刻度为30.当前时间(秒)为10/30 = 0.33333秒.电影第40帧的时间值为40/30 = 1.33333.所以第40帧应该在电影的1.3333秒处呈现.
我不确定这个时基是否适合H.264视频.我不熟悉这个规范.我知道在捕获视频时,视频帧的显示时基是10亿.从技术上讲,这应该没关系.时间是有理数 - 1000000000/1000000000 = 1秒,30/30 = 1秒.
| 归档时间: |
|
| 查看次数: |
5865 次 |
| 最近记录: |