How to get the start and end time for the selected frames from the video using iOS sdk?

1.4k Views Asked by At

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?
1

There are 1 best solutions below

3
On

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];