Audio problems when filtering movie file

1 reply [Last post]
dimi2012
User offline. Last seen 9 years 20 weeks ago. Offline
Joined: 07/04/2012
Posts:

I'm using the following code to filter "Movie.m4v" in my app's documents folder, to "MovieFiltered.m4v" in the same folder. The problem is, when i enable audio with:

 self.movieWriter.shouldPassthroughAudio = YES;
 movieFile.audioEncodingTarget = self.movieWriter;
 [movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];

the app crashes, with EXC BAD ACCESS on:

runOnMainQueueWithoutDeadlocking(^{
                [self processMovieFrame:sampleBufferRef]; 
            });

If I don't enable audio, the movie is filtered fine, so the error is something to do with audio. Any pointers would be really appreciated!

Full Code:

-(void)filterMovie
{
    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *pathString = [documentsDirectory stringByAppendingPathComponent:@"Movie.m4v"];
    NSURL *pathUrl = [NSURL fileURLWithPath:pathString];
 
    GPUImageMovie *movieFile = [[GPUImageMovie alloc] initWithURL:pathUrl];
    movieFile.runBenchmark = YES;
 
    [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;
    movieFile.audioEncodingTarget = self.movieWriter;
    [movieFile enableSynchronizedEncodingUsingMovieWriter:self.movieWriter];
 
    [self.movieWriter startRecording];
    [movieFile startProcessing];
 
    [self.movieWriter setCompletionBlock:^{
        NSLog(@"Recording done");
 
        [self.movieWriter finishRecording];
 
    }];
 
}

dimi2012
User offline. Last seen 9 years 20 weeks ago. Offline
Joined: 07/04/2012
Posts:

Fixed it right after posting this.

For anybody else having this problem: movieFile is getting deallocated prematurely, and that caused the error. Setting movieFile as a retained property fixed the issue.

Syndicate content