English 中文(简体)
IOS AVPlayer
原标题:IOS AVPlayer get fps

试图说明如何通过AVPlayer检索录像带。 AVPlayer 这个项目的汇率变化不定,但其数值在0到2之间(通常是在玩 playing时)。 任何人都知道如何获得视频数据。

卡车

问题回答

Use AVAssetTrack s nominalFrameRate property.

采用以下方法获取<代码>FrameRate: www.un.org/Depts/DGACM/index_spanish.htm

-(float)getFrameRateFromAVPlayer
{
  float fps=0.00;
  if (self.queuePlayer.currentItem.asset) {
    AVAssetTrack * videoATrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] lastObject];
    if(videoATrack)
    {
        fps = videoATrack.nominalFrameRate;
    }
  }
  return fps;
}

快速4版答复:

let asset = avplayer.currentItem.asset

let tracks = asset.tracks(withMediaType: .video)

let fps = tracks?.first?.nominalFrameRate

接手办理婚礼。

这一名义上似乎存在差异。 同一媒体在不同版本的Si-Rate返回。 我有一个录像带,其编号为每秒1个框架(125个框架),每个25个框架都有关键参数,在坐标7.x上装(名义)框架为1.0,而在SOS8中,(名义)比例为0.99。 似乎这种差别很小,但就我而言,我需要精确地对待电影的某一方位,这种差异使这种航海变形(电影是一系列演示幻灯片的编码)。 鉴于我已经知道我需要拍摄的录像带的底线速度(例如1片),我只能依靠这一价值,而不是以动态方式确定基准率(通过名义价值计算),然而,我想知道,就这个名义框架而言,我们的版本之间有这种差异。 任何想法?

AVPlayer的汇率是相对于其实际运行时间的速率,例如0.5是缓慢的,2是双重速度。

As Paresh Navadiya points out a track also has a nominalFrameRate variable however this seems to sometimes give strange results. the best solution I ve found so far is to use the following:

CMTime frameDuration = [myAsset tracksWithMediaType:AVMediaTypeVideo][0].minFrameDuration;
float fps = frameDuration.timescale/(float)frameDuration.value;

以上给出了可变框架率的略微出乎意料的结果,但可变框架率有点奇怪。 除此以外,在我的测验中,它还相应了症状。

EDIT ----

我发现,有时以上所述时间为CMtimeZero。 用于这项工作的第一阶段工作是建立一个有轨输出的AVAssetReader,把第一个框架和第二个框架的顶点推向后两个框架。

我不知道中能够帮助您计算基准率的任何内容。

<代码>AVPlayerItemrate property is the actback rate, no do to the framework rate.

比较容易的选择是获得<代码>AVAssetTrack,并读到nominalFrameRate。 仅创设一个<条码>AVAsset,你有一系列轨道。

或使用<条码>AVAssetReader,读到视频框架,获得介绍时间,并计算同一秒数,即几秒或整个录像。

This is not gonna work anymore, API has changed, and this post is old. :( The swift 4 answer is also cool, this is answer is similar.

请从<代码>AVPlayerItem上获取视频轨道,并检查该密码:]

private var numberOfRenderingFailures = 0
func isVideoRendering() -> Bool {
    guard let currentItem = player.currentItem else { return false }

    // Check if we are playing video tracks
    let isRendering = currentItem.tracks.contains { ($0.assetTrack?.mediaType == .video) && ($0.currentVideoFrameRate > 5) }
    if isRendering {
        numberOfRenderingFailures = 0
        return true
    }
    numberOfRenderingFailures += 1
    if numberOfRenderingFailures < 5 {
        return true
    }
    return false
}

In case of playing a Live stream player.currentItem?.asset doesn t have video tracks at all so you need to get FPS from player.currentItem?.tracks and AVPlayerItemTrack.currentVideoFrameRate property, e.g.:

var currentVideoFrameRate: Float {
  if let track = player.currentItem?.tracks.first(where: { $0.assetTrack?.mediaType == .video }) {
    return track.currentVideoFrameRate
  }
  return 0
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签