Reputation: 31
I'm trying to use AVAssetExportSession
to set the metadata of a AVFileTypeMPEG4
type file,but it
doesn't work,if I change the file type to AVFileTypeQuickTimeMovie
,it works.But I need mp4 file,I can't find any document say AVFileTypeMPEG4
file can not be set metadata,Has anyone set meta successfully?
Here is the code that I used:
NSMutableArray *metadata = [NSMutableArray array];
AVMutableMetadataItem *metaItem = [AVMutableMetadataItem metadataItem];
metaItem.key = AVMetadataCommonKeySource;
metaItem.keySpace = AVMetadataKeySpaceCommon;
metaItem.value = @"Test metadata";
[metadata addObject:metaItem];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:composition presetName:AVAssetExportPresetMediumQuality];
exportSession.metadata = metadata;
exportSession.audioMix = audioMix;
exportSession.videoComposition = videoComposition;
exportSession.outputFileType = AVFileTypeMPEG4;//AVFileTypeQuickTimeMovie;
NSString *outputFilePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"testMetadata.mp4"];
exportSession.outputURL = [NSURL fileURLWithPath:outputFilePath];
[exportSession exportAsynchronouslyWithCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
//todo
}else{
//todo
}
});
}];
Upvotes: 3
Views: 2190
Reputation: 2585
Apple filters metadata depending on the output type. They don't consider iTunes metadata valid for MPEG4 output, so they strip it.
Some options:
Use AVFileTypeQuickTimeMovie > MOV is closely related to MP4, and is often compatible. This depends on what you are looking to do.
Try other types (some people report success with the MPV type)
use a library to write custom data/atoms (mp4v2 works for example). Lots of work, but the only real way to achieve it.
Upvotes: 1
Reputation: 11
Try it with
metaItem.key = AVMetadataiTunesMetadataKeyDescription; metaItem.keySpace = AVMetadataKeySpaceiTunes;
tried the other keyspaces but only itunes worked for me.
Upvotes: 1