avfoundation - iOS中使用AVAssetWriter录制视频,提示未知错误(Code=-11800)?

 莫莫2602891683 发布于 2022-10-29 11:32

2016.5.7:
使用AVAssetWriterInputPixelBufferAdaptor来创建、写入CVPixelBuffer后,可以成功录制视频了,下面的这个错误没有再出现
不过,在iPhone6上又遇到一个新的问题(5c、5s上没有),图像出现了变形……

原问题:
在使用AVAssetWriter录制视频,调用AVAssetWriterInput的appendSampleBuffer方法时,返回失败,error信息如下:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1b83f490 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12780)}

文档里也查不到……如果有人遇到过类似问题,或是对这方面有所了解,还请不吝赐教,非常感谢。下面我会给出一些详细信息:

由于某些原因,sampleBuffer并没有直接使用AVCaptureSession和AVCaptureVideoDataOutput的组合得到的数据,或是AVAssetReader。而是通过其它途径创建出CGImageRef,再创建CVPixelBufferRef,最后得到CMSampleBufferRef。可以通过Xcode的调试预览看到正确的CGImageRef图像,CVPixelBufferRef的信息如下:

 {
        type = immutable dict, count = 3, entries =>
            0 : {contents = "CGImageCompatibility"} = {value = true}
            1 : {contents = "PixelFormatDescription"} =  {
                type = immutable dict, count = 15, entries =>
                    1 : {contents = "CGImageCompatibility"} = {value = true}
                    2 : {contents = "FillExtendedPixelsCallback"} = {length = 24, capacity = 24, bytes = 0x0000000000000000dc0cbc82010000000000000000000000}
                    5 : {contents = "ContainsAlpha"} = {value = true}
                    6 : {contents = "CGBitmapContextCompatibility"} = {value = true}
                    7 : {contents = "BitsPerBlock"} = {value = +32, type = kCFNumberSInt32Type}
                    8 : {contents = "BlackBlock"} = {length = 4, capacity = 4, bytes = 0x000000ff}
                    9 : {contents = "IOSurfaceOpenGLESTextureCompatibility"} = {value = true}
                    10 : {contents = "OpenGLESCompatibility"} = {value = true}
                    11 : {contents = "CGBitmapInfo"} = {value = +8196, type = kCFNumberSInt32Type}
                    12 : {contents = "IOSurfaceCoreAnimationCompatibility"} = {value = true}
                    13 : {contents = "IOSurfaceOpenGLESFBOCompatibility"} = {value = true}
                    14 : {contents = "ContainsYCbCr"} = {value = false}
                    15 : {contents = "PixelFormat"} = {value = +1111970369, type = kCFNumberSInt32Type}
                    16 : {contents = "ComponentRange"} = {contents = "FullRange"}
                    21 : {contents = "ContainsRGB"} = {value = true}
            }

            2 : {contents = "CGBitmapContextCompatibility"} = {value = true}
    }
    propagatedAttachments={type = mutable dict, count = 0, entries => }
    nonPropagatedAttachments={type = mutable dict, count = 0, entries => }
>

CMSampleBufferRef信息:

CMSampleBuffer 0x1418db960 retainCount: 1 allocator: 0x19e5bcb68
    invalid = NO
    dataReady = YES
    makeDataReadyCallback = 0x0
    makeDataReadyRefcon = 0x0
    formatDescription =  {
        mediaType:'vide' 
        mediaSubType:'BGRA' 
        mediaSpecific: {
            codecType: 'BGRA'       dimensions: 375 x 667 
        } 
        extensions: {(null)}
    }
    sbufToTrackReadiness = 0x0
    numSamples = 1
    sampleTimingArray[1] = {
        {PTS = {0/1 = 0.000}, DTS = {INVALID}, duration = {INVALID}},
    }
    imageBuffer = 0x13fc8f3e0

另外,AVAssetWriterInput的outputSettings如下:

{
    AVVideoCodecKey = avc1;
    AVVideoCompressionPropertiesKey =     {
        AverageBitRate = "4.05";
        ExpectedFrameRate = 30;
        MaxKeyFrameInterval = 30;
    };
    AVVideoHeightKey = 667;
    AVVideoWidthKey = 375;
}

sourceFormatHint:

 {
    mediaType:'vide' 
    mediaSubType:'BGRA' 
    mediaSpecific: {
        codecType: 'BGRA'        dimensions: 375 x 667 
    } 
    extensions: {(null)}
}

如果还需要其它信息我再贴上来~万分感谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有