Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zoom, Crop and Cut videos iPhone

I have a small video clip in my iPhone Application on which I wish to carryout the following operations -

  1. Zoom - I should be able to zoom in and out the video by pinching gestures.
  2. Crop - I should be able to Crop the video length after increasing/decreasing its speed.
  3. Cut - I should be able to drag a window on any part of the video and cut that piece of video which is within the window as a separate video.

Since the video size is very small (less than a minute), all I can think of is converting the video into images by extracting each frames and then carry-out the above operations. Can anyone suggest a better idea?

Thanks

like image 268
girish_vr Avatar asked Dec 03 '25 17:12

girish_vr


1 Answers

An easy an fast way to achieve these operations would be to use the GPUImage framework. You should be looking at the GPUImageMovie class in GPUImage to edit movies in iOS. The framework already comes with a set of filters that you can use to carry out the operations that you need. See this section for more details on how to edit videos using GPUImage.

In short, you first create a GPUImageMovie object:

movieFile = [[GPUImageMovie alloc] initWithURL:sampleURL];

Then create some filters and apply the filters to the object.

cropFilter = [[GPUImageCropFilter alloc] init];
[movieFile addTarget:cropFilter];

You can add more filters in the chain by adding targets to the previousFilter in your chain. Finally, when you are ready to convert the video, do this:

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.shouldPassthroughAudio = YES;
movieFile.audioEncodingTarget = movieWriter;
[movieFile enableSynchronizedEncodingUsingMovieWriter:movieWriter];

[movieWriter startRecording];
[movieFile startProcessing]
like image 179
Pulkit Goyal Avatar answered Dec 06 '25 06:12

Pulkit Goyal