AVAssetWriterInput appendSampleBuffer failed with error -12780

I tried adding watermarks to the recorded video. Appending sample buffers using AVAssetWriterInput's append method fails and when I inspect the AVAssetWriter's error property, I get the following:

Error Domain=AVFoundation Error Domain Code=-11800 "This operation cannot be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDDescription=This operation cannot be completed, NSUnderlyingError=0x302399a70 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}}

As far as I can tell -11800 indicates an AVErrorUknown, however I have not been able to find information about the -12780 error code, which as far as I can tell is undocumented.

Thanks!

Answered by DTS Engineer in 821637022

Hello @HeYingJian,

Your issue stems from the topic mentioned in this TN3177: Understanding alternate audio track groups in movie files.

In short, iPhone 16 and iPhone 16 Pro can record a stereo and Spatial track for the same movie. It is incorrect to mix those tracks together. Your app is mixing them together with AVAssetReaderAudioMixOutput, and that is resulting in this issue.

-- Greg

Hello @HeYingJian,

Please provide a focused sample project that reproduces the error.

-- Greg

Hello @HeYingJian,

Your issue stems from the topic mentioned in this TN3177: Understanding alternate audio track groups in movie files.

In short, iPhone 16 and iPhone 16 Pro can record a stereo and Spatial track for the same movie. It is incorrect to mix those tracks together. Your app is mixing them together with AVAssetReaderAudioMixOutput, and that is resulting in this issue.

-- Greg

Can I solve this problem by changing AVAssetReaderAudioMixOutput to AVAssetReaderTrackOutput?

The important part to any solution here is to not mix the active and inactive audio tracks together. One way to do that is to write them to the destination asset as separate audio tracks (just as they are in the source asset).

You don't necessarily have to use AVAssetReaderTrackOutput, for example, you could use AVAssetReaderAudioMixOutput with just the active track. It's really up to you to decide what behavior you want your app to have here.

-- Greg

AVAssetWriterInput appendSampleBuffer failed with error -12780
 
 
Q