ios - 如何通过 AVAssetExportSession 设置 AVFileTypeMPEG4 文件的元数据?

标签 ios avfoundation

我尝试使用 AVAssetExportSession 设置 AVFileTypeMPEG4 类型文件的元数据,但它 不起作用,如果我将文件类型更改为 AVFileTypeQuickTimeMovie,它就起作用。但是我需要 mp4 文件,我找不到任何文档说 AVFileTypeMPEG4 文件不能设置元数据,有人设置元成功吗? 这是我使用的代码:

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

最佳答案

尝试一下


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

尝试了其他键空间,但只有 itunes 对我有用。

关于ios - 如何通过 AVAssetExportSession 设置 AVFileTypeMPEG4 文件的元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26418627/

相关文章:

objective-c - 我应该把 removeObserver 放在 AppDelegate.m 的什么地方,ios

ios - 如何在集成绘图项目的情况下模拟 iOS 应用程序的位置

ios - AvFoundation - 如何连接 AVCaptureSession 和 AVAssetWriter?

iphone - SceneKit – AVPlayer Material 崩溃

swift - 我如何在另一个类中使用此扩展委托(delegate)更新我的 ViewController UI

ios - 在 Swift 3 中匹配和删除数组项

ios - 使用 Firebase 快速接收数据

ios - Swift:如何编写采用可选序列类型的枚举变体

ios - 如何在iOS应用中检测音频文件的BPM

ios - 选项类型 'String?' 的 AVFoundation 值未解包,应用程序崩溃,不会播放声音