Я использую фреймворк iOS AVFoundation, и я могу успешно объединять видеодорожки с наложением изображений и текстовыми оверлеями. Однако мой выходной файл не сохраняет аудио в исходном исходном видео.
Как я могу убедиться, что источник звука из одного из моих видео остается с новым созданным мной видео?
ИЗМЕНИТЬ
* Используйте этот код, чтобы иметь хороший пример того, как выполнить это создание видео (с оригинальным аудио). Для меня не было очевидно, что мне нужно включать звуковую дорожку отдельно при обработке видео с помощью AVFoundation. Надеюсь, это поможет кому-то еще.
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];
}