gpt4 book ai didi

iphone - 使用 AVAssetWriter 在 iPhone 上创建 MPEG-2 或 AAC ADTS

转载 作者:行者123 更新时间:2023-11-29 05:01:14 25 4
gpt4 key购买 nike

是否可以使用 AVAssetWriter 在 ios 上编写 MPEG2 ADTS 或 AAC ADTS?

首先我制作一个 AVAssetWriter

assetWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:filePath]
fileType:AVFileTypeCoreAudioFormat
error:&er];

然后我使用我怀疑正​​确的设置进行输入,并尝试将其添加到编写器,但无济于事:

AudioChannelLayout channelLayout;
memset(&channelLayout, 0, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
NSDictionary *outputSettings =
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatMPEGLayer2], AVFormatIDKey,
[NSNumber numberWithFloat:44100.0], AVSampleRateKey,
[NSNumber numberWithInt:2], AVNumberOfChannelsKey,
[NSNumber numberWithInt:128000], AVEncoderBitRateKey,
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
nil];

assetWriterInput = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeAudio
outputSettings:outputSettings];
assetWriterInput.expectsMediaDataInRealTime = NO;

if ([assetWriter canAddInput:assetWriterInput]) {
[assetWriter addInput:assetWriterInput];
} else {
NSLog (@"can't add asset writer input.");
}

最佳答案

这是我的 aac 工作设置

AudioChannelLayout channelLayout;
memset(&channelLayout, 0, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;

AVAssetWriter *assetWriter = [[AVAssetWriter assetWriterWithURL:exportURL
fileType:AVFileTypeMPEG4

error:&assetError] retain];

NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[ NSNumber numberWithInt: 2 ], AVNumberOfChannelsKey,
[ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
[NSData dataWithBytes:&channelLayout length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,
[ NSNumber numberWithInt: 128000 ], AVEncoderBitRateKey,nil];

关于iphone - 使用 AVAssetWriter 在 iPhone 上创建 MPEG-2 或 AAC ADTS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6892961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com