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

标签 ios video-processing 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/

相关文章:

ios - captureOutput :didOutputSampleBuffer:from connection: 中的方向问题

python - 在Python中使用多线程进行实时视频处理

ffmpeg - 在 FFmpeg 中使用 mpdecimate 去除视频中的滞后峰值

ios - 如何使用GPUImage MotionDetection-swift获取移动物体的坐标

iphone - 从 Photoshop 到 iOS 的颜色特定色相/饱和度

ios - 显示来自视频 swift 的预览图像

ios - 如何使用 swift 2.2 从 tableview 中删除一行

ios - 实时混合 UIImages

ios - 本地通知声音不起作用

c# - 如何在 Windows 8 (WinRT) 上从图像创建视频