vic Vic
vic Vic

Reputation: 43

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. 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? How can I use Vivo X5 Pro(android 5.0, API 21) to encode a normal data size? 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.

Upvotes: 1

Views: 892

Answers (1)

mstorsjo
mstorsjo

Reputation: 13317

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.

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.)

Upvotes: 1

Related Questions