I'm using AVAssetWriter
on iOS 9.3 SDK to write an AAC packaged in MP4 container. Pretty standard stuff. It is working well.
However, now I need to add an atom contained in the udta
atom (called mine
for this example), so I have done this:
AVAssetWriter * writer =....
NSData * valueData = [NSJSONSerialization dataWithJSONObject:obj options:0 error:nil];
AVMutableMetadataItem * item = [AVMutableMetadataItem metadataItem];
item.keySpace = AVMetadataKeySpaceQuickTimeUserData; //udta
item.key = @"mine";
item.value = valueData;
writer.metadata = @[item];
[writer startWriting];
...
And then in the end, the udta atom doesn't appear at all in the output file. What is going wrong here?
Finally found the issue. If you create your asset writer in the pure MP4 (AVFileTypeMPEG4
) mode, then custom metadata seems to be dropped on the floor silently. The solution is to use the QuickTime container file type:
AVAssetWriter * writer = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeQuickTimeMovie error:nil];