Ios 无效数据字节/行:CGBitmapContextCreate:CGContextDrawImage:无效上下文0x0

Ios 无效数据字节/行:CGBitmapContextCreate:CGContextDrawImage:无效上下文0x0,ios,swift,cgcontextdrawimage,cgbitmapcontext,cvpixelbuffer,Ios,Swift,Cgcontextdrawimage,Cgbitmapcontext,Cvpixelbuffer,我正在尝试将图像数组转换为视频文件。在这个过程中,我必须从选定的图像填充像素缓冲区。以下是代码片段: CVPixelBufferLockBaseAddress(pixelBuffer, 0) let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer) let bitmapInfo:CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValu

我正在尝试将图像数组转换为视频文件。在这个过程中,我必须从选定的图像填充像素缓冲区。以下是代码片段:

CVPixelBufferLockBaseAddress(pixelBuffer, 0)

let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer)
let bitmapInfo:CGBitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue)
let rgbColorSpace = CGColorSpaceCreateDeviceRGB()
print("\npixel buffer width: \(CVPixelBufferGetWidth(pixelBuffer))\n")
print("\nbytes per row: \(CVPixelBufferGetBytesPerRow(pixelBuffer))\n")

let context = CGBitmapContextCreate(
    pixelData,
    Int(image.size.width),
    Int(image.size.height),
    CGImageGetBitsPerComponent(image.CGImage),
    CVPixelBufferGetBytesPerRow(pixelBuffer),
    rgbColorSpace,
    bitmapInfo.rawValue
)
CGContextDrawImage(context, CGRectMake(0, 0, image.size.width, image.size.height), image.CGImage)

CVPixelBufferUnlockBaseAddress(pixelBuffer, 0)
在执行这些行之后,我在xcode中得到以下消息: CGBitmapContextCreate:无效数据字节/行:对于8个整数位/组件、3个组件、KCGIMAGEAlphaPremultipledFirst,应至少为13056。CGContextDrawImage:无效上下文0x0。 调试后,我得到以下值:

CVPixelBufferGetWidth(pixelBuffer) // value 480
CVPixelBufferGetBytesPerRow(pixelBuffer) // value 1920
我应该如何获取有效的数据字节/行?控制台日志中指定的3个组件是什么?我在stackoverflow中看到了类似的问题,但在我的案例中没有任何帮助