10

我正在尝试在 iOS7 下使用 AVAssetExportSession 合并 2 个 WAV 文件。我已经确认文件在那里并且似乎没有损坏或任何东西。这些是从设备本身录制的 WAV 文件,它们是相对较小的文件。

当它调用 exportAsync 方法时,它立即失败,并在完成块中立即出现“操作已停止”错误(原因描述为:“此媒体不支持该操作”)。这发生在模拟器和设备本身中。请参阅下面的我的导出代码:

NSError *avError = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
AVURLAsset *tmpAsset = [[AVURLAsset alloc] initWithURL:_tmpRecordingUrl options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @YES}];
AVURLAsset *permAsset = [[AVURLAsset alloc] initWithURL:_url options:@{AVURLAssetPreferPreciseDurationAndTimingKey: @YES}];
AVMutableComposition *composition = [AVMutableComposition composition];

[composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, permAsset.duration) ofAsset:permAsset atTime:kCMTimeZero error:&avError];
[composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, tmpAsset.duration) ofAsset:tmpAsset atTime:CMTimeMakeWithSeconds(_positionSlider.value, 1) error:&avError];

AVAssetExportSession *export = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetPassthrough];

if ([fileManager fileExistsAtPath:[_workingUrl path]]) {
    [fileManager removeItemAtURL:_workingUrl error:&avError];
}

export.outputFileType = AVFileTypeWAVE;
export.outputURL = _workingUrl;

[export exportAsynchronouslyWithCompletionHandler:^(void) {
    // fails
}];

我还确认“avError”永远不会被填充,因此插入 timeRanges 或创建导出会话似乎没有问题。我对资产进行了检查,它们都是可读的、可播放的和可导出的(根据 obj 上的布尔值)。

我在这里遗漏了一些明显的东西吗?此代码适用于 iOS6。如果我需要提供更多信息,请随时告诉我,并提前感谢您提供的任何指导!

编辑#1:我尝试添加跟踪机制,类似于这篇文章的内容:AVAssetExportSession - Join 2 mp4 files in IOS,但没有运气,同样的问题。另外,如果需要知道,当我从 WAV 切换到 CAF 时也会发生同样的错误。这是我supportedFileTypes在尝试使用任何音频类型格式时打印出的结果:

(
"com.apple.quicktime-movie",
"com.apple.m4a-audio",
"public.mpeg-4",
"com.apple.m4v-video",
"public.3gpp",
"org.3gpp.adaptive-multi-rate-audio",
"com.microsoft.waveform-audio",
"public.aiff-audio",
"public.aifc-audio",
"com.apple.coreaudio-format"
)

由于音频格式在那里,并且导出器为可导出、可播放和可读的两种资产返回 YES,我看不出它为什么会因此类错误而失败。

编辑#2:一些额外的信息——即使我将代码剥离到最低限度,只需从 NSURL 创建一个 AVAsset,然后使用 passthrough 预设将其提供给 AVAssetExportSession,它仍然在 iOS7 中失败。这里一定有我想念的东西。

我用视频(mp4)文件测试了这个相同的代码,它在 iOS7 中完美运行。我使用相同的代码并针对 WAV、CAF 和 M4A 文件进行了调整,但每次都失败并显示“此媒体不支持该操作”。错误。

这是Apple代码中的错误,还是我们甚至可以在iOS7中使用音频文件来做到这一点?我在 Apple 的“iOS7 中的新增功能”文档的 AV Foundation 部分中没有看到任何关于此的具体内容,而在 iOS6 中,这似乎工作正常。我可能会在这方面与苹果公司合作。

4

1 回答 1

7

I filed a TSI on this with Apple, and I received a response soon after:

Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have determined that you are experiencing a known bug for which there is no known workaround at this time.

They instructed me to go ahead and file a bug via bugreport.apple.com, so I did so. Hopefully they can get a fix in for it, as we have quite a bit of functionality residing on this.

My hopes are that this helps others save time on debugging pains with this if they run into it as well!

于 2014-01-30T23:07:57.187 回答