如何在解码video.mp4时获取iOS中每个视频帧的时间戳 [英] How to get the timestamp of each video frame in iOS while decoding a video.mp4

查看:685
本文介绍了如何在解码video.mp4时获取iOS中每个视频帧的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:
我正在编写 iOS应用尝试解码videoFile.mp4.我正在将 AVAssetReaderTrackOutput

Scenario:
I am writing an iOS app to try decode a videoFile.mp4. I am using AVAssetReaderTrackOutput with AVAssetReader to decode frames from the video file. This works very well. I get each & every frame from videoFile.mp4 basically using the following logic at the core.

代码:

AVAssetReader * videoFileReader;
AVAssetReaderTrackOutput * assetReaderOutput = [videoFileReader.outputs objectAtIndex:0];
CMSampleBufferRef sampleBuffer = [assetReaderOutput copyNextSampleBuffer];

sampleBuffer是此处每个视频帧的缓冲区.

sampleBuffer is the buffer of each video frame here.

问题:

  • 如何在这里如何获得每个视频帧的时间戳?
  • 换句话说&更详细地,如何如何获取从copyNextSampleBuffer返回的每个sampleBuffer的时间戳?
  • How can I get the timestamp of each video frame here ?
  • In other words & more detail, how can I get the timestamp of each sampleBuffer that i am returned from copyNextSampleBuffer?

PS:
请注意,我需要以毫秒为单位的时间戳.

PS:
Please note that I need the timestamp in milliseconds.

推荐答案

我终于得到了我问题的答案.接下来的两行可以获取从copyNextSampleBuffer

I got the answer to my question finally. Following 2 lines can get the frame timestamp of the sampleBuffer returned from copyNextSampleBuffer

CMTime frameTime = CMSampleBufferGetOutputPresentationTimeStamp(sampleBuffer);
double frameTimeMillisecs = CMTimeGetSeconds(frameTime) * 1000;

时间戳记在seconds中返回.因此,将其乘以1000即可转换为milliseconds

Timestamp is returned in seconds. Hence multiplying it by 1000 to convert to milliseconds

这篇关于如何在解码video.mp4时获取iOS中每个视频帧的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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