通过AVAssetExportSession将元数据添加到AAC M4A [英] Adding metadata to AAC M4A via AVAssetExportSession

查看:154
本文介绍了通过AVAssetExportSession将元数据添加到AAC M4A的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AVAudioRecorder创建和存储AAC编码的.m4a文件.这样就产生了一个可播放的.m4a文件.然后,我想使用AVAssetExportSession来处理文件,以便将元数据添加到文件中.下面的代码生成一个大小相似的.m4a文件(比源文件小1 KB),但是当播放时,只有静音.

I am creating and storing an AAC-encoded .m4a file using AVAudioRecorder. This produces a playable .m4a file just fine. I want to then use AVAssetExportSession to process the file in order to add metadata to the file. The below code is producing a .m4a file of a similar size (1 KB less than source), but when it plays back, there is just silence.

NSURL* url = [NSURL fileURLWithPath:self.m4aPath];
AVURLAsset* asset = [AVAsset assetWithURL:url];
AVMutableMetadataItem* t = [AVMutableMetadataItem metadataItem];
t.key = AVMetadataCommonKeyTitle;
t.keySpace = AVMetadataKeySpaceCommon;
t.value = @"Unit Test";
NSArray* metadata = [NSArray arrayWithObject:t];

AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetAppleM4A];

exportSession.outputURL = [NSURL fileURLWithPath:[[NSFileManager  rawRecordingsDirectory] stringByAppendingPathComponent:@"test.m4a"]];
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.metadata = metadata;

[exportSession exportAsynchronouslyWithCompletionHandler:^{....}];

更多信息:当我在Finder中查看源文件和导出文件时,源文件具有黑色iTunes图标,而导出文件具有白色iTunes图标.不确定这在实践中意味着什么,但希望它会有所帮助.此外,双击源将其添加到iTunes并开始播放,而双击导出的源将打开iTunes,但不执行任何操作.

One more piece of info: When I look at the source and exported file in the Finder, the source file has the black iTunes icon, while the exported file has the white iTunes icon. Not sure what this means in practice, but hoping it might be helpful. Moreover, double-clicking source adds it to iTunes and starts playback, while double-clicking the exported opens iTunes but does nothing.

推荐答案

我遇到了类似的问题,即我的输出m4a文件带有白色图标(而不是黑色)并且无法播放.尽管那是我从原始样本数据创建原始源文件的时间,而不是在向其添加元数据时.

I had a similar issue where my output m4a file had the white icon (instead of black) and wouldn't play. Though that was when I was creating the original source file from raw sample data, not when adding metadata to it.

我的问题是我没有关闭代码中的导出文件(我只是在调用close函数之前终止了应用程序).一旦我调用关闭函数,它便开始工作.您可能要检查一下.

My issue was that I wasn't closing the exported file in my code (I was just terminating the app before calling the close function). Once I called the close function, it started working. You might want to check that.

此外,我发现打开方式-> Quicktime"很有用,因为当文件损坏时会发出错误,而在文件未损坏时会很好地播放.比iTunes静默忽略该错误更有用.

Also, I found "open with->Quicktime" useful as that gives an error when the file is corrupt, and plays it fine when it isn't. More useful than iTunes silently ignoring the error.

这篇关于通过AVAssetExportSession将元数据添加到AAC M4A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆