I have been banging my head against the wall for days trying to find any solution that will allow me to write arbitrary metadata into an MP4 using AVFoundation. Both AVAssetWriter and AVAssetExportSession have metadata API that look for all to see like they should do the trick of writing metadata, but having tried and tried again to add metadata via these APIs, the metadata is never written. Are they any examples of actually successfully writing metadata to an MP4 with AVFoundation?
Here's an example that seems like it should work, but doesn't:
And this doesn't work either:
Here's an example that seems like it should work, but doesn't:
Code Block swift let myMetadata = AVMutableMetadataItem() myMetadata.identifier = AVMetadataIdentifier(rawValue: "udta/GPMF") myMetadata.value = "Yo, dawg, I'm metadata" as NSString myMetadata.dataType = kCMMetadataBaseDataType_RawData as String exporter?.metadata = [myMetadata] // export.exportAsynchronously()...
And this doesn't work either:
Code Block swift let foo = AVMutableMetadataItem() foo.value = gpmf.dataValue! as NSData // this is copying data directly from AVMetadataItem taken from an AVAsset I have which already has metadata assetWriter.metadata = [foo] assetWriter.startWriting() // assetWriter.finishWriting