3

What i am trying to do:

I am trying to get the start and end time of the frames chosen as in the attachement below: enter image description here

What i have done so far:

  1. UIImagePickerController: Implemented and found that start and end time won't be returned from the delegate "didFinishPickingMediaWithInfo", if the video input is chosen from the album. Confirmed with Apple team too.
  2. Tried with "UIVideoEditorController" and finally couldn't get the start and end time.
  3. Planning to try with "AVAssetImageGenerator" to generate the thumbnails and to programmatically handle the "stick or marker" to choose the frames along with AVPlayer to have instant preview as in the IOS movie player.(as in the attachment). But its quite uneasy and complicated and not sure about its processing speed.

What i want to know:

  1. Apart from the above three techniques, are there any other way to have the video trimmer functionality? Any direct api's from Apple SDK?
  2. Can anyone give a reference links or sample codes for "AVAssetImageGenerator" based video trimmer?
2vision2
  • 4,933
  • 16
  • 83
  • 164

1 Answers1

2

If you use AVPlayer , you can get the start and end time of the player asset using

self.player.currentItem.asset.duration;

Then use a custom slider to select the start and end frames and convert the values relative to the total duration and the length of the slider and the value from slider.

once you have an approximate start and end time frame,proceed as follows

AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:player.currentItem.asset];



    CGImageRef cgIm = [generator copyCGImageAtTime:player.currentTime 
                                        actualTime:&actualTime 
                                             error:&error];
    UIImage *image = [UIImage imageWithCGImage:cgIm];
JIthin
  • 1,413
  • 1
  • 13
  • 29
  • Thanks for the answer. True, i am going to try this option. Will the time durations be accurate in this way? The customized slider won't be like default UIImagePickerController(Eg: when you hold on frames, the thumbnail will get extracted to show few more images in the selected region).. Thats one of the reasons why i am looking for "UIImagePickerController" like feature. – 2vision2 Aug 05 '14 at 12:44
  • I think the accuracy will be good enough. You can improve it by setting higher range for slider.I haven't tried it with UIImagePickerController. – JIthin Aug 05 '14 at 12:57
  • I want to select video of maximum 30 seconds from gallery, any suggestions how to do it and please provide swift code if possible @JIthin – Parth Barot Jul 05 '18 at 06:34