在设备上导出时 AVAssetExportSession 缺少音轨
我在模拟器上运行导出,一切正常。我在设备上运行它,视频被导出,但没有音频。这让我相信我一定使用了设备不支持但 OS X 支持的音频格式,因为模拟器使用 OS X 使用的音频格式。我尝试过 m4a、aiff 和 aifc,但没有成功!有什么想法吗?
I run the export on the simulator and everything works great. I run it on the device and the video gets exported but there's no audio. This leads me to believe that I must be using an audio format that the device doesn't support but OS X does, as the simulator uses what OS X uses. I've tried m4a, aiff, and aifc and have had no luck! Any ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有一个非常相似的问题。这似乎与编解码器无关,因为我制作了一个单独的测试用例,可以在同一视频上正常运行。有一个相关问题,指出问题可能出在使用
MPMoviePlayerController
播放相同资源时。这让我走上了正确的道路(某种程度上)。就我而言,问题源于在导出期间使用
AVPlayer
中的资源。我无法找到导致导出丢失音轨的确切组合 - 在单独的测试项目中,即使资产同时在AVPlayer
中播放,导出也运行良好。经过几个小时的尝试找到确切原因后,我放弃了,只是在导出过程中使用replaceCurrentItemWithPlayerItem:nil
将资产从播放器中弹出。这是一个黑客,但它有效。AVFoundation 是一个非常强大的框架,但上帝我希望它不要那么挑剔,或者至少记录更多错误,而不是默默地产生垃圾。
I have a very similar problem. It does not seem to do with codecs, as I made a separate test case that runs fine with the same video. There’s a related question that says the problem might be in playing the same assets using
MPMoviePlayerController
. That got me on the right track (sort of).In my case the trouble stem from using the assets in an
AVPlayer
during the export. I was not able to find the exact combination that causes the export to drop the audio track – in the separate test project the export runs fine even though the asset plays inAVPlayer
at the same time. After several hours of trying to find the exact cause I gave up and simply popped the asset out of the player usingreplaceCurrentItemWithPlayerItem:nil
during export. It’s a hack, but it works.AVFoundation
is a very powerful framework, but God I wish it wasn’t so finicky or at least logged more errors instead of silently producing garbage.