简体   繁体   English

如何使用 AVAssetWriter 编写自定义 udta 原子?

[英]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.我在 iOS 9.3 SDK 上使用AVAssetWriter编写打包在 MP4 容器中的 AAC。 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:但是,现在我需要添加一个包含在udta原子中的原子(在本例中称为mine的),所以我这样做了:

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.然后最后, udta 原子根本没有出现在输出文件中。 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.如果您在纯 MP4 ( AVFileTypeMPEG4 ) 模式下创建资产AVFileTypeMPEG4器,那么自定义元数据似乎会无声无息地丢在地板上。 The solution is to use the QuickTime container file type:解决方案是使用 QuickTime 容器文件类型:

AVAssetWriter * writer = [AVAssetWriter assetWriterWithURL:url fileType:AVFileTypeQuickTimeMovie error:nil];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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