问题描述
我通过 MediaProjection
直播 Android 屏幕,但仅限于最大 0xFFFF 字节 (65535) 的数据包
有没有办法限制输出缓冲区的大小?
我尝试更改比特率、帧率并检查所有设置,但找不到解决方案。
Bellow 是代码的一部分,其中 outputBuffer
需要限制为 0xFFFF
mediaProjection = mediaprojectionmanager.getMediaProjection(resultCode,resultData);
videoBufferInfo = new MediaCodec.BufferInfo();
mediaFormat = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC,width,height);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE,bitrate);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE,FPS);
mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT,0);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL,1);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
try {
encoder = MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
Bundle bitrateChange = new Bundle();
bitrateChange.putInt(MediaCodec.ParaMETER_KEY_VIDEO_BITRATE,bitrate);
this.encoder.setParameters(bitrateChange);
this.encoder.setCallback(new MediaCodec.Callback() {
@Override
public void onOutputBufferAvailable(MediaCodec codec,int outputBufferId,MediaCodec.BufferInfo info) {
ByteBuffer outputBuffer = codec.getoutputBuffer(outputBufferId);
// How to limit outputBuffer size to 0xFFFF?
}
//...
});
this.encoder.configure(mediaFormat,null // surface,null // crypto,MediaCodec.CONfigURE_FLAG_ENCODE);
inputSurface = encoder.createInputSurface();
encoder.start();
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)