iPhone水印錄製視訊.
提前致謝.
使用AVFoundation.我建議用AVCaptureVideoDataOutput抓住幀,然後將捕獲的幀與水印影象重疊,最後將捕獲和處理的幀寫入檔案使用者AVAssetWriter.
搜尋堆疊溢位,有一大堆神奇的例子詳細說明如何做這些我提到的每一件事情.我沒有看到任何給出你想要的效果的程式碼示例,但是你應該能夠很容易地混合和匹配.
編輯:
看看這些連結:
ofollow,noindex" target="_blank">iPhone: AVCaptureSession capture output crashing (AVCaptureVideoDataOutput) – 這個帖子可能僅僅是包含相關程式碼的本質.
AVCaptureDataOutput將返回影象為CMSampleBufferRefs.
使用以下程式碼將它們轉換為CGImageRefs:
- (CGImageRef) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer // Create a CGImageRef from sample buffer data { CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer,0);// Lock the image buffer uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);// Get information of the image size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); size_t width = CVPixelBufferGetWidth(imageBuffer); size_t height = CVPixelBufferGetHeight(imageBuffer); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGContextRef newContext = CGBitmapContextCreate(baseAddress, width, height, 8, bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); CGImageRef newImage = CGBitmapContextCreateImage(newContext); CGContextRelease(newContext); CGColorSpaceRelease(colorSpace); CVPixelBufferUnlockBaseAddress(imageBuffer,0); /* CVBufferRelease(imageBuffer); */// do not call this! return newImage; }
從那裡你會轉換成UIImage,
UIImage *img = [UIImage imageWithCGImage:yourCGImage];
然後使用
[img drawInRect:CGRectMake(x,y,height,width)];
將框架繪製到上下文中,在其上繪製水印的PNG,然後使用AVAssetWriter將處理後的影象新增到輸出視訊.我建議實時新增它們,所以你不會填補大量的UIImage的記憶.
How do I export UIImage array as a movie? – 此帖顯示如何在給定的持續時間內將視訊處理的UIImages新增到該視訊中.
這樣可以讓您很好地為您的視訊新增水印.記住要實行良好的記憶體管理,因為洩漏的影象以20-30fps進入是一個很好的方式來崩潰的應用程式.
http://stackoverflow.com/questions/7205820/iphone-watermark-on-recorded-video