DrustZ / ICGVideoTrimmer_extend

A library for quick video trimming, mimicking the behavior of Instagram's
MIT License
15 stars 4 forks source link

Video length exceeds the end time which is given. #4

Open ajay2c9 opened 7 years ago

ajay2c9 commented 7 years ago

HI, I am using the ICGVideoTrimmer_extend in my app. I am facing a little problem with end time in the below scenario. I am cropping two videos and playing. The Maximum limit of the video is 10 seconds. I am loading a video and give the stop time as 5 seconds at first and later it can be adjusted. here is the code //Setting the start time and end time to the trimmer view self.startTime=0 self.stopTime=5.0 self.trimmerView.setVideoBoundsToStartTime(CGFloat(self.startTime), endTime: CGFloat(self.stopTime)) I am displaying the trim time i.e trimmed video length in the onplaybacktimechecker method like below.

/////////// ON PLAYBACK TIME CHECKER METHOD

let duration:CMTime = CMTimeMakeWithSeconds(Float64(self.stopTime - self.startTime),self.player.currentItem!.asset.duration.timescale) trim1time = CGFloat(CMTimeGetSeconds(duration)) let str:String = String(format: "%.2f", trim1time) timelbl.text = "Trim length: " + str

I am saving the start time and end time which is comming from delegate method. When i am getting the video length from the above process,video length exceeds stop time. which is given(5) and it shows like 5.02 or 5.06 or 5.08 like that for some videos, and shows correctly for some videos.i.e 5.0 I give the start time as "0" and stop time as "5.0". Video length is displaying more than stop time .If i give stop time as 6 or 4 it will work fine for the above calculation. but i give 5 it video length exceeds .i.e end time exceeds.

How to handle this situation

DrustZ commented 7 years ago

Hi,

Thanks for using the library. However, due to the long period since last time I modified the codes, it's kinda difficult for me to dig into details of the problem :~(

I guess it was because the precision of duration. let duration:CMTime = CMTimeMakeWithSeconds(Float64(self.stopTime - self.startTime),self.player.currentItem!.asset.duration.timescale) With some googling I got those links: AVPlayer seekTo not accurate and AVAsset duration is not correct hope these will help.