一、SPS和PPS文档说明
二、NALU类型
三、获取SPS、PPS两种方式
1、同步方式
ByteBuffer spsb = videoEncodec.getOutputFormat().getByteBuffer("csd-0");
byte[] sps = new byte[spsb.remaining()];
spsb.get(sps, 0, sps.length);
ByteBuffer ppsb = videoEncodec.getOutputFormat().getByteBuffer("csd-1");
byte[] pps = new byte[ppsb.remaining()];
ppsb.get(pps, 0, pps.length);
2、异步方式
@Override
public void onOutputFormatChanged(@NonNull MediaCodec codec, @NonNull MediaFormat format) {
MediaFormat outputFormat = codec.getOutputFormat();
SPS = outputFormat.getByteBuffer("csd-0").array();
PPS = outputFormat.getByteBuffer("csd-1").array();
Log.e(TAG," onOutputFormatChanged SPS "+ CommonUtils.byteToHex(SPS));
Log.e(TAG," onOutputFormatChanged PPS "+CommonUtils.byteToHex(PPS));
}
四、对应的sps、pps、I帧、P帧等数据
1、sps、pps
sps:000000016742ffffffc01effffffda05ffffffc145ffffff97ffffff8078402150
pps:0000000168ffffffce3cffffff80
2、I帧
data:0000000165ffffffb80010ffffffa413ffffffffffffffe5ffffffc3ffffffd31239695affffffabffffffb0340a
3、P帧
data:0000000161ffffffe9ffffffab13ffffffcd72ffffffdbffffffe5ffffffe25f5d7e64ffffff9ffffffff33affffffebffffffbd
总结:编码器编出来的数据首帧、sps、pps、I帧、P帧等顺序