Unable to play VCR using GPUImage

I use the GPUImage library to write video to a file on the file system. I save it as an m4v file. This is the code I'm using:

  NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:recordingDestination]; unlink([pathToMovie UTF8String]); NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1280.0, 720.0)]; [videoCameraFilter addTarget:movieWriter]; movieWriter.shouldPassthroughAudio = YES; movieFile.audioEncodingTarget = movieWriter; [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter]; [movieWriter startRecording]; [movieFile startProcessing]; [movieWriter setCompletionBlock:^{ [videoCameraFilter removeTarget:movieWriter]; [movieWriter finishRecording]; }]; 

Records m4v video. Then I will try to play it using MPMoviePlayerController :

  NSString *videoPath = [NSString stringWithFormat:@"%@/%@", [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"], [libraryFiles objectAtIndex:selectedCell]]; NSLog(videoPath); NSURL *url=[[NSURL alloc] initWithString:videoPath]; MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDonePressed) name:MPMoviePlayerDidExitFullscreenNotification object:moviePlayer]; moviePlayer.controlStyle=MPMovieControlStyleDefault; [moviePlayer play]; [self.view addSubview:moviePlayer.view]; [moviePlayer setFullscreen:YES animated:YES]; 

However, the player simply starts buffering and nothing happens. The video does not start. The player simply buffers forever. The application does not crash, and there are no warnings on the console, so I don’t know what the problem is.

+6
source share
2 answers

I see a couple of things that do not look right.

First, you write directly to NSHomeDirectory , which returns an application directory that is not writable (see reference ). Either write to the Documents folder, or to the Library/Caches .

Secondly, I do not see how videoCameraFilter is videoCameraFilter . You must be sure to add it as a movieFile target

 GPUImageMovie *movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *pathToMovie = [documentsDirectory stringByAppendingPathComponent:@"filtered-movie.m4v"]; unlink([pathToMovie UTF8String]); NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie]; GPUImageMovieWriter *movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(1920.0, 1080.0)]; GPUImageBoxBlurFilter * videoCameraFilter = [[GPUImageBoxBlurFilter alloc] init]; // just a random filter... videoCameraFilter.blurSize = 2.0; [movieFile addTarget:videoCameraFilter]; [videoCameraFilter addTarget:movieWriter]; movieWriter.shouldPassthroughAudio = YES; movieFile.audioEncodingTarget = movieWriter; [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter]; [movieWriter startRecording]; [movieFile startProcessing]; __weak GPUImageMovieWriter *weakMoviewWriter = movieWriter; [movieWriter setCompletionBlock:^{ [movieFile removeTarget:weakMoviewWriter]; [weakMoviewWriter finishRecording]; }]; 

* EDIT:

Have you tried making the moviePlayer property / ivar as @SAMIR RATHOD suggested? The fact that moviePlayer remains there with endless buffering is most likely due to the fact that it does not persist.

add a property to your viewController interface:

 @property (nonatomic, strong) MPMoviePlayerController *moviePlayer; 

and create an instance of MPMoviewPlayerController :

 self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
0
source

Try the following:

First check if VideoPath displays the correct path or not?

.h file

  MPMoviePlayerController* player 

.m @synthesize player;

  -(void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:videoPath]]; player.scalingMode = MPMovieScalingModeFill; player.movieSourceType = MPMovieSourceTypeFile; player.view.frame = CGRectMake(0, 45, 320, 400); player.shouldAutoplay = YES; [player prepareToPlay]; [self.view addSubview:player.view]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player play]; } #pragma mark MoviPlayer Method - (void) movieFinishedCallback:(NSNotification*) aNotification { MPMoviePlayerController *player1 = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player1]; [player stop]; [player1.view removeFromSuperview]; player1 = nil; [self.navigationController popViewControllerAnimated:YES]; } -(void) dealloc { [player release]; [super dealloc]; } 
0
source

All Articles