cmtime

AVPlayer seekToTime not working properly

。_饼干妹妹 提交于 2019-12-05 18:05:29
Im having a problem with seeking with AVPlayer.seekToTime, I have the time index that I want to seek to inside a scrollViewDidScroll method like this: func scrollViewDidScroll(scrollView: UIScrollView) { let offsetTime = scrollView.contentOffset.y * 0.1 self.playerController.player?.seekToTime(CMTime(seconds: Double(offsetTime), preferredTimescale: 10), toleranceBefore: kCMTimePositiveInfinity, toleranceAfter: kCMTimeZero) } But the video does not flow nice. For example, when you scroll I want the video to only to move forward like 0.01 of a second (the video I have is real short only about 2

AVPlayer - Add Seconds to CMTime

巧了我就是萌 提交于 2019-12-04 17:24:37
问题 How can I add 5 seconds to my current playing Time? Actually this is my code: CMTime currentTime = music.currentTime; I can´t use CMTimeGetSeconds() , because I need the CMTime format. Thank you for your answers... EDIT: How can I set a variable for CMTime? 回答1: Here is one way: CMTimeMakeWithSeconds(CMTimeGetSeconds(music.currentTime) + 5, music.currentTime.timescale); 回答2: elegant way is using CMTimeAdd CMTime currentTime = music.currentTime; CMTime timeToAdd = CMTimeMakeWithSeconds(5,1);

Movement by a single frame in CMTime and AVFoundation

﹥>﹥吖頭↗ 提交于 2019-12-04 12:00:22
问题 I'm attempting to play a video with AVFoundation. I am using the following code for a button that advances the playback by one frame. It works intermittently, on some executions it will do the right thing and advance one frame, but most times I will have to press the button 3 or 4 times before it will advance a frame. This makes me think it is some kind of precision issue, but I can't figure out what it is. Each time it is run the new CMTime appears to be advancing by the same amount. My

AVAssetWriterInputPixelBufferAdaptor and CMTime

懵懂的女人 提交于 2019-12-03 16:16:54
问题 I'm writing some frames to video with AVAssetWriterInputPixelBufferAdaptor , and the behavior w.r.t. time isn't what I'd expect. If I write just one frame: [videoWriter startSessionAtSourceTime:kCMTimeZero]; [adaptor appendPixelBuffer:pxBuffer withPresentationTime:kCMTimeZero]; this gets me a video of length zero, which is what I expect. But if I go on to add a second frame: // 3000/600 = 5 sec, right? CMTime nextFrame = CMTimeMake(3000, 600); [adaptor appendPixelBuffer:pxBuffer

Movement by a single frame in CMTime and AVFoundation

一笑奈何 提交于 2019-12-03 07:39:12
I'm attempting to play a video with AVFoundation. I am using the following code for a button that advances the playback by one frame. It works intermittently, on some executions it will do the right thing and advance one frame, but most times I will have to press the button 3 or 4 times before it will advance a frame. This makes me think it is some kind of precision issue, but I can't figure out what it is. Each time it is run the new CMTime appears to be advancing by the same amount. My other theory is that it could be caused by the currentTime not being set to an exact frame boundary at my

AVAssetWriterInputPixelBufferAdaptor and CMTime

陌路散爱 提交于 2019-12-03 05:32:21
I'm writing some frames to video with AVAssetWriterInputPixelBufferAdaptor , and the behavior w.r.t. time isn't what I'd expect. If I write just one frame: [videoWriter startSessionAtSourceTime:kCMTimeZero]; [adaptor appendPixelBuffer:pxBuffer withPresentationTime:kCMTimeZero]; this gets me a video of length zero, which is what I expect. But if I go on to add a second frame: // 3000/600 = 5 sec, right? CMTime nextFrame = CMTimeMake(3000, 600); [adaptor appendPixelBuffer:pxBuffer withPresentationTime:nextFrame]; I get ten seconds of video, where I'm expecting five. What's going on here? Does

Make CMTime with a very small value

China☆狼群 提交于 2019-12-02 02:08:44
问题 I have a small integer value and I want to convert it into CMTime. The problem is that CMTime(value: _ , timeScale: _) or CMTimeMakeWithSeconds(value: _ , timeScale: _) will always return the floor so that time always equals 0.0 seconds let smallValue = 0.0401588716 let frameTime = CMTime(Int64(smallValue) , timeScale: 1) //frameTime is 0.0 seconds because of Int64 conversion let frameTimeInSeconds = CMTimeMakeWithSeconds(smallValue , timeScale: 1) // frameTimeInSeconds also returns 0.0

Make CMTime with a very small value

落花浮王杯 提交于 2019-12-02 00:31:59
I have a small integer value and I want to convert it into CMTime. The problem is that CMTime(value: _ , timeScale: _) or CMTimeMakeWithSeconds(value: _ , timeScale: _) will always return the floor so that time always equals 0.0 seconds let smallValue = 0.0401588716 let frameTime = CMTime(Int64(smallValue) , timeScale: 1) //frameTime is 0.0 seconds because of Int64 conversion let frameTimeInSeconds = CMTimeMakeWithSeconds(smallValue , timeScale: 1) // frameTimeInSeconds also returns 0.0 seconds. CMTime represents a time value as a rational number with integer numerator (the value ) and

Trying to understand CMTime

我只是一个虾纸丫 提交于 2019-11-26 09:21:06
问题 I have seen some examples of CMTime (Three separate links), but I still don\'t get it. I\'m using an AVCaptureSession with AVCaptureVideoDataOutput and I want to set the max and min frame rate of the the output. My problem is I just don\'t understand the CMTime struct. Apparently CMTimeMake(value, timeScale) should give me value frames every 1/timeScale seconds for a total of value/timeScale seconds, or am I getting that wrong? Why isn\'t this documented anywhere in order to explain what this