我想使用GPUImage对某些电影帧应用效果。我已成功添加对整个电影文件的效果,所以有没有办法在不同的帧上添加不同的效果?
例如,我想在5秒到10秒的时间内对视频应用棕褐色效果。所以我需要0-5秒才能成为原始视频,5-10秒带有深褐色效果,10 - 视频总秒数带有原始视频。
另外,我想使用GPUImage在某些帧上绘制文本/图像,是否可能?
任何回复都将不胜感激。
答案 0 :(得分:1)
您可以要求MPMoviePlayerController或AVAssetImageGenerator在您指定的时间生成缩略图。
iPhone Read UIimage (frames) from video with AVFoundation
AVAssetImageGenerator provides images rotated
如果您想要视频而不仅仅是视频帧,则可以修剪视频中的某个部分并对其应用效果。这会获取您视频的网址并将其修剪为指定的时间。
AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(startMilliseconds, 1000), CMTimeMake(endMilliseconds - startMilliseconds, 1000));
exportSession.timeRange = timeRange;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status) {
case AVAssetExportSessionStatusCompleted:
///
// Call something to apply the effect
///
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"Failed:%@", exportSession.error);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Canceled:%@", exportSession.error);
break;
default:
break;
}
}];
完成后,您将应用效果,如果您使用了视频片段路径,请将它们组合并对其进行编码。
How to combine video clips with different orientation using AVFoundation