Search code examples
objective-cgpuimagegpuimagestillcamera

Cannot save a live video file in gpuimage framework objective c


I'm creating the camera app for ios with live video features by importing GPUImage framework.I used this framework for live photos it was working good.I used the following code for live video with the reference of 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];

MY doubt : How to save the video to the photo gallery.I reviewed other blogs they are using the urls, I'm not sure how to implement the url for photo gallery. I used the following code to save the live video to the photo gallery, but I couldnt find the video capture.

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

I want to know, how to find pathToMovie?

please help.Thanks in advance.


Solution

  • To reference of the above Question, I solved the camera roll path for live video's by giving the following code,

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

    Along with the code I mentioned in the question(video camera initiation), add the following code, so that the live video will be in buffer.

    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");
    

    To save the live video the following code works for me,

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