仅使用您正在使用的 GPUImage 框架......这是迄今为止视频过滤器的最佳框架。浏览框架文档https://github.com/BradLarson/GPUImage向下滚动页面,您将找到可用过滤器的详细信息...
此过滤器应用于视频并编写视频,您必须使用 GPUImageMovieWriter 类...它会自动处理音频..
您不必维护它...使用 GPUImageMovieWriter 的 shouldPassThroughAudio 属性,它将自行管理音频。
使用本教程获取帮助http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
这是我使用 GPUImage 框架裁剪视频和音频的代码,在编辑后不会被删除。
NSURL *videoUrl = [selectedAsset defaultRepresentation].url;
GPUImageMovie *movieUrl = [[GPUImageMovie alloc] initWithURL:videoUrl];
self.cropFilter = [[GPUImageCropFilter alloc] initWithCropRegion:videoArea];
movieUrl.runBenchmark = YES;
movieUrl.playAtActualSpeed = YES;
[movieUrl addTarget:self.cropFilter];
//Setting path for temporary storing the video in document directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"CroppedVideo-%d.mov",arc4random() % 1000]];
NSURL *movieURL = [NSURL fileURLWithPath:myPathDocs];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoUrl options:nil];
AVAssetTrack *videoAssetTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGAffineTransform videoTransform = videoAssetTrack.preferredTransform;
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(videoAssetTrack.naturalSize.width, videoAssetTrack.naturalSize.height)];
[_cropFilter addTarget:movieWriter];
movieWriter.shouldPassthroughAudio = YES;
movieUrl.audioEncodingTarget = movieWriter;
[movieUrl enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[self.movieWriter startRecordingInOrientation:videoTransform];
[self.movieWriter startRecording];
[movieUrl startProcessing];
__block BOOL completeRec = NO;
__unsafe_unretained typeof(self) weakSelf = self;
[self.movieWriter setCompletionBlock:^{
[weakSelf.cropFilter removeTarget:weakSelf.movieWriter];
[weakSelf.movieWriter finishRecording];
[movieUrl removeTarget:weakSelf.cropFilter];
if (!completeRec)
{
[weakSelf videoCropDoneUrl:movieURL];
completeRec = YES;
}
}];