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:
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:
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
Post
Replies
Boosts
Views
Activity
I am trying to build a tool to concatenate two MP4 videos while maintaining crucial metadata within. The metadata is in the source video both as header metadata and as a timecode track. I've been trying for starters to simply read a single MP4 using AVAsset and write that same video out using AVAssetExportSession and AVMutableComposition. I find that even though I add all tracks from the source asset to the composition and also set the export session's metadata to be equal to the source asset's metadata, if I read the result after exporting, I find that none of the header metadata is present, and the timecode track is also not present. How can I get these metadata pieces to be actually written out?