无法在gpuimage框架目标c中保存实时视频文件

时间:2016-05-05 17:15:34

标签: objective-c gpuimage gpuimagestillcamera

我正在通过导入GPUImage框架为具有实时视频功能的ios创建相机应用程序。我使用此框架实时照片它运行良好。我使用以下代码进行实时视频,参考Brad github,

videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;

startfilter = [[GPUImageFilter alloc] init];
outputView = [[GPUImageView alloc] initWithFrame:CGRectMake(0.0, 0.0,self.view.frame.size.width,self.view.frame.size.height)];
 [self.image_view addSubview:outputView];
[startfilter removeAllTargets];
// Add the view somewhere so it's visible
[startfilter forceProcessingAtSize:outputView.sizeInPixels];
[videoCamera useNextFrameForImageCapture];
[videoCamera addTarget:startfilter];
[startfilter addTarget:outputView];

[videoCamera startCameraCapture];

我怀疑: 如何将视频保存到照片库。我查看了他们使用网址的其他博客,我不知道如何实现照片库的网址。 我使用以下代码将实时视频保存到照片库,但我无法找到视频捕获。

[videoCamera stopCameraCapture];
UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, nil, nil);

我想知道,如何找到pathToMovie?

请帮忙。谢谢。

1 个答案:

答案 0 :(得分:0)

为了参考上述问题,我通过提供以下代码解决了直播视频的相机滚动路径,

pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];

除了我在问题中提到的代码(摄像机启动),添加以下代码,以便实时视频将在缓冲区中。

pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]); // If a file already exists, AVAssetWriter won't let you record new frames, so delete the old movie
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];
[movieFile addTarget:startfilter];
movie_write = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480, 640)];
movie_write.shouldPassthroughAudio=YES;
videoCamera.audioEncodingTarget=movie_write;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movie_write];
[movie_write startRecording];
[movieFile startProcessing];
[videoCamera startCameraCapture];
NSLog(@"Movie completed");

要保存实时视频,以下代码适合我,

   [startfilter useNextFrameForImageCapture];
    UIImage*process=[[UIImage alloc]init];
    process=[startfilter imageFromCurrentFramebuffer];
     NSLog(@"Image %@",process);

    [videoCamera pauseCameraCapture];

        [startfilter removeTarget:movie_write];
        UISaveVideoAtPathToSavedPhotosAlbum(pathToMovie, nil, nil, nil);
       [movie_write finishRecording];
   [videoCamera stopCameraCapture];