Random black screen when filtering video
Thu, 07/05/2012 - 17:43
I use the following code to filter a pre-recorded video "Movie.m4v" into a filtered file "MovieFiltered.m4v". The filter (self.previewFilter) is freshly alloc init-ed just before making this method call. Sometimes this works fine, other times I get a black screen, with working audio. It does not seem to the depend on the type of filter used, lenght of video, or any other distinguishable pattern. Seems pretty random. I've been at this for about a day now and can't figure it out. Any help appreciated.
-(void)reEncodeMovie { NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *pathString = [documentsDirectory stringByAppendingPathComponent:@"Movie.m4v"]; NSURL *pathUrl = [NSURL fileURLWithPath:pathString]; self.movieFile = [[GPUImageMovie alloc] initWithURL:pathUrl]; [self.movieFile addTarget:self.previewFilter]; [self.previewFilter removeAllTargets]; NSString* filteredFile= [documentsDirectory stringByAppendingPathComponent:@"MovieFiltered.m4v"]; unlink([filteredFile UTF8String]); NSURL *movieURL = [NSURL fileURLWithPath:filteredFile]; self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)]; [self.previewFilter addTarget:self.movieWriter]; self.movieWriter.shouldPassthroughAudio = YES; self.movieFile.audioEncodingTarget = self.movieWriter; [self.movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter]; [self.movieWriter startRecording]; [self.movieFile startProcessing]; [self.movieWriter setCompletionBlock:^{ NSLog(@"Recording done"); [self.movieWriter finishRecording]; [self.previewFilter removeTarget:self.movieWriter]; }]; }
No ideas on what might be causing this? :/