问题描述
我正在尝试从GPUImage
捕获的视频帧中生成UIImage
.我已经做了很多AVFoundation
视频工作,但是我是使用GPUImage
的新手.我已经subclassed
GPUImageVideoCamera
并添加了此方法,但是UIImage
始终为nil.如果有人能告诉我我哪里出了这么大的错误,我将非常感激!
I'm trying to generate a UIImage
from a video frame captured by GPUImage
. I've done a lot of AVFoundation
video work, but i'm new to using GPUImage
. I've subclassed
GPUImageVideoCamera
and added this method, but the UIImage
is always nil. If anyone can tell me where i've gone so horribly wrong, i'd be very appreciative!
- (void)processVideoSampleBuffer:( CMSampleBufferRef )sampleBuffer
{ [super processVideoSampleBuffer:sampleBuffer]; //让GPUImage首先进行处理
{ [super processVideoSampleBuffer:sampleBuffer]; // to let GPUImage do it's processing first
if (!self.thumbnailGenerated)
{
CMTime timestamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer);
NSLog(@"%f", (float)timestamp.value / timestamp.timescale);
self.thumbnailGenerated = YES;
dispatch_sync(dispatch_get_main_queue(), ^
{
// generate a preview frame from the last filter in the camera filter chain
UIImage *thumbnailImage = [UIImage imageWithCGImage:[[self.targets lastObject] newCGImageFromCurrentlyProcessedOutput]];
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Thumbnail.png"];
[UIImagePNGRepresentation(thumbnailImage) writeToFile:pathToMovie atomically:YES];
});
}
}
推荐答案
我不确定这是否有帮助,但是在处理视频时会出现缩略图.为此,我使用
I'm not sure if that is of any help, but I'm getting thumbnail while processing video. For this purpose I'm using
videoInput --> someMyOperations --> fileOutput
someMyOperations --> imageOutput //imageOutput is PictureOutput()
videoInput.start() //that needs to be called!
imageOutput.saveNextFrameToUrl(coverUrl, format: .jpg) { file in
//here goes the code what to do with thumbnail
videoInput.cancel() //quite probably here you want this
}
这是猜测-我看不到您的代码,但对我来说这可行.
That's guessing - I don't see your code, but for me this works.
这篇关于从GPUImage视频帧生成UIImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!