Код: Выделить всё
// Initial AVAssetWriter
// Write mp4 file
let assetWriter = try AVAssetWriter(outputURL: targetUrl, fileType: .mp4)
let width = size.width * 2
// set options for written video
let videoSettings: [String : Any] = [
AVVideoCodecKey: AVVideoCodecType.h264,
AVVideoWidthKey: width,
AVVideoHeightKey: size.height
]
guard assetWriter.canApply(outputSettings: videoSettings, forMediaType: AVMediaType.video) else {
fatalError("Error applying output settings")
}
// Initial AVAssetWriterInput
let assetWriterInput = AVAssetWriterInput(mediaType: .video, outputSettings: videoSettings)
// set arritbutes
let sourcePixelBufferAttributes: [String : Any] = [
kCVPixelBufferPixelFormatTypeKey as String: kCVPixelFormatType_32BGRA]
// Initial AVAssetWriterInputPixelBufferAdaptor
let inputPixelBufferAdaptor =
AVAssetWriterInputPixelBufferAdaptor(assetWriterInput: assetWriterInput,
sourcePixelBufferAttributes: sourcePixelBufferAttributes)
if assetWriter.canAdd(assetWriterInput) == true {
assetWriter.add(assetWriterInput)
assetWriter.startWriting()
assetWriter.startSession(atSourceTime: .zero)
} else {
print("Cannot add asset writer input.")
}
if let error = assetWriter.error {
print("assetWrite status=\(assetWriter.status), error=\(error)")
}
Код: Выделить всё
assetWrite status=AVAssetWriterStatus(rawValue: 3), error=Error
Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed"
UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12902),
NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x30189cb10
{Error Domain=NSOSStatusErrorDomain Code=-12902 "(null)"}}
Если бы я написал :
Код: Выделить всё
let videoSettings: [String : Any] = [
AVVideoCodecKey: AVVideoCodecType.h264,
AVVideoWidthKey: 4090, // width,
AVVideoHeightKey: size.height
]
Можно ли как-нибудь решить эту проблему, используя значение 4400 или больше в качестве ключа ширины?
Подробнее здесь: https://stackoverflow.com/questions/784 ... frame-size