Closed martenorton closed 2 years ago
您好,根据您的描述,是ios端吗,提供下具体操作步骤和播放器sdk版本号 技术问题 欢迎交流 q2562367495 注明来意
试了另外一个代码,一样的问题:
+ (UIImage *)imageFromYUVImageBuffer:(CVImageBufferRef)imageBuffer {
CVPixelBufferLockBaseAddress(imageBuffer, 0);
size_t bytesPerRow = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0);
size_t width = CVPixelBufferGetWidthOfPlane(imageBuffer, 0);
size_t height = CVPixelBufferGetHeightOfPlane(imageBuffer, 0);
void *lumaAddress = CVPixelBufferGetBaseAddress(imageBuffer);
CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(lumaAddress, width, height, 8, bytesPerRow, rgbSpace, kCGRenderingIntentDefault );
CGImageRef imageRef = CGBitmapContextCreateImage(context);
CGContextRelease(context);
CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return image;
}
您好,如还是复现,请提供播放器sdk版本号,我们具体看下 技术问题 欢迎交流 q2562367495 注明来意
情况还是出现,sdk版本号:8.4
解决了,原来是格式错误,这样转就可以正常显示了:
+ (UIImage*)uiImageFromPixelBuffer:(CVPixelBufferRef)p {
CIImage* ciImage = [CIImage imageWithCVPixelBuffer:p];
CIContext* context = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}];
CGRect rect = CGRectMake(0, 0, CVPixelBufferGetWidth(p), CVPixelBufferGetHeight(p));
CGImageRef videoImage = [context createCGImage:ciImage fromRect:rect];
UIImage* image = [UIImage imageWithCGImage:videoImage];
CGImageRelease(videoImage);
return image;
}
转换出来的图片不完整:![image](https://user-images.githubusercontent.com/52880215/111393349-29b38700-86eb-11eb-85d9-bb8014c55436.png)
操作代码: