How to set metadata for AVFileTypeMPEG4 file via AVAssetExportSession?

I'm trying to use AVAssetExportSession

to set the file type metadata AVFileTypeMPEG4

, but it doesn't work, if I change the file type to AVFileTypeQuickTimeMovie

, it works. But I need an mp4 file, I cannot find any document, say the AVFileTypeMPEG4

file cannot be set metadata. Has anyone installed the meta successfully? Here is the code 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
                }
            });
        }];

      

+3


source to share


2 answers


Try with

    metaItem.key = AVMetadataiTunesMetadataKeyDescription;
    metaItem.keySpace = AVMetadataKeySpaceiTunes;



tried other key areas but only itunes worked for me.

+1


source


Apple filters metadata based on the type of output. They don't think iTunes metadata is valid for MPEG4 output, so they split into it.

Some parameters:



  • Using AVFileTypeQuickTimeMovie> MOV is closely related to MP4 and often compatible. It depends what you are looking for.

  • Try other types (some report success with MPV type)

  • use a library to write custom data / atoms (like mp4v2). A lot of work, but the only real way to get it done.

+1


source







All Articles