I am trying to decode Prores video file But it doesn't work. I always got
Optional(Error Domain=AVFoundationErrorDomain Code=-11821 "Cannot Decode" UserInfo={NSLocalizedFailureReason=The media data could not be decoded. It may be damaged., NSLocalizedDescription=Cannot Decode, NSUnderlyingError=0x600002a982a0 {Error Domain=NSOSStatusErrorDomain Code=-12137 "(null)"}})
Here a full decoder:
class Decoder {
private let assetReader: AVAssetReader?
private let output: AVAssetReaderTrackOutput
init() throws {
VTRegisterProfessionalVideoWorkflowVideoDecoders()
VTRegisterProfessionalVideoWorkflowVideoEncoders()
let assetReader = try AVAssetReader(asset: movieAsset)
let tracks = movieAsset.tracks(withMediaType: .video)
guard let firstTrack = tracks.first else {
print("No video tracks found")
throw NSError()
}
let out = AVAssetReaderTrackOutput(track: firstTrack, outputSettings: outputSettings)
out.alwaysCopiesSampleData = true
assetReader.add(out)
self.assetReader = assetReader
self.output = out
}
func run(){
guard let assetReader = assetReader, assetReader.startReading() else {
print("Failed to stard asset reader")
return
}
while(assetReader.status == .reading) {
guard let sampleBuffer = output.copyNextSampleBuffer() else {
print(assetReader.status.rawValue)
print(assetReader.error)
continue
}
print("Decoding success!")
}
}
}
It's not clear why you want Bayer and I'm not sure what you mean by "native", but I guess you might want your data to be
So there are two possibilities I think.
If you like high definition data, try setting your
AVAssetReaderTrackOutputpixel format tokCVPixelFormatType_444YpCbCr16VideoRange_16A_TriPlanar,kCVPixelFormatType_4444AYpCbCr16orkCVPixelFormatType_64RGBALEor one of the other formats mentioned in theAVAssetReaderTrackOutput. I'd think the chances are good thatAVAssetReaderwon't gratuitously truncate the data.I have no idea about natural or efficient representations when working with ProRes RAW, but if you really want Bayer output, you can set your
outputSettingstoniland use aVTDecompressionSessionto convert the raw sample buffers tokCVPixelFormatType_16VersatileBayer(orkCVPixelFormatType_64RGBAHalf,kCVPixelFormatType_128RGBAFloatif you're still into high range formats thatAVAssetReaderdislikes for some reason), but notkCVPixelFormatType_64RGBA_DownscaledProResRAWas that doesn't seem to work.Anyway, you could lightly modify your code to do decode to
kCVPixelFormatType_16VersatileBayerlike so:The thing I don't get is why
AVAssetReader, which probably usesVTDecompressionSessionunder the hood doesn't simply let you requestkCVPixelFormatType_16VersatileBayerin the first place. Maybe it's bloody mindedness or maybe it doesn't make sense? p.s. what are you trying to do?