How to trim the video file and convert to 15 seconds video with iOS SDK?

前端 未结 2 875
独厮守ぢ
独厮守ぢ 2020-12-15 12:40

I want to trim a video file. I want to just pick the video from a gallery and convert it to a 15-second video. If I use normal trimming with picker view controller, it does

2条回答
  •  暖寄归人
    2020-12-15 12:54

    The above answer worked for me with a little change in case we need to set both start time and end time to trim.

    I changed this:

    CMTime start = CMTimeMakeWithSeconds(1.0, 600); // you will modify time range here
    CMTime duration = CMTimeMakeWithSeconds(15.0, 600);
    CMTimeRange range = CMTimeRangeMake(start, duration);
    

    To this:

    CMTime start = CMTimeMakeWithSeconds(self.StartTime, 600); // you will modify time range here
        CMTime duration = CMTimeSubtract(CMTimeMakeWithSeconds(self.EndTime, 600), start);
        CMTimeRange range = CMTimeRangeMake(start, duration);
    

    It worked for me.

提交回复
热议问题