BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.22k stars 4.61k forks source link

Issue filtering video, unique frame with sound #1336

Open thibauddavid opened 10 years ago

thibauddavid commented 10 years ago

Hello,

I've tried the sample code allowing to filter a video from NSURL with steps GPUImageMovie -> Filter -> GPUImageMovieWriter with an NSURL of movie from imagePickerController, but the result is always the first frame of the video, during the correct time of it.

The sound is ok by the way, I just can figure out why I still only get the first frame displayed whereas all seem to be processed, as NSLogging @"read a video frame: %@" suggests.

Here is the used code:

-(void)imagePickerController:(UIImagePickerController )picker didFinishPickingMediaWithInfo:(NSDictionary )info { ... NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL]; self.tmpMediaUrl = videoURL; ...

self.movieFile = [[GPUImageMovie alloc] initWithURL:self.tmpMediaUrl];
[self.movieFile addTarget:self.filter];
self.movieFile.playAtActualSpeed = NO; //Tried YES too

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

self.movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(320.0, 480.0)];
[self.filter 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:
^{
     //Playing media with MPMoviePlayerController, which perfectly works
     // before filtering
 }

}

Thanks for helping.

BradLarson commented 10 years ago

Is the movie a local one on the device? Can you display it to the screen by driving it to a GPUImageView instead of a movie writer? Does the movie show properly in that case?

thibauddavid commented 10 years ago

The movies comes from UIImagePickerControllerSourceTypeCamera. I commented movieWriter part, and replaced it by GPUImageView preview = [[GPUImageView alloc] initWithFrame:self.view.frame]; [self.filter addTarget:(GPUImageView )preview]; [self.mainViewController.view addSubview:preview]; And still got my only frame, without any sound, that time, which I suppose is normal...