2013-04-14 3 views
6

GPUImageライブラリを使用して、ビデオをファイルシステム上のファイルに記録しています。私はm4vファイルとして保存します。これは私が使用しているコードです: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]; 
    }]; 

これはm4vビデオを記録します。私はその後、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]; 

しかし、プレイヤーはただのバッファリングを開始し、何も起こりません。ビデオの再生が開始されません。プレイヤーは永遠にバッファリングしています。アプリはクラッシュせず、コンソールに警告が表示されないので、何が問題なのか分かりません。

+0

あなたがビデオをチェックして保存先にあるのでしょうか?ビデオが破損していないことを確認するためにPCにダウンロードして再生してください – Ushan87

答えて

0

私は正しいと思わないものをいくつか見ています。

まず、NSHomeDirectoryに直接書き込みを行い、書き込み可能ではないアプリケーションディレクトリを返します(reference参照)。 代わりにDocumentsフォルダまたはLibrary/Cachesフォルダに書き込んでください。

第2に、videoCameraFilterがどのように定義されているかわかりません。あなたはEDIT * 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]; 
}]; 

の対象として追加することを確認する必要があります。@SAMIR RATHODが提案されているよう

あなたはヨーヨーがmoviePlayerプロパティ/ IVAR作ってみましたか? moviePlayerが無限にバッファリングしているという事実は、それが保持されていないために発生している可能性が最も高いです。

あなたのViewControllerのインターフェースにプロパティを追加します。

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer; 

とあなたのMPMoviewPlayerControllerをインスタンス化:

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

いいえ、私はDocumentsディレクトリに書き込みます。私はそれを記録した後、ビデオを再生しようとしています。私はビデオが適切であることを知っています。なぜなら、私がカメラのロールからそれを開くだけで動作するからです。 –

+0

私の編集を参照してください.... –

0

これを試してみてください:

まずチェックvideoPathそれが適切なパスを表示するかどうか?

.hファイル

MPMoviePlayerController*  player 

.M @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]; 
    } 
関連する問題