Nitenq
Nitenq

Reputation: 193

AVAudioFile (Mac/iOS) : encode audio to constant bitrate AAC

I would like to encode audio buffers to M4A/AAC file using AVAudioFile. It works except that the output file is always AAC with a variable bitrate, even when I configure the AVAudioFile with specific constant bitrate flag.

Here is the code of AVAudioFile initialisation :

NSDictionary* outputSettings = @{
        AVFormatIDKey: [NSNumber numberWithUnsignedInt:kAudioFormatMPEG4AAC],
        AVNumberOfChannelsKey: [NSNumber numberWithInt:2],
        AVEncoderBitRateKey: [NSNumber numberWithInt:128000],
        AVEncoderBitRateStrategyKey: AVAudioBitRateStrategy_Constant /* should output constant bitrate AAC, but doesn't */
    };

AVAudioFile *outputFile = [[AVAudioFile alloc] initForWriting:outputURL
                                                     settings:outputSettings
                                                 commonFormat:AVAudioPCMFormatFloat32
                                                  interleaved:NO
                                                        error:&error];

Is constant bitrate AAC supported by AVAudioFile ? The documentation is not clear about that.

Upvotes: 2

Views: 223

Answers (0)

Related Questions