开发者

AVAssetWriterInput output settings not rendering valid NSData

I am using AVAssetWriterInput to take an mp3 file from the user, and email it (DRM free only). I got the process to work when using PCM, but when I try mp3, or m4a, or caf, I either get a file that doesn't work, or I get empty data. I think it is due to my output settings. The output settings used that draw no data are below. I am open to changing all of it. Thanks!

    NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                [ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                [ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey,
                                开发者_开发问答[ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey,
                                [ NSData dataWithBytes: &channelLayout length: sizeof( AudioChannelLayout ) ], AVChannelLayoutKey,
                                [ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey,
                                nil];


Apple provides no API for writing mp3 files, perhaps because mp3 is just headerless packets and simply writing out the raw packets works fine.

As for writing out AAC data in m4a/caf containers, I'm not sure - but that AVEncoderBitRateKey should definitely not be there as you're not encoding anything - you're just passing data through. So why not forget about AVAssetWriter and use an AVAssetExportSession with a passthrough preset?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜