我正在實現裁剪視頻幀的自定義視頻合成器。目前我使用Core Graphics來執行此操作:如何使用Metal API或Accelerate Framework繪製裁剪的位圖?
-(void)renderImage:(CGImageRef)image inBuffer:(CVPixelBufferRef)destination {
CGRect cropRect = // some rect ...
CGImageRef currentRectImage = CGImageCreateWithImageInRect(photoFullImage, cropRect);
size_t width = CVPixelBufferGetWidth(destination);
size_t height = CVPixelBufferGetHeight(destination);
CGContextRef context = CGBitmapContextCreate(CVPixelBufferGetBaseAddress(destination), // data
width,
height,
8, // bpp
CVPixelBufferGetBytesPerRow(destination),
CGImageGetColorSpace(backImage),
CGImageGetBitmapInfo(backImage));
CGRect frame = CGRectMake(0, 0, width, height);
CGContextDrawImage(context, frame, currentRectImage);
CGContextRelease(context);
}
如何使用金屬API執行此操作?它應該更快,對嗎? 使用Accelerate Framework(vImage具體)怎麼樣?這會更簡單嗎?
你可以很容易地從CVMetalTextureRef到CGImageRef,然後到CVPixelBufferRef,但是如果你需要實時性能,我在同一個pickle中(試圖找出如何獲得CVPixelBufferRef) –