1

I use UIImagePickerController to edit video and cut it, I create it like this:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[imagePicker setVideoQuality:UIImagePickerControllerQualityType640x480];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = @[(__bridge NSString *)kUTTypeMovie, (__bridge NSString *)kUTTypeVideo, (__bridge NSString *)kUTTypeMPEG4];
imagePicker.allowsEditing = YES;
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];

but unfortunately in delegate method that is called I cant get start and end editing time - to save edited video:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {

    [picker dismissViewControllerAnimated:YES completion:^{

    }];

    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
        [type isEqualToString:(NSString *)kUTTypeMovie]) { // movie != video
        NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];


        NSNumber *start = [info objectForKey:@"_UIImagePickerControllerVideoEditingStart"];
        NSNumber *end = [info objectForKey:@"_UIImagePickerControllerVideoEditingEnd"];

}

in my case start and end is nil. I have no idea how to get this information. Could you please advice how to get it? Thank you in advance for any help.

Melany
  • 466
  • 7
  • 20

1 Answers1

1

I just check your code and run and i found that _UIImagePickerControllerVideoEditingStart and _UIImagePickerControllerVideoEditingEnd return only captured video from camera but if you are select video from your PhotoLibrary you did not get this two key in info dictionary:

If you are using imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; then you will get following info dictionary log:

    UIImagePickerControllerMediaType = "public.movie";
    UIImagePickerControllerMediaURL = "file:///private/var/mobile/Containers/Data/Application/BCBE6A30-1A92-41BB-8734-BFF052E416DE/tmp/trim.59737F15-FC2A-4EB7-89AE-DF3831089657.MOV";
    UIImagePickerControllerReferenceURL = "assets-library://asset/asset.MOV?id=87E3E50A-1DBF-449F-8BE3-AB36E718D82C&ext=MOV";

If you are using imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; then you will get following info dictionary log:

    UIImagePickerControllerMediaType = "public.movie";
    UIImagePickerControllerMediaURL = "file:///private/var/mobile/Containers/Data/Application/611D33A4-61F4-4CD0-934D-C0EFF82B75AC/tmp/capture/capturedvideo.MOV";
    "_UIImagePickerControllerVideoEditingEnd" = "2.360877976190476";
    "_UIImagePickerControllerVideoEditingStart" = "1.360505952380952";

So at the end with UIImagePickerControllerSourceTypePhotoLibrary UIImagePickerController wont provide a _UIImagePickerControllerVideoEditingStart and _UIImagePickerControllerVideoEditingEnd key. so you can get its duration by using AVURLAsset like following code that assume start Time is 0 and end time is full duration.

AVURLAsset *Asset = [AVURLAsset assetWithURL:videoURL];
CMTime duration = [Asset duration];
int fullduration = ceil(duration.value/duration.timescale);
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • 1
    thank you very much!!! Yes I got it, thanks for explanation. I had to convert trimmed video to audio file - so finally I used UIImagePickerControllerMediaURL - and converted it into audio. Thanks one again!!! – Melany Jun 24 '16 at 13:37
  • by the way do you know whether there is possibility to use UiImagePickerController - without entering into Library - just directly into the selected video? – Melany Jun 24 '16 at 13:40
  • Yes you can use `ALAssetsLibrary` that you no need to use `UiImagePickerController` you need to create your own UI for that check: http://stackoverflow.com/questions/17585908/how-can-i-get-the-list-of-all-video-files-from-library-in-ios-sdk – Nitin Gohel Jun 24 '16 at 13:43
  • yes, but I need also to have possibility for trimming video, and it doesn't have this... – Melany Jun 24 '16 at 13:57
  • thank you for this answer mate, you saved me quite some time to try and figure out this by myself, seems we have to make our own ui – thibaut noah Feb 02 '17 at 08:43