我正在使用视频过滤。我使用了 GPUImage
BradLarson 。它完美地处理图像,但现在我试图从库中过滤视频文件,它给我错误 [AVAssetWriter startWriting] Cannot call method when status is 3
。
我用的是IOS7
听到是我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
videoEditingPlayView = [[GPUImageView alloc] initWithFrame:CGRectMake(60,108,200,200)];
[self.view addSubview:videoEditingPlayView];
}
-(IBAction)btnEffectsClick:(id)sender{
NSURL *videoURl = [NSURL fileURLWithPath:self.strVideoURl];
if (movieFile != nil) {
videoFilter = nil;
movieFile = nil;
}
movieFile = [[GPUImageMovie alloc] initWithURL:videoURl];
movieFile.runBenchmark = YES;
videoFilter = [[GPUImageBrightnessFilter alloc] init];
[(GPUImageBrightnessFilter *)videoFilter setBrightness:0.0];
[movieFile addTarget:videoFilter];
videoEditingPlayView.hidden = NO;
GPUImageView *filterView = (GPUImageView *)videoEditingPlayView;
[videoFilter addTarget:filterView];
NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480, 360)];
[videoFilter addTarget:movieWriter];
// movieWriter.
movieWriter.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];
[filterView setFillMode:kGPUImageFillModePreserveAspectRatio];
filterView.transform = CGAffineTransformRotate(filterView.transform, 3.14159/2);
double delayToStartRecording = 0.5;
dispatch_time_t startTime = dispatch_time(DISPATCH_TIME_NOW, delayToStartRecording * NSEC_PER_SEC);
dispatch_after(startTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Start recording");
[movieWriter startRecording];
**[movieFile startProcessing];** ***if I remove this line then it is working but not dispying video on videoEditingPlayView***
double delayInSeconds = 30.0;
dispatch_time_t stopTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(stopTime, dispatch_get_main_queue(), ^(void){
[filter removeTarget:movieWriter];
[movieWriter finishRecording];
[videoFilter removeTarget:movieWriter];
movieWriter = nil;
NSLog(@"Movie completed");
});
});
}
在编码中,如果我删除这一行
[movieFile startProcessing]
; 然后应用程序运行顺利,但不显示视频。如果我输入
[movieFile startProcessing]
那么它会崩溃并给我一个错误。我试过这个,但无法解决崩溃问题。
GPUImage terminates due to [AVAssetWriter startWriting] Cannot call method when status is 3'
https://github.com/BradLarson/GPUImage/issues/1228
Blends with GPUImageView are not giving expected result
GPUImageMovieWriter - crashing with "Cannot call method when status is 2"
还有其他。
谢谢。
最佳答案
检查您的目标文件是否存在。
如果存在,删除存在的文件。
关于ios - AVAssetWriter startWriting 状态为 3 时无法调用方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23680567/