AVAssetWriter failed on macOS 12.0.01/iOS15.1.1 with error code -11800 and underlying code -17771

Hi there,

I used AVAssetWriter to export mp4 file, input audio and video samples are encoded data (aac and h264 samples), sometimes it works well, but sometime it will failed randomly with error code -11800 and underlying code -17771 after calling finishWritingWithCompletionHandler, log looks like this:

 AVAssetWriter status: Failed, status:err:Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-17771), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x60400008e1d0 {Error Domain=NSOSStatusErrorDomain Code=-17771 "(null)"}}, status=3

And I notice these logs on Console.app just before the error message:

default	17:35:08.380220+0800	MyAPP	<<<< FigExportCommmon >>>> remakerFamily_formatWriterErrorOccurred: (0x6140001ba240)
default	17:35:08.380561+0800	MyAPP	<<<< FigExportCommmon >>>> remakerFamily_PostFailureNotificationIfError: (0x6140001ba240) state finish writing called
default	17:35:08.381010+0800	MyAPP	<<<< FigExportCommmon >>>> remakerfamily_setFailureStatusIfError: (0x6140001ba240) err -17771 state finish writing called

I don't know why this will happen, any replies are appreciate. thx.

Post not yet marked as solved Up vote post of JoeyBlue Down vote post of JoeyBlue
901 views
  • I have tried: 1.both the pull style and push style API, neither works well. I use serial NSOperationQueue to make sure all writer operation be serial in push sytle, doesn't help too 2._writer.shouldOptimizeForNetworkUse set to be YES or NO, neither helps. When YES is set, there's no file after finishing writing, when NO is set, there's a mp4 file without moov atom, only 'ftyp', 'wide' and a broken 'mdat' atom exist

Add a Comment

Replies

Please file a report so we can take a look at what is going on. Ideally you could attach a project that we can build and run to reproduce the problem.

  • Thanks for you reply. I found the solution yestoday, after giving duration value for every video frame's CMSampleTimingInfo struct, this problem disappeared.

    I put the code in another reply

Add a Comment

Thanks for you reply. I found the solution yestoday, after giving duration value for every video frame's CMSampleTimingInfo struct, this problem disappeared.

///// Code with Problem

 CMSampleTimingInfo timingInfo;
 timingInfo.presentationTimeStamp = CMTimeMake(pts_ms, 1000);
 timingInfo.decodeTimeStamp = CMTimeMake(dts_ms, 1000);

 size_t sampleSize[1] = { frame_size };

 CMSampleBufferRef sampleBuffer;
 status = CMSampleBufferCreate(kCFAllocatorDefault,
                dataBlock,
                true, // dataReady
                NULL, // makeDataReadyCallback
                NULL, // makeDataReadyRefcon
                _videoFormatDescription,
                1, // numSamples
                1, // numSampleTimingEntries
                &timingInfo, // CMSampleTimingInfo *sampleTimingArray
                1, // numSampleSizeEntries
                sampleSize, // sampleSizeArray
                &sampleBuffer); //sampleBufferOut

///// Code without Problem

 CMSampleTimingInfo timingInfo;
 timingInfo.presentationTimeStamp = CMTimeMake(pts_ms, 1000);
 timingInfo.decodeTimeStamp = CMTimeMake(dts_ms, 1000);

// ⬇️⬇️⬇️
timingInfo.duration = CMTimeMake(duration, 1000)

 size_t sampleSize[1] = { frame_size };

 CMSampleBufferRef sampleBuffer;
 status = CMSampleBufferCreate(kCFAllocatorDefault,
                dataBlock,
                true, // dataReady
                NULL, // makeDataReadyCallback
                NULL, // makeDataReadyRefcon
                _videoFormatDescription,
                1, // numSamples
                1, // numSampleTimingEntries
                &timingInfo, // CMSampleTimingInfo *sampleTimingArray
                1, // numSampleSizeEntries
                sampleSize, // sampleSizeArray
                &sampleBuffer); //sampleBufferOut
  • I'm happy to hear that you found the solution. If you have a spare moment, could you still raise a report for the fact that AVAssetWriter is giving you an unhelpful error message?

  • I've seen this error pop up for a handful of users in the past year, and I've looked and I see that the sample buffers I am handing to AVAssetWriter also have no duration. It's working well over 99% of the time, so there's some smaaaall edge case that must be occurring. As far as I understand, there's no requirement to ever specify the duration of a frame. @ Media Engineer can you shed some light on what the -17771 error means a bit more specifically?

Add a Comment