GPUImage因[AVAssetWriter startWriting]而终止,当状态为3时无法调用方法

时间:2013-10-11 22:02:33

标签: gpuimage chromakey

我在运行GPUImage时遇到问题。我修改了SimpleVideoFileFilter程序(用chromakeyfilter替换过滤器)并使用我自己的视频。由于以下错误,我的程序正在终止:

[AVAssetWriter startWriting]状态为3'

时无法调用方法

我已经浏览了论坛,但不确定为什么moviewriter正在关闭,然后有人写信给它。

我正在使用运行iOS 7.0的iPhone4

非常感谢任何线索。非常感谢!

6 个答案:

答案 0 :(得分:6)

检查目标文件是否已存在。如果是,请将其删除。

答案 1 :(得分:1)

我试图将文件添加到不存在的目录中。示例: /Videos/Video.mov ,只留下 /Video.mov

答案 2 :(得分:0)

movieFile1 = [[GPUImageMovie alloc] initWithURL:movieFileURL1];

movieFile2 = [[GPUImageMovie alloc] initWithURL:movieFileURL2];
movieFile2.runBenchmark = YES;
movieFile2.playAtActualSpeed = NO;

filter = [[GPUImageChromaKeyBlendFilter alloc] init];
[(GPUImageChromaKeyBlendFilter *)filter setColorToReplaceRed:0.0 green:1.0 blue:0.0];
[(GPUImageChromaKeyBlendFilter *)filter setThresholdSensitivity:0.4];

GPUImageView *filterView = (GPUImageView*)displayView;
[filter addTarget:displayView];

[movieFile1 addTarget:filter];
[movieFile2 addTarget:filter];

NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1920.0, 1280.0)];
[filter addTarget:movieWriter];

movieWriter.shouldPassthroughAudio = YES;
movieFile1.audioEncodingTarget = movieWriter;
[movieFile1 enableSynchronizedEncodingUsingMovieWriter:movieWriter];

[movieWriter startRecording];
[movieFile1 startProcessing];
[movieFile2 startProcessing];


[movieWriter setCompletionBlock:^{

   [filter removeTarget:movieWriter];
   [movieWriter finishRecording];
}];

答案 3 :(得分:0)

好的,我有一些想法。

当你说“它只是显示一个帧并且从不播放视频”时,我们很好地指出,从开始到结束的整个处理管道只运行一次,然后停止工作。

这告诉我们你正确地将事物串在一起,但是一些组件的存在时间不超过单个帧缓冲周期,随后整个过程停止。

它看起来像filtermovieWriter作用于类(我假设它们不是缺少下划线的属性,_filter and _movieWriter)。所以他们将在这个方法完成后继续存在(如果我错了,请纠正我......)

我认为您遇到麻烦的地方是(GPUImageView*)displayView

这应该被声明为一个类属性(虽然它可以只作为一个变量),然后通过视图控制器的nib或viewDidLoad方法实例化。

正如你现在所做的那样,这一行:GPUImageView* filterView = (GPUImageView*)displayView;正在为filterView做一个未使用的赋值(因此不必要)。目前尚不清楚displayView是否真的是GPUImageView的实例,或者当前方法结束时它是否仍然存在。 (实际上你说它“是我编程创建的UIView”)

displayView必须是GPUImageView的子类才能完成整个工作,并且必须将其范围限定在类中,而不是方法。

声明如下:

@property (strong, nonatomic)GPUImageView* displayView;

然后将其实例化,并将其添加到viewDidLoad

中的视图层次结构中

答案 4 :(得分:0)

if (outputPath) {
                finalURL = [[stongObj tempFileURL] copy];
                DebugLog(@"Start Filter Processing :%@",finalURL);
                DebugLog(@"movieUrl :%@",movieUrl);

         //   [CSUtils removeChuckFilePaths:@[outputPath]];


            //Create Image Movie Object
            _movieFile = [[GPUImageMovie alloc] initWithURL:outputPath];
            //_movieFile = [[GPUImageMovie alloc] initWithURL:[[NSBundle mainBundle] URLForResource:@"videoviewdemo" withExtension:@"mp4"]];
            _movieFile.runBenchmark = NO;
            _movieFile.playAtActualSpeed = YES;
            _movieFile.delegate = self;

            //Movie Writer Object
            _movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:finalURL size:CGSizeMake([UIScreen mainScreen].bounds.size.height,[UIScreen mainScreen].bounds.size.height)];
            //_movieWriter.delegate = self;

            //Create Selecetive GPU Image Filter
            [stongObj setGpuOutputFilter:selectedVideoFilterType];

            //Create Group Filter
            groupFilter = [[GPUImageFilterGroup alloc] init];
            [groupFilter addTarget:imageOutputFilter];

            // Only Single Filter is implemented.
            //Apply Initial and Terminal Filter
            [(GPUImageFilterGroup *)groupFilter setInitialFilters:[NSArray arrayWithObject:imageOutputFilter]];
            [(GPUImageFilterGroup *)groupFilter setTerminalFilter:imageOutputFilter];

            //_movieWriter -> groupFilter ->_movieFile
            [_movieFile addTarget:groupFilter];
            [groupFilter addTarget:_movieWriter];

            _movieWriter.shouldPassthroughAudio = YES;
            _movieFile.audioEncodingTarget = _movieWriter;
            [_movieFile enableSynchronizedEncodingUsingMovieWriter:_movieWriter];

            //Start Recording
            [_movieWriter startRecording];
            //Start Processing
            [_movieFile startProcessing];

            __weak typeof(self) weekSelf=self;
            [_movieWriter setCompletionBlock:^{

                __strong typeof(self) stongSelf=weekSelf;

                DebugLog(@"Movie Write Completed");
                //Finish Recording.
                [stongSelf.movieWriter finishRecording];

                //Release all object
                // [self releaseAllObject];

                //remove movieUrl,audioUrl,outputPath
                [CSUtils removeChuckFiles:@[movieUrl,audioUrl,outputPath]];

            }];

[_ movieFile startProcessing];应用程序在iOS 8上崩溃,但在iOS 7上工作正常

答案 5 :(得分:0)

@Seasia Creative,我没有足够的声誉来添加该列表的评论,我创建了一个新列表来回答U. 我检查输出URL,控制台日志“/var〜~~~ / tmpmerge.mp4”,所以我意识到,我想念一个“/”--->“/ var ~~~~ / tmp / merge.mp4 ”。 如果网址不正确,则项目会遇到相同的错误。 希望能帮助一些人。