简体   繁体   English

MediaCodec编码数据太大

[英]MediaCodec encode data too big

I use MediaCodec to encode camera data, and when I use it on a device named Vivo X5 Pro(android 5.0, API 21),the data's size MediaCodec encoded is above 90000, and normally on other devices the size is about 15000.However I change the params of media format,it also dose't work. 我使用MediaCodec对摄像机数据进行编码,当我在名为Vivo X5 Pro(android 5.0,API 21)的设备上使用它时,MediaCodec编码的数据大小大于90000,通常在其他设备上约为15000。更改媒体格式的参数,也无效。 I also find that when I get the format with method MediaCodec.getOutputFormat() on Vivo X5 Pro(android 5.0, API 21),it has 7 data, one more than other normal case,it named "buffer-size" and value is 1048576,is this will influence the MediaCodec encode? 我还发现,当我在Vivo X5 Pro(android 5.0,API 21)上使用MediaCodec.getOutputFormat()方法获取格式时,它具有7个数据,比其他正常情况多一个数据,它名为“ buffer-size”,其值为1048576,这会影响MediaCodec编码吗? How can I use Vivo X5 Pro(android 5.0, API 21) to encode a normal data size? 如何使用Vivo X5 Pro(android 5.0,API 21)编码常规数据大小? Thank for help!!! 谢谢帮忙!!!

    MediaCodec mEncoder = MediaCodec.createEncoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
    MediaFormat format = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC, 320, 568);
    format.setInteger(MediaFormat.KEY_BIT_RATE, 320 * 568 * 2);
    format.setInteger(MediaFormat.KEY_FRAME_RATE, 20);
    format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1);
    format.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE, 320 * 568);

PS:However I change the params Vivo X5 Pro(android 5.0, API 21) encode data size still above 90000. PS:但是,我更改了参数Vivo X5 Pro(android 5.0,API 21)编码的数据大小仍然大于90000。

Make sure that you pass proper timestamps for the input frames, in the right unit (microseconds), otherwise the encoder can allocate too few/many bits per frame - see https://stackoverflow.com/a/20663056/3115956 for a longer explanation of this. 确保以正确的单位(微秒)为输入帧传递正确的时间戳,否则编码器可以为每个帧分配太少/很多位-请参阅https://stackoverflow.com/a/20663056/3115956以获得更长的时间对此的解释。

Have you tried lowering/raising the bitrate parameter to see if it actually changes the output size? 您是否尝试过降低/提高比特率参数以查看其是否实际上改变了输出大小? Otherwise the encoder might just be broken in the sense that it doesn't respect this parameter. 否则,编码器可能会因为不遵守该参数而被破坏。 (Also, the size of the first output packet might not totally reflect what the total average bitrate of the output stream is. So even if the first frame might be a bit too big, the later ones can potentially make up for it.) (此外,第一个输出数据包的大小可能无法完全反映输出流的总平均比特率。因此,即使第一个帧可能太大,后面的帧也有可能弥补它。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM