包大小有限的 Android MediaProjection

问题描述

我通过 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...