AVAssetWriter startWriting状态为3时无法调用方法

时间:2014-05-15 14:03:16

标签: ios video-processing gpuimage

我正在使用视频过滤。我使用了GPUImage BradLarson。它完美的图像工作,但现在我试图从库中过滤视频文件,它给我错误[AVAssetWriter startWriting] Cannot call method when status is 3。 我使用了IOS7

heare是我的代码

- (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];

然后app运行顺利,但不显示视频。如果我放[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"

还有其他。

感谢。

1 个答案:

答案 0 :(得分:5)

检查您的目标文件是否存在。

如果存在,请删除现有文件。