Question

I am developing an app which edit videos. There is no problem when I record video because, initially I will set all the settings like saturation, brightness, contrast etc.

But the problem is with recorded videos. I am unable to change all the above properties of videos which are recorded already.

Anyone please tell me the solution for he problem.

Any good solutions, suggestions will be appreciated.

Was it helpful?

Solution

Movies can be loaded into the framework via the GPUImageMovie class, filtered, and then written out using a GPUImageMovieWriter. GPUImageMovieWriter is also fast enough to record video in realtime from an iPhone 4's camera at 640x480, so a direct filtered video source can be fed into it.

The following is an example of how you would load a sample movie, pass it through a pixellation and rotation filter, then record the result to disk as a 480 x 640 h.264 movie:

movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
pixellateFilter = [[GPUImagePixellateFilter alloc] init];
GPUImageRotationFilter *rotationFilter = [[GPUImageRotationFilter alloc] initWithRotation:kGPUImageRotateRight];

[movieFile addTarget:rotationFilter];
[rotationFilter addTarget:pixellateFilter];

NSString *pathToMovie = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Movie.m4v"];
unlink([pathToMovie UTF8String]);
NSURL *movieURL = [NSURL fileURLWithPath:pathToMovie];

movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(480.0, 640.0)];
[pixellateFilter addTarget:movieWriter];

[movieWriter startRecording];
[movieFile startProcessing];

Once recording is finished, you need to remove the movie recorder from the filter chain and close off the recording using code like the following:

[pixellateFilter removeTarget:movieWriter];
[movieWriter finishRecording];

A movie won't be usable until it has been finished off, so if this is interrupted before this point, the recording will be lost.

Here is good tutorial:

http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework

See "Filtering and re-encoding a movie" section.

OTHER TIPS

Here is the code which worked for me.I used GPUImage.

viewController.h

#import "GPUImage.h"

GPUImageMovie *movieFile;
GPUImageOutput<GPUImageInput> *filter;
GPUImageMovieWriter *movieWriter;

int ArrayIndex;
UISlider *mSlider;

ViewController.m

NSURL *sampleURL = [[NSBundle mainBundle] URLForResource:@"sample_iPod" withExtension:@"m4v"];

    mSlider=[[UISlider alloc]initWithFrame:CGRectMake(60,380,200, 30)];
    mSlider.continuous=YES;
    [mSlider addTarget:self action:@selector(updatePixelWidth:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:mSlider];

    movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];
    movieFile.runBenchmark = YES;
    movieFile.playAtActualSpeed = YES;

    if(ArrayIndex==0)
    {
         filter=[[GPUImageBrightnessFilter alloc]init];

        mSlider.maximumValue=1.0;
        mSlider.minimumValue=-1.0;
        mSlider.value=0.0;
    }
    else if(ArrayIndex==1)
    {
         filter=[[GPUImageContrastFilter alloc]init];

        mSlider.minimumValue=0.0;
        mSlider.maximumValue=4.0;
        mSlider.value=1.0;

    }
    else if(ArrayIndex==2)
    {
         filter=[[GPUImageSaturationFilter alloc]init];

        mSlider.minimumValue=0.0;
        mSlider.maximumValue=2.0;
        mSlider.value=1.0;

    }

    [movieFile addTarget:filter];

    // Only rotate the video for display, leave orientation the same for recording
    GPUImageView *filterView = (GPUImageView *)self.view;
    [filter addTarget:filterView];

    // In addition to displaying to the screen, write out a processed version of the movie to disk
    NSString *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];

    movieWriter = [[GPUImageMovieWriter alloc] initWithMovieURL:movieURL size:CGSizeMake(640.0, 480.0)];
    [filter addTarget:movieWriter];

    // Configure this for video from the movie file, where we want to preserve all video frames and audio samples
    movieWriter.shouldPassthroughAudio = YES;
    movieFile.audioEncodingTarget = movieWriter;
    [movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];

    [movieWriter startRecording];
    [movieFile startProcessing];

    [movieWriter setCompletionBlock:^{
        [filter removeTarget:movieWriter];
        [movieWriter finishRecording];

        if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (pathToMovie)) {
            UISaveVideoAtPathToSavedPhotosAlbum (pathToMovie,self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
        }

    }];



- (void)updatePixelWidth:(id)sender
{
    if(ArrayIndex==0)
    {
        [(GPUImageBrightnessFilter *)filter setBrightness:[(UISlider *)sender value]];
    }
    else if (ArrayIndex==1)
    {
          [(GPUImageContrastFilter *)filter setContrast:[(UISlider *)sender value]];
    }
    else if (ArrayIndex==2)
    {
        [(GPUImageSaturationFilter *)filter setSaturation:[(UISlider *)sender value]];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top