iOS确定视频中的帧数 [英] iOS Determine Number of Frames in Video
本文介绍了iOS确定视频中的帧数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我在Swift中有一个MPMoviePlayerController:
If I have a MPMoviePlayerController in Swift:
MPMoviePlayerController mp = MPMoviePlayerController(contentURL: url)
我有没有办法让视频中的帧数位于 url
?如果没有,是否有其他方法来确定帧数?
Is there a way I can get the number of frames within the video located at url
? If not, is there some other way to determine the frame count?
推荐答案
我不认为 MPMoviePlayerController
可以帮助你。
使用 AVAssetReader
并计算<$的数量c $ c> CMSampleBuffer 它返回给你。您可以将其配置为甚至不解码帧,有效地解析文件,因此它应该快速且内存有效。
Use an AVAssetReader
and count the number of CMSampleBuffer
s it returns to you. You can configure it to not even decode the frames, effectively parsing the file, so it should be fast and memory efficient.
类似
var asset = AVURLAsset(URL: url, options: nil)
var reader = AVAssetReader(asset: asset, error: nil)
var videoTrack = asset.tracksWithMediaType(AVMediaTypeVideo)[0] as! AVAssetTrack
var readerOutput = AVAssetReaderTrackOutput(track: videoTrack, outputSettings: nil) // NB: nil, should give you raw frames
reader.addOutput(readerOutput)
reader.startReading()
var nFrames = 0
while true {
var sampleBuffer = readerOutput.copyNextSampleBuffer()
if sampleBuffer == nil {
break
}
nFrames++
}
println("Num frames: \(nFrames)")
很抱歉,如果这不是惯用语,我不知道swift。
Sorry if that's not idiomatic, I don't know swift.
这篇关于iOS确定视频中的帧数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文