5

I'm working on an app which needs to modify metadata of audio files. I have played with Apple's official demo AVReaderWriterOSX. I have tried to set the metadata of AVAssetWriterInput and AVAssetWriter, but I still can't make it work to write metadata to the output file. Does anyone have any examples for this?

Thank you in advance.

nonamelive
  • 6,510
  • 8
  • 40
  • 47

1 Answers1

6

I think I have found the solution. The simplest solution is to use AVAssetExportSession.

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
    initWithAsset:asset presetName:AVAssetExportPresetMediumQuality];
exportSession.outputURL = ...;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
exportSession.timeRange = CMTimeRangeMake(startTime, duration);
exportSession.metadata = ...;
[exportSession exportAsynchronouslyWithCompletionHandler:handlerBlock];
nonamelive
  • 6,510
  • 8
  • 40
  • 47
  • 3
    It's a lossless conversion if you use the "AVAssetExportPresetPassthrough" preset. – nonamelive Jan 02 '12 at 15:44
  • Not sure if this is still the case as of Sept. 2016 for AVAssetWriter, but this is (still) a long-standing bug in AVFoundation for AVCaptureAudioFileOutput which also has a metadata property but only the title is written. Other keys like album name and artist name are not written. In order to get around this, you have to capture/write to a temporary file, then create an AVAssetExportSession (as above) to add in all the metadata. An export just to add metadata, when it should be supported during the original write. Such a waste. – Dalmazio Sep 17 '16 at 22:14