本文介绍了AVMutableCompositionTrack - insertTimeRange - insertEmptyTimeRange问​​题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题:我想生成一个新的声音文件了两次声音文件和沉默

I have a strange problem: I want to generate a new sound file out of two soundfiles and silence.

Sound1例子:2秒长
+
沉默:2秒沉默
+
SOUND2:2秒长

sound1: 2 seconds long+silence: 2 seconds silence+sound2: 2 seconds long

当我尝试下面的code,我得到6秒长音效档的所有部分,但是以不同的顺序!顺序是:Sound1例子,SOUND2,沉默

When I try the code below, I get a 6 seconds long soundfile with all the parts, but in a different order! The order is: sound1, sound2, silence

我不能够把这种沉默在这个结构的中间(也没有开头)。这是一个典型的行为或者我是否出错了?

I am not able to put this silence in the middle of this composition (also not at the beginning). Is this a typical behavior or do I something wrong?

下面是code为把段一起:

Here is the code for putting the segments together:

[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio1 duration])  ofTrack:clipAudioTrack1 atTime:kCMTimeZero error:nil];
[compositionAudioTrack insertEmptyTimeRange:CMTimeRangeMake(kCMTimeZero, CMTimeMake(2, 1))];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio2 duration])  ofTrack:clipAudioTrack2 atTime:CMTimeMake(4, 1) error:nil];

也许有人有一个想法?谢谢你在前进!

Perhaps someone has an idea? Thank you in advance!

顺便说一下:以下code,而不insertEmptyTimeRange行也不管用,它只是产生4秒声SOUND2幻灯片来Sound1例子的末尾:

By the way: following code without the insertEmptyTimeRange-line doesn't work either, it just generates 4 seconds of sound and sound2 slides to the end of sound1:

    [compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio1 duration])  ofTrack:clipAudioTrack1 atTime:kCMTimeZero error:nil];
[compositionAudioTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, [audio2 duration])  ofTrack:clipAudioTrack2 atTime:CMTimeMake(4, 1) error:nil];

看来,这是不允许的,有无段之间!?

It seems that it is not allowed that there is "nothing" between segments!?

推荐答案

还是不知道这是什么insertEmptyTimeRange的意思。我做了一个变通与无关,在它是沉默 - 音频文件。我把两个声音文件之间的空音频文件,这样做对我来说。问题已关闭;)
(但是,如果有人可以解释这个insertEmptyTimeRange这将是有趣还是...)

Still don't know what this "insertEmptyTimeRange" means. I made a work around with a "silence"-audio file which has nothing in it. I put this empty audio file between the two sound files and this does it for me. Question closed ;)(But if someone could explain this "insertEmptyTimeRange" this would be still interesting...)

这篇关于AVMutableCompositionTrack - insertTimeRange - insertEmptyTimeRange问​​题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-23 16:18