Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cropping videos in iOS

Tags:

iphone

ios4

crop

We can crop images. Can we crop videos?

like image 850
Anand Avatar asked Jun 02 '11 09:06

Anand


2 Answers

Since video is a collection of pictures you can crop all frames from video and after create new video. AVFoundation guide describe some tasks: Putting it all Together: Capturing Video Frames as UIImage Objects After this you crops images and write video

You can use an asset writer to produce a QuickTime movie file or an MPEG-4 file from media such as sample buffers or still images.

See for more details AV Foundation Framework

like image 94
beryllium Avatar answered Oct 23 '22 17:10

beryllium


[[NSFileManager defaultManager] removeItemAtURL:outputURL error:nil];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:inputURL options:nil];
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetLowQuality];
exportSession.outputURL = outputURL;
exportSession.shouldOptimizeForNetworkUse = YES;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;

CMTime start = CMTimeMakeWithSeconds(1.0, 600);
CMTime duration = CMTimeMakeWithSeconds(120.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;

[exportSession exportAsynchronouslyWithCompletionHandler:^(void){
               handler(exportSession);
               [exportSession release];}];

Here we get a video of first 2 mins.

like image 40
aViNaSh Avatar answered Oct 23 '22 19:10

aViNaSh