完整代码:https://github.com/wuqingsen/AVWuDemo
目录:Android音视频整理
package com.demo.audiowudemo.util;
import android.annotation.SuppressLint;
import android.media.AudioFormat;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.media.MediaRecorder;
import android.util.Log;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.ArrayList;
/**
* wuqingsen on 2020-05-28
* Mailbox:1243411677@qq.com
* annotation:pcm转aac
*/
@SuppressLint("NewApi")
public class PCMToAAC {
private String encodeType = MediaFormat.MIMETYPE_AUDIO_AAC;
private static final int samples_per_frame = 2048;
private MediaCodec mediaEncode;
private MediaCodec.BufferInfo encodeBufferInfo;
private ByteBuffer[] encodeInputBuffers;
private ByteBuffer[] encodeOutputBuffers;
private byte[] chunkAudio = new byte[0];
private BufferedOutputStream out;
File aacFile;
File pcmFile;
public PCMToAAC(String aacPath, String pcmPath) {
aacFile =