如何设置MediaCodec创建的编码器缓冲区大小 [英] How to set encoder buffer size created by MediaCodec

查看:523
本文介绍了如何设置MediaCodec创建的编码器缓冲区大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Nexus来测试Mediacodec API的编码.我可以看到编码器提供的inputBuffers为119040(通过记录inputBuffers.capacity).但是帧的大小(即输入)为460800.我在 inputBuffer.put 处收到错误消息,并出现了 buffer溢出.因此,我打算将输入缓冲区设置为460800.我可以找到的API是 BufferInfo.set .但是,我找不到将此设置附加到编码器的方法.有人可以帮忙吗?谢谢!!!

I am trying to use Nexus to test encoding with Mediacodec APIs. I can see the inputBuffers provided by the encoder is 119040 (by logging inputBuffers.capacity). But the size of the frame, i.e. input, is 460800. I got error message at inputBuffer.put with buffer overflow. So I was about to set the input buffer to 460800. The API I could find is BufferInfo.set. However, I cannot find a way to attach this setting to the encoder. Could someone help? Thanks!!!

encoder = MediaCodec.createByCodecName(codecInfo.getName());
ByteBuffer[] inputBuffers = encoder.getInputBuffers();
if (inputBufferIndex >= 0) {
    ByteBuffer inputBuffer = inputBuffers[inputBufferIndex];
    inputBuffer.clear();
    inputBuffer.put(input);
encoder.queueInputBuffer(inputBufferIndex, 0, input.length, 0, 0);}

推荐答案

我参加聚会很晚,但是基于:

I'm late to the party, but based on: Android MediaCodec Documentation I think the correct way to change the buffer will be to adjust the MAX_INPUT_SIZE, something like:

int width=800;
int height=480;
encoder = MediaCodec.createByCodecName(codecInfo.getName());
format = MediaFormat.createVideoFormat ("video/avc", width, height);
format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE,655360); // 0.5MB but adjust it as you need.

这篇关于如何设置MediaCodec创建的编码器缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆