AVAssetWriter with non-constant frame rate

I'm trying to export a series of JPG images into a H264 movie (ideally it would be a motion JPEG movie, but unfortunately out AVAssetWriter

does not support this codec). The images originate from a professional surveillance camera with VFR (variable frame rate), hence I compute the CMTime

based on the time they have been captured, which results in a non-constant frame rate.


When I do this, the AVAssetWriter always fails to render the movie:


Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16364), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x604000245a90 {Error Domain=NSOSStatusErrorDomain Code=-16364 "(null)"}}


When I change the CMTime instances to be e.g.

CMMakeTime( frameIndex * 150, 600 )

it works, albeit resulting in a slightly wrong output.

Any idea how I could fix this? Is AVAssetWriter supposed to support that scenario?

Accepted Reply

-16364 means invalid timestamp. Asset Writer certainly supports variable frame rate video. Please double check your timestamps for consistency. Perhaps you're going backwards in time?

Replies

-16364 means invalid timestamp. Asset Writer certainly supports variable frame rate video. Please double check your timestamps for consistency. Perhaps you're going backwards in time?

Yay! Another check showed me that my time codes were indeed going backwards (off-by-one error, for the last image I computed 0 instead of the correct base value). The export works great now!


Thanks a lot, bford!

hello guys,
I am also facing this problem.
time of asset writer going backward but I don't know how to solve this problem can you help me.
Code Block
WARNING: Trouble appending pixel buffer at time: CMTime(value: 80, timescale: 600, flags: __C.CMTimeFlags(rawValue: 1), epoch: 0) Optional(Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16364), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x2828f7ed0 {Error Domain=NSOSStatusErrorDomain Code=-16364 "(null)"}})