如何编辑亮度,对比度和饱和度并添加已保存在库中的已创建视频的字幕?

时间:2013-12-17 05:18:13

标签: ios iphone xcode ipad video

我正在制作一个视频应用,我必须调整已经创建的视频的亮度,对比度和饱和度。我还要在电影中添加字幕。我已经阅读了很多关于它的内容并且了解了有关视频的信息,我们可以在创建视频时添加亮度,对比度和饱和度,但无法在已创建的视频中进行编辑。此外,我已经了解了如何添加文本视频,但我想让它像电影一样间隔地播放字幕。

使用GPUImage我在录制时改变了这样的亮度。

GPUImageFilter *selectedFilter = nil ;
selectedFilter = [[GPUImageBrightnessFilter alloc] init];
[(GPUImageBrightnessFilter*)selectedFilter setBrightness:brightnesSlider.value];

但是我需要编辑已经制作并保存在图库中的视频。任何线索。

参考文献:

Apple Edit Demo

RAY WENDERLICH

Brightness,Contrast and saturation

1 个答案:

答案 0 :(得分:1)

以下代码对我有用。我使用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]];
    }
}