2013-04-14 8 views
6

Sto utilizzando la libreria GPUImage per registrare un video su un file sul filesystem. Lo salvo come file m4v. Questo è il codice che sto usando:Impossibile riprodurre il videoregistratore con GPUImage

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]; 
    }]; 

Questo registra un video m4v. Allora provo a giocare con 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]; 

Tuttavia, il giocatore appena inizia il buffering e non succede nulla. Il video non inizia a giocare. Il giocatore sta semplicemente tamponando per sempre. L'app non si arresta in modo anomalo e non ci sono avvisi nella console, quindi non so quale sia il problema.

+0

Hai controllato il video è lì nella destinazione salvato? scarica e riproduci sul tuo PC per assicurarti che il video non sia corrotto. – Ushan87

risposta

0

Vedo in un paio di cose che non sembrano giuste.

Prima di tutto, si scrive direttamente su NSHomeDirectory che restituisce la directory dell'applicazione che tuttavia non è scrivibile (vedere reference). Scrive invece nella cartella o nella cartella Library/Caches.

In secondo luogo, non vedo come sia definito videoCameraFilter. È necessario assicurarsi di aggiungerlo come un obiettivo di movieFile

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:

Hai provato yo fare moviePlayer una proprietà/Ivar come suggerito @SAMIR Rathod? Il fatto che MoviePlayer resti lì a buffering senza fine è probabilmente causato perché non viene mantenuto.

aggiungere un alloggio alla vostra interfaccia di viewController:

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer; 

e istanziare la tua MPMoviewPlayerController:

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

No, sto scrivendo alla cartella Documenti. Sto quindi cercando di riprodurre il video DOPO che lo registro. So che il video è corretto, perché se lo apro dal rullino fotografico, funziona. –

+0

Vedi la mia modifica .... –

0

Prova questo:

In primo luogo controllare videoPath si visualizza il corretto percorso o no?

file h

MPMoviePlayerController*  player 

.m giocatore @synthesize;

-(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]; 
    }