简体   繁体   中英

How to write a custom udta atom with AVAssetWriter?

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM