gpt4 book ai didi

swift - 如何从 Swift 中的本地视频文件中获取帧?

转载 作者:行者123 更新时间:2023-11-28 14:55:48 35 4
gpt4 key购买 nike

我需要从本地视频文件中获取帧,以便在播放视频之前处理它们。我已经尝试过使用 AVAssetReader 和 VideoOutput。

[编辑] 这是我在 Accesing Individual Frames using AV Player 中使用的代码

let asset = AVAsset(URL: inputUrl)
let reader = try! AVAssetReader(asset: asset)

let videoTrack = asset.tracksWithMediaType(AVMediaTypeVideo)[0]

// read video frames as BGRA
let trackReaderOutput = AVAssetReaderTrackOutput(track: videoTrack, outputSettings:[String(kCVPixelBufferPixelFormatTypeKey): NSNumber(unsignedInt: kCVPixelFormatType_32BGRA)])

reader.addOutput(trackReaderOutput)
reader.startReading()

while let sampleBuffer = trackReaderOutput.copyNextSampleBuffer() {
print("sample at time \(CMSampleBufferGetPresentationTimeStamp(sampleBuffer))")
if let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
// process each CVPixelBufferRef here
// see CVPixelBufferGetWidth, CVPixelBufferLockBaseAddress, CVPixelBufferGetBaseAddress, etc
}
}

最佳答案

我相信 AVAssetReader 应该可以工作。你尝试了什么?您看过 Apple 的示例代码吗? https://developer.apple.com/library/content/samplecode/ReaderWriter/Introduction/Intro.html

关于swift - 如何从 Swift 中的本地视频文件中获取帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49390728/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com