.wav to any compressed form from AVAssetWritter ios

前端 未结 2 551
时光说笑
时光说笑 2021-02-06 18:01

Well the problem I am facing right now is a size issue problem. I am allowing the user to to choose a song from their library and then chop it up into pieces and then be able to

相关标签:
2条回答
  • 2021-02-06 18:39

    ANSWER

    This is the correct audio options for .m4a and if you want the user to see it as an .mp3 or .wav file just append those onto the end of the file name!

    AudioChannelLayout channelLayout;
    memset(&channelLayout, 0, sizeof(AudioChannelLayout));
    channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
    NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                                [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                [NSNumber numberWithInt:2], AVNumberOfChannelsKey,
                                [NSNumber numberWithInt:128000], AVEncoderBitRateKey,
                                [NSData dataWithBytes:&channelLayout    length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,                  
    
                                nil];    
    
    0 讨论(0)
  • 2021-02-06 18:39

    How about this (sorry for not trying it myself but it should get you closer):

    AVAssetWriter *assetWriter = [AVAssetWriter assetWriterWithURL:exportURL
                                                           fileType:AVFileTypeAppleM4A
                                                              error:&assetError];
    
    NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
           [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
           [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
           [NSNumber numberWithInt:2], AVNumberOfChannelsKey,
           [NSNumber numberWithInt:128000], AVEncoderBitRateKey,
           [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
           [NSNumber numberWithInt: AVAudioQualityHigh],  AVEncoderAudioQualityKey,
           nil];
    
    0 讨论(0)
提交回复
热议问题