在设备上导出时AVAssetExportSession缺少音轨 [英] AVAssetExportSession missing audio track when exporting on device

查看:262
本文介绍了在设备上导出时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??

推荐答案

我有一个非常相似的问题.它似乎与编解码器无关,因为我制作了一个单独的测试用例,可以很好地处理相同的视频.有一个相关问题,说明问题可能出在使用MPMoviePlayerController播放相同的资产.那使我走上了正确的轨道.

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).

在我的情况下,问题出在导出期间使用了AVPlayer中的资产.我无法找到导致导出丢失音轨的确切组合–在单独的测试项目中,即使资产同时在AVPlayer中播放,导出也可以正常运行.在尝试寻找确切原因几个小时之后,我放弃了,只是在导出过程中使用replaceCurrentItemWithPlayerItem:nil从播放器中弹出了资产.这是一种骇客,但行之有效.

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 in AVPlayer 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 using replaceCurrentItemWithPlayerItem:nil during export. It’s a hack, but it works.

AVFoundation是一个非常强大的框架,但是上帝,我希望它不是那么挑剔,或者至少记录了更多的错误,而不是无声地产生垃圾.

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.

这篇关于在设备上导出时AVAssetExportSession缺少音轨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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