iOS trim video to fixed length - ios

I would like to be able to select a video from the photo library and pick out 15 seconds of video from an existing clip. Is there a way to force the trim to be a fixed length?

Set the UIImagePickerController property, videoMaximumDuration to the fixed length you want. From the documentation:
The maximum duration, in seconds, for a video recording.
#property (nonatomic) NSTimeInterval videoMaximumDuration
Discussion
The default value for this property is 10 minutes (600 seconds). When a user taps the Share button to send a movie to MMS, MobileMe, YouTube, or another destination, an appropriate duration limit and an appropriate video quality are enforced.
This property is available only if the mediaTypes property’s value array includes the kUTTypeMovie media type.

Can you please see the following code. I hope it will be helpful to you
-(void)recordVideo{
imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [[NSArray alloc]initWithObjects:(NSString *) kUTTypeMovie, (NSString *) kUTTypeMPEG4, nil];
imagePicker.videoQuality = UIImagePickerControllerQualityTypeIFrame1280x720;
[imagePicker setVideoMaximumDuration:15.0f];
sourceType = [UIImagePickerController availableMediaTypesForSourceType:imagePicker.sourceType];
if (![sourceType containsObject:(NSString *) kUTTypeMovie]) {
NSLog(#"Can not Save Video");
}
[self presentModalViewController:imagePicker animated:YES];
}
Make sure that, you have to set allowsEditing to YES before presenting the controller.

Related

UIImagePickerController trim controls not showing

I've been unable to get the trim controls to appear when capturing an iOS movie.
Here's my code:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = #[(__bridge NSString *)kUTTypeMovie, (__bridge NSString *)kUTTypeImage];
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
Additionally, I'm capturing the reply with imagePickerController:didFinishPickingMediaWithInfo:.
From searching StackOverflow I'm aware that I need to actually trim the video myself. That doesn't seem too difficult, but while I get the image picker and can capture a video I can't get the trim controls to appear! What am I missing?
My mistake was just in using video samples that were too short. They need to be over a certain length before the trimming tools will appear.

Control trim seek bar in UIImagePickerController with Source type camera

In my application i need to allow the user to record the video without any time limit (only while recording), but after recording in the edit view, i need to control the trim seek bar up to 30 sec (meaning user can use only the 30 secs video alone from the recorded full length video).
Here is my code to present the picker controller:
picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
picker.allowsEditing = YES;
picker.delegate = (id<UIImagePickerControllerDelegate,UINavigationControllerDelegate>) self;
[self presentModalViewController: picker animated: YES];
if we set the video maximum duration is 30 sec means we cant record after 30 sec it will break my functionality.
my question is, is it possible to control the trim seek bar with out the knowledge of maximum duration property
or
is it possible to alert the user based on the video current trim length status while trimming?
Please guide me to fix this issue. Thanks in advance.
Your best bet would be to implement your own trimming solution.
See:
https://github.com/andrei200287/SAVideoRangeSlider

How to select multiple video from camera roll and photo Gallery?

I want to upload multiple video to server using ASIHttDataFormRequest.For selecting video ,I am using ImagePickerViewController But it doesn't give the option to select multiple video.
Bellow is the code, which is used to open imagePicker and but unable to select multiple video.
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.allowsEditing = YES;
imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
Please help me by giving some clue or code. Thanks in Advance
Use this sample
https://github.com/B-Sides/ELCImagePickerController
For video multiple selection refer
Use ELCImagePickerController to pick video
Hope it helps you..
Here is the library to take a photo or select from library: https://github.com/fulldecent/FDTake
This works great so far for photos. Video is in progress.

add UIView overlay to UIIMagePickerController video recording

i want to use UIIMagePickerController to record video as i would normally do.
but i want to add a layer (UIView) that needs to be captured within the video overlay.
lets sat i have a star spinning on my view. when i will take the video i will see the star spinning as i am recording and when finish recording the same output will be.
i know this object has a property :
#property (nonatomic, retain) UIView *cameraOverlayView
but i think it needs to manage only the buttons that would not be captured.
what is the normal\recommended approach to manage such a thing?
Generally, you can add your custom overlay view and UIImagePickerController.view as subviews to one view.
User startVideoCapture and stopVideoCapture to do your task.
Sample codes:
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
picker.showsCameraControls = NO;
picker.delegate = self;
self.videoPicker = picker;
[self.view addSubview:self.videoPicker.view];
Of course, if you do this, the control of flash lights should be done by yourself.

Programmatically take X amount of pictures

I am trying to implement a feature of taking X amount of pictures programmatically after entering a UIViewController for both the iPhone and iPad. I looked into UIImagePickerController but I do not want to present the camera controls and have the user hit a button to capture only one photo. Is there a way to capture X amount of photos once entering a UIViewController and storing all the photos in the end for future reference in one go?
Edit:
-(void)viewDidAppear:(BOOL)animated
{
// Create image picker controller
picker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
// Set source to the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
picker.delegate = self;
// Allow editing of image ?
picker.allowsEditing = NO;
//picker.showsCameraControls = NO;
// Show image picker
[picker animated:YES completion:nil];
}
straight away with takePicture you can not take multiple snaps, for that you have to use some video recording and get snap out of it for particular frame or time, for you more reference you can use this apple documentation for bulk snaps AVFoundation Programming Guide
You can try something like this:
int numberOfPhotos = 3; // Number of photos you want to take.
for ( int i = 0; i < numberOhPhotos; i++ )
{
// Note that you should use some sort of a pause in between each photo.
[picker takePicture];
}

Resources