3

I want to apply effects on certain frames of movie using GPUImage. I have successfully added effect on entire movie file, so is there a way to add different effects on different frames?

For example, I want to apply effect of Sepia on video from 5 seconds to 10 seconds. So I need 0-5 seconds to be original video, 5-10 seconds with Sepia effect and 10 - video total seconds with original video.

Also, I want to draw text/image on certain frames using GPUImage, is it possible?

Any response will be greatly appreciated.

jigneshbrahmkhatri
  • 3,627
  • 2
  • 21
  • 33

1 Answers1

1

You could ask MPMoviePlayerController or AVAssetImageGenerator to generate a thumbnail at the time you specify.

iPhone Read UIimage (frames) from video with AVFoundation

AVAssetImageGenerator provides images rotated

If you'd like videos instead of just frames, you could trim a section out of the video and apply an effect to that. This takes the URL of your video and trims it to the specified time.

    AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil]; 
    AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:videoAsset presetName:AVAssetExportPresetHighestQuality];
    exportSession.outputURL = [NSURL fileURLWithPath:outputURL];
    exportSession.outputFileType = AVFileTypeQuickTimeMovie;
    CMTimeRange timeRange = CMTimeRangeMake(CMTimeMake(startMilliseconds, 1000), CMTimeMake(endMilliseconds - startMilliseconds, 1000));
    exportSession.timeRange = timeRange;

    [exportSession exportAsynchronouslyWithCompletionHandler:^{
        switch (exportSession.status) {
            case AVAssetExportSessionStatusCompleted:
                 ///
                // Call something to apply the effect
               ///
                break;
            case AVAssetExportSessionStatusFailed:
                NSLog(@"Failed:%@", exportSession.error);
                break;
            case AVAssetExportSessionStatusCancelled:
                NSLog(@"Canceled:%@", exportSession.error);
                break;
            default:
                break;
        }
    }];

Upon completion, you'd then apply your effect and if you went with the video clip route, combine them, and encode them.

How to combine video clips with different orientation using AVFoundation

Community
  • 1
  • 1
Brandon Schlenker
  • 5,078
  • 1
  • 36
  • 58
  • Brandon, thanks for alternate solution. Do you mean, If I want to apply effect on video from 5 seconds to 10 seconds, I should export this 5 seconds video first and then apply effect using GPUImage and then insert it on original video? – jigneshbrahmkhatri May 19 '12 at 06:16
  • Yes, that seems to be the best solution I can find. I'm certainly not an expert at this, so someone else may have a better answer. – Brandon Schlenker May 19 '12 at 08:37
  • Thanks for your solution, I have already thought this one, but I need better solution for this, because It might take time if I apply more than one effects on different different time frames. – jigneshbrahmkhatri May 19 '12 at 15:18