Swift Avassetrader-无法解码MOV
我正在尝试从视频中获取一组帧。 这是我的密码:Swift Avassetrader-无法解码MOV,swift,alpha,mov,avassetreader,Swift,Alpha,Mov,Avassetreader,我正在尝试从视频中获取一组帧。 这是我的密码: var frames = [UIImage]() let url = NSBundle.mainBundle().URLForResource(name, withExtension: ext, subdirectory: "Assets")! let asset = AVAsset(URL: url) let reader = try AVAssetReader(asset
var frames = [UIImage]()
let url = NSBundle.mainBundle().URLForResource(name, withExtension: ext, subdirectory: "Assets")!
let asset = AVAsset(URL: url)
let reader = try AVAssetReader(asset: asset)
let output = AVAssetReaderVideoCompositionOutput(videoTracks: asset.tracksWithMediaType(AVMediaTypeVideo), videoSettings: nil)
output.videoComposition = AVVideoComposition(propertiesOfAsset: asset)
reader.addOutput(output)
reader.startReading()
let frameCount = Int(asset.duration.seconds*23.973)
let context = CIContext()
print("Asset reader: \(reader.error)")
for _ in 0..<frameCount{
let buff = output.copyNextSampleBuffer()
if buff == nil{
continue
}
let pixelBuffer = CMSampleBufferGetImageBuffer(buff!)! as CVPixelBuffer
let ciImage = CIImage(CVPixelBuffer: pixelBuffer)
let cgImgRef = context.createCGImage(ciImage, fromRect: CGRectMake(0, 0, CGFloat(CVPixelBufferGetWidth(pixelBuffer)), CGFloat(CVPixelBufferGetHeight(pixelBuffer))))
frames.append(UIImage(CGImage: cgImgRef))
}
我尝试了premiere pro中支持透明和像素格式kCVPixelFormatType_32RGBA、kCVPixelFormatType_32BGRA、kCVPixelFormatType_32ARG和kCVPixelFormatType_32ABGR的所有编解码器,但仍然得到相同的错误。有什么建议吗?有些文件可能无法从NSBundle.mainBundle()读取,请使用document directory let path=NSSearchPathForDirectoriesInDomains(.DocumentDirectory.UserDomainMask,true)。首先!作为一种资产,我有我的视频。如何从文档目录加载它?我已在模拟器中进行了检查,但它们没有出现在那里。您的视频在real中的位置在哪里?只需尝试一下,您就可以将您的.mov视频复制到文档目录中并从那里播放,然后检查它是否正常工作。我的视频位于项目层次结构中的文件夹中。我已经测试过将它复制到文档目录,但它没有解决问题。。。仍然表示无法解码,因为所需的解码器丢失某些文件可能无法从NSBundle.mainBundle()读取,请使用document directory let path=NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)。首先!作为一种资产,我有我的视频。如何从文档目录加载它?我已在模拟器中进行了检查,但它们没有出现在那里。您的视频在real中的位置在哪里?只需尝试一下,您就可以将您的.mov视频复制到文档目录中并从那里播放,然后检查它是否正常工作。我的视频位于项目层次结构中的文件夹中。我已经测试过将它复制到文档目录,但它没有解决问题。。。仍然表示无法解码,因为缺少所需的解码器
Error Domain=AVFoundationErrorDomain Code=-11833 "Cannot Decode" UserInfo={NSLocalizedFailureReason=The decoder required for this media cannot be found., NSUnderlyingError=0x15e77fb90 {Error Domain=NSOSStatusErrorDomain Code=-12906 "(null)"}, AVErrorMediaTypeKey=vide, NSLocalizedDescription=Cannot Decode})