- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到的问题是在两个 wav 文件之间放置可变数量的静音。
到目前为止,我的方法如下:
首先我创建了一个 AVMutableComposition
和一个 AVMutableCompositionTrack
AVMutableComposition* composition = [AVMutableComposition composition];
AVMutableCompositionTrack* appendedAudioTrack =
[composition addMutableTrackWithMediaType:AVMediaTypeAudio
preferredTrackID:kCMPersistentTrackID_Invalid];
AVURLAsset
我分配了我方便命名的 first.wav 文件。
AVURLAsset* firstComponent = [[AVURLAsset alloc]
initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"first" ofType: @"wav"]] options:nil];
appendedAudioTrack
的可变组合轨道中早些时候
NSArray *firstTrack = [firstComponent tracksWithMediaType:AVMediaTypeAudio];
CMTimeRange timeRange = CMTimeRangeMake(kCMTimeZero, firstComponent.duration);
[appendedAudioTrack insertTimeRange:timeRange
ofTrack:[firstTrack objectAtIndex:0]
atTime:kCMTimeZero
error:&error];
AVURLAsset* secondComponent = [[AVURLAsset alloc]
initWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: @"second" ofType: @"wav"]] options:nil];
NSArray *secondTrack = [secondComponent tracksWithMediaType:AVMediaTypeAudio];
CMTimeRange timeRange2 = CMTimeRangeMake(kCMTimeZero, secondComponent.duration);
[appendedAudioTrack insertTimeRange:timeRange2
ofTrack:[secondTrack objectAtIndex:0]
atTime:kCMTimeZero
error:&error];
insertEmptyTimeRange
插入可变数量的静音像这样:
CMTimeRange timeRange3 = CMTimeRangeFromTimeToTime(firstComponent.duration,CMTimeAdd(firstComponent.duration,CMTimeMake(interval,1)));
[appendedAudioTrack insertEmptyTimeRange:timeRange3];
float
出于测试目的,目前为 0.49。它的变量名是
interval
它以秒为单位表示所需的静音。
CMTimeRange
所做的假设是
AVURLAsset
的持续时间属性可以认为是结束
CMTime
对于第一个音轨。
// Create a new audio file using the appendedAudioTrack
AVAssetExportSession* exportSession = [AVAssetExportSession
exportSessionWithAsset:composition
presetName:AVAssetExportPresetAppleM4A];
if (!exportSession)
{
// do something
return nil;
}
//This gives me an output URL to a file name that doesn't yet exist
NSString *path2;
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path2 = [paths2 objectAtIndex:0];
path2 = [path2 stringByAppendingPathComponent:[string stringByAppendingString: @".m4a"]];
NSString* appendedAudioPath= path2;
exportSession.outputURL = [NSURL fileURLWithPath:appendedAudioPath];
exportSession.outputFileType = AVFileTypeAppleM4A;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
switch (exportSession.status)
{
case AVAssetExportSessionStatusFailed:
NSLog(@"%@",exportSession.error);
break;
case AVAssetExportSessionStatusCompleted:
break;
case AVAssetExportSessionStatusWaiting:
break;
default:
break;
}
最佳答案
事实证明,间隔的持续时间不正确,当检查 audacity 时,它实际上是 0.049,而不是 0.49。
我遇到的问题是这个
CMTimeMake(interval,1)
interval/1
秒,但我错了。
CMTimeMakeWithSeconds
连同
NSEC_PER_SEC
像这样
CMTimeRange timeRange3 = CMTimeRangeFromTimeToTime(firstComponent.duration,CMTimeAdd(firstComponent.duration,CMTimeMakeWithSeconds(interval ,NSEC_PER_SEC)));
[appendedAudioTrack insertEmptyTimeRange:timeRange3];
interval
秒长,并且在正确的位置。
关于ios - AVMutableCompositionTrack - 使用 insertEmptyTimeRange 在两个 WAV 文件之间插入静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25099671/
将录制的视频和资源中的音频混合时,无法设置音频音量。 这是我的代码: AVMutableComposition *composition = [[AVMutableComposition alloc]
我有两个音轨,我可以像这样相互组合: AVMutableComposition *composition = [[AVMutableComposition alloc] init]; AVMutabl
我尝试将.mp3-文件添加到AVMutableCompositionTrack,然后再导出新文件。问题是:导出后,生成的文件存在,但为空,无法播放。有人在我的代码中看到错误了吗? AVMutableC
在我的应用程序中,我需要合并音频和视频,然后我需要在 Mediaplayer 中播放音频文件。如何在 IOS 中合并音频和视频。有没有这方面的源代码。请给我一些建议 提前致谢 最佳答案 使用这个 AV
我有一个奇怪的问题:我想用两个声音文件和静音生成一个新的声音文件。 声音1:2秒长+静音:2秒静音+sound2:2秒长 当我尝试下面的代码时,我得到了一个 6 秒长的声音文件,其中包含所有部分,但顺
我正在尝试放置我正在创建的视频的一部分的一些文本。我意识到我可以使用 CALayers 在整个视频长度上使用带有文本的图层,但如何仅在视频的一部分上执行此操作?经过一些研究,我发现您可以创建 AVMe
我创建了一个包含多个视频剪辑的合成,我还添加了一些空白范围,用于显示带有 CoreAnimation 的标题屏幕。 |--Video1--|--NoVideo(AVsyncLayer)--|--Vid
我正在开发一款简单的视频编辑应用。我想在我的应用程序中添加慢动作。我注意到 AVMutableCompositionTrack 类中有一个 scaleTimeRange 方法,因此我使用它来实现我的目
感谢阅读我的问题。 :D 这是我的问题 我正在使用 AVAudioRecorder 将音频文件录制为声乐资源,目的是在不同时间将声乐插入我的视频中。但是当我将人声插入我的人声轨道(AVMutableC
我遇到的问题是在两个 wav 文件之间放置可变数量的静音。 到目前为止,我的方法如下: 首先我创建了一个 AVMutableComposition和一个 AVMutableCompositionTra
从最近 2 天开始,我一直在为 AVMutableCompositionTrack 挠头,在我的例子中,它拍摄的是纵向视频,但在添加水印后它变成了横向。 这是我的代码: AVURLAsset* vid
调用时有时会出现如下错误 - (BOOL)insertTimeRange:(CMTimeRange)timeRange ofTrack:(AVAssetTrack *)track atTime:(CM
下面的代码使用 AVMutableComposition 导出视频。但是在导出的视频中,如果您希望图像在源视频结束后显示 3 秒,有没有办法使用 AVMutableCompositionTrack 来
首先我必须说我喜欢这个论坛,它帮助了我很多时间。我有一个问题,但我在任何地方都找不到答案,所以这是我在这里的第一个问题。 我的问题是: 我有一个由 AVPlayerItem 表示的视频,用户可以使用将
我是一名优秀的程序员,十分优秀!