avfoundation - iOS中使用AVAssetWriter录制视频,提示未知错误(Code=-11800)?
阿神
阿神 2017-04-17 17:56:51
0
1
1960

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的信息如下:

<CVPixelBuffer 0x13fc8f3e0 width=375 height=667 bytesPerRow=1536 pixelFormat=BGRA iosurface=0x0 
    attributes=<CFBasicHash 0x13fc12130 [0x19e5bcb68]> {
        type = immutable dict, count = 3, entries =>
            0 : <CFString 0x19a067ad8 [0x19e5bcb68]>{contents = "CGImageCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
            1 : <CFString 0x19a067c98 [0x19e5bcb68]>{contents = "PixelFormatDescription"} = <CFBasicHash 0x13dee97d0 [0x19e5bcb68]> {
                type = immutable dict, count = 15, entries =>
                    1 : <CFString 0x19a067ad8 [0x19e5bcb68]>{contents = "CGImageCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    2 : <CFString 0x19a068198 [0x19e5bcb68]>{contents = "FillExtendedPixelsCallback"} = <CFData 0x1418176b0 [0x19e5bcb68]>{length = 24, capacity = 24, bytes = 0x0000000000000000dc0cbc82010000000000000000000000}
                    5 : <CFString 0x19a067ed8 [0x19e5bcb68]>{contents = "ContainsAlpha"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    6 : <CFString 0x19a067ab8 [0x19e5bcb68]>{contents = "CGBitmapContextCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    7 : <CFString 0x19a067f98 [0x19e5bcb68]>{contents = "BitsPerBlock"} = <CFNumber 0xb000000000000202 [0x19e5bcb68]>{value = +32, type = kCFNumberSInt32Type}
                    8 : <CFString 0x19a067fb8 [0x19e5bcb68]>{contents = "BlackBlock"} = <CFData 0x141817500 [0x19e5bcb68]>{length = 4, capacity = 4, bytes = 0x000000ff}
                    9 : <CFString 0x19a067bb8 [0x19e5bcb68]>{contents = "IOSurfaceOpenGLESTextureCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    10 : <CFString 0x19a067bf8 [0x19e5bcb68]>{contents = "OpenGLESCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    11 : <CFString 0x19a068078 [0x19e5bcb68]>{contents = "CGBitmapInfo"} = <CFNumber 0xb000000000020042 [0x19e5bcb68]>{value = +8196, type = kCFNumberSInt32Type}
                    12 : <CFString 0x19a067b98 [0x19e5bcb68]>{contents = "IOSurfaceCoreAnimationCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    13 : <CFString 0x19a067bd8 [0x19e5bcb68]>{contents = "IOSurfaceOpenGLESFBOCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
                    14 : <CFString 0x19a068098 [0x19e5bcb68]>{contents = "ContainsYCbCr"} = <CFBoolean 0x19e5bd0b0 [0x19e5bcb68]>{value = false}
                    15 : <CFString 0x19a067e78 [0x19e5bcb68]>{contents = "PixelFormat"} = <CFNumber 0xb000000424752412 [0x19e5bcb68]>{value = +1111970369, type = kCFNumberSInt32Type}
                    16 : <CFString 0x19a0680f8 [0x19e5bcb68]>{contents = "ComponentRange"} = <CFString 0x19a068138 [0x19e5bcb68]>{contents = "FullRange"}
                    21 : <CFString 0x19a0680b8 [0x19e5bcb68]>{contents = "ContainsRGB"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
            }

            2 : <CFString 0x19a067ab8 [0x19e5bcb68]>{contents = "CGBitmapContextCompatibility"} = <CFBoolean 0x19e5bd0a0 [0x19e5bcb68]>{value = true}
    }
    propagatedAttachments=<CFBasicHash 0x13fcbdd40 [0x19e5bcb68]>{type = mutable dict, count = 0, entries => }
    nonPropagatedAttachments=<CFBasicHash 0x13fca58f0 [0x19e5bcb68]>{type = mutable dict, count = 0, entries => }
>

CMSampleBufferRef信息:

CMSampleBuffer 0x1418db960 retainCount: 1 allocator: 0x19e5bcb68
    invalid = NO
    dataReady = YES
    makeDataReadyCallback = 0x0
    makeDataReadyRefcon = 0x0
    formatDescription = <CMVideoFormatDescription 0x14181e0a0 [0x19e5bcb68]> {
        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:

<CMVideoFormatDescription 0x152156900 [0x19e5bcb68]> {
    mediaType:'vide' 
    mediaSubType:'BGRA' 
    mediaSpecific: {
        codecType: 'BGRA'        dimensions: 375 x 667 
    } 
    extensions: {(null)}
}

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

阿神
阿神

闭关修行中......

membalas semua(1)
Evan

Hello A Shen, saya juga mengalami masalah yang sama seperti anda. Saya telah menyemak masalah selama beberapa hari dan masih tidak menyelesaikannya. Adakah anda telah menyelesaikan masalah ini? Jika anda menyelesaikannya, bolehkah anda berkongsi?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!