iOS 9:AVFoundation导出会话缺少音频 [英] iOS 9 : AVFoundation Export Session is missing audio

查看:90
本文介绍了iOS 9:AVFoundation导出会话缺少音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将视频与原始音频合并时,我使用了以下代码.它一直有效,直到我升级到iOS9.任何人都面临同样的问题,任何解决的帮助将不胜感激.经过一整天的研究,我找不到任何东西.

I'm using the below code snipped while merging videos with original audio. It has been working until I upgraded to iOS9. Anyone faced the same issue and any help to resolve would be greatly appreciated. I couldn't find anything after researching whole day.

AVAssetTrack *videoTrack = nil;
AVAssetTrack *audioTrack = nil;
CMTime insertionPoint = kCMTimeZero;

if([[url tracksWithMediaType:AVMediaTypeVideo] count] != 0) {
    videoTrack = [url tracksWithMediaType:AVMediaTypeVideo][0];
}

if([[url tracksWithMediaType:AVMediaTypeAudio] count] != 0) {
    audioTrack = [url tracksWithMediaType:AVMediaTypeAudio][0];
}

// Insert the video and audio tracks from AVAsset
if (videoTrack != nil) {
    AVMutableCompositionTrack *compositionVideoTrack = [videoComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [url duration]) ofTrack:videoTrack atTime:insertionPoint error:&error];
}
if (audioTrack != nil) {
    AVMutableCompositionTrack *compositionAudioTrack = [videoComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
    [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [url duration]) ofTrack:audioTrack atTime:insertionPoint error:&error];
}

推荐答案

发现了问题: 我在上面的代码之后使用了下面的代码.删除后,它工作正常.下面的额外行删除了iOS 9中已经添加的音轨. 希望它对某人有帮助!

Found the issue: I have used the below after the above code. After removing this it worked fine. The below extra line removes the already added audio track in iOS 9. Hope it helps someone!

AVMutableCompositionTrack * compositionAudioTrack2 = [videoComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

AVMutableCompositionTrack *compositionAudioTrack2 = [videoComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];

这篇关于iOS 9:AVFoundation导出会话缺少音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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