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 withPresentationTime
somehow set both the start of the frame and the duration?
Note that I'm not calling endSessionAtSourceTime
, just finishWriting
.
According to the documentation of
-[AVAssetWriterInput appendSampleBuffer:]
method:So, basically you are in the situation #3:
5s
, based on the PTS different between first and second sample5s
too, becausethe duration of the second-to-last sample
was used