使用AVFoundation修改音频元数据

non*_*ive 5 cocoa metadata objective-c avfoundation avassetwriter

我正在开发一个需要修改音频文件元数据的应用程序.我玩过Apple的官方演示AVReaderWriterOSX.我试图设置的元数据AVAssetWriterInputAVAssetWriter,但我仍然不能使它工作,将元数据写入到输出文件.有没有人有这方面的例子?

先感谢您.

non*_*ive 6

我想我找到了解决方案.最简单的解决方案是使用AVAssetExportSession.

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
    initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
exportSession.outputURL = ...;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.timeRange = CMTimeRangeMake(startTime, duration);
exportSession.metadata = ...;
[exportSession exportAsynchronouslyWithCompletionHandler:handlerBlock];
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用"AVAssetExportPresetPassthrough"预设,则这是无损转换. (3认同)