AVAssetWriter error -12743 appending HDR Metadata

It seems AVAssetWriter is rejecting CVPixelBuffers with error -12743 when appending NSData for kCVImageBufferAmbientViewingEnvironmentKey for HDR videos.

Here is my code:

 var ambientViewingEnvironment:CMFormatDescription.Extensions.Value?
    var ambientViewingEnvironmentData:NSData?
     ambientViewingEnvironment = sampleBuffer.formatDescription?.extensions[.ambientViewingEnvironment]
     let plist = ambientViewingEnvironment?.propertyListRepresentation
       ambientViewingEnvironmentData = plist as? NSData
And then attaching this data,
   CVBufferSetAttachment(dstPixelBuffer, kCVImageBufferAmbientViewingEnvironmentKey, ambientViewingEnvironmentData! as CFData, .shouldPropagate)

No matter what I do, including copying the attachment from sourcePixelBuffer to destinationPixelBuffer as it is, the error remains!

      var attachmentMode:CVAttachmentMode = .shouldPropagate
                    let attachment = CVBufferCopyAttachment(sourcePixelBuffer!, kCVImageBufferAmbientViewingEnvironmentKey, &attachmentMode)
                    NSLog("Attachment \(attachment!), mode \(attachmentMode)")
                    CVBufferSetAttachment(dstPixelBuffer, kCVImageBufferAmbientViewingEnvironmentKey, attachment!, attachmentMode)

I need to know if there is anything wrong in the way metadata is copied.

Replies

Why the propertyListRepresentation? The kCVImageBufferAmbientViewingEnvironmentKey should be in the binary format defined in ITU-T H.274. So you should get the data directly as is and pass it to new buffer, a plist won't work.

  • The plist itself is type CFData in this case. Nothing works as I said, including the second code sample I posted in the question where I simply copy and paste the attachment from source sample buffer. Feel free to modify and post the sample code you think should work.

Add a Comment

@galad87 The plist itself is type CFData in this case. Nothing works as I said, including the second code sample I posted in the question where I simply copy and paste the attachment from source sample buffer. Feel free to modify and post the sample code you think should work.