Search code examples
iosobjective-ciphonemp3audio-streaming

How to lower the bitrate of mp3 in iOS?


I made a Multipeer Audio Streaming app using the Tony's tutorial. But I can only play .mp3 with 128kbps bit rate. So I need to lower .mp3 with 192kbps or more bit rate to 128kbps. I found a similar solution[here], but it's for encoding mp3 to video.

Please help me how to lower the bitrate.


Solution

  • AVAssetReaderTrackOutput *assetOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:asset.tracks[0] outputSettings:nil];  
    

    You should provide outputSettings: on a server side (phone that streams audio)

    So it should look like this.

    NSDictionary *settings = @{
        AVEncoderBitRateKey : @128000,
        AVFormatIDKey : @(kAudioFormatAppleIMA4),
        AVNumberOfChannelsKey : @2,
        AVLinearPCMBitDepthKey : @16,
        AVLinearPCMIsBigEndianKey : @NO,
        AVLinearPCMIsFloatKey : @NO
    };
    AVAssetReaderTrackOutput *assetOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:asset.tracks[0] outputSettings:settings];