Ric*_*nop 6 objective-c m4v ios gpuimage
我正在使用GPUImage库将视频录制到文件系统上的文件中.我把它保存为m4v文件.这是我正在使用的代码:
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];
}];
Run Code Online (Sandbox Code Playgroud)
这会记录一个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];
Run Code Online (Sandbox Code Playgroud)
然而,玩家只是开始缓冲而没有任何反应.视频无法播放.玩家只是永远缓冲.应用程序没有崩溃,控制台中没有警告,所以我不知道是什么问题.
我发现有几件事看起来不太对劲。
首先,您直接写入,NSHomeDirectory该目录返回不可写的应用程序目录(请参阅参考资料)。要么写入该Documents文件夹,要么改为写入该Library/Caches文件夹。
其次我不明白如何videoCameraFilter定义。您需要确保将其添加为目标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];
}];
Run Code Online (Sandbox Code Playgroud)
* 编辑:
您是否尝试按照@SAMIR RATHOD 的建议创建moviePlayer属性/ivar?moviePlayer 一直在那里无休止地缓冲的事实很可能是因为它没有被保留。
将属性添加到 viewController 的界面:
@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
Run Code Online (Sandbox Code Playgroud)
并实例化你的MPMoviewPlayerController:
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1755 次 |
| 最近记录: |