简体   繁体   English

MediaCodec:MediaFormat KEY_I_FRAME_INTERVAL不适用于H264codec

[英]MediaCodec: MediaFormat KEY_I_FRAME_INTERVAL not working for H264codec

I'm setting MediaFormat.KEY_I_FRAME_INTERVAL value as 1 (below given code) but it's not generating Key frame every second but it is generating every 66 second. 我将MediaFormat.KEY_I_FRAME_INTERVAL值设置为1(在给定代码下方),但是它不会每秒生成关键帧,而是每66秒生成一次。 I'm using Libstreaming library. 我正在使用Libstreaming库。 can anyone please help why is not working ? 谁能帮忙为什么不起作用?

mMediaCodec = MediaCodec.createByCodecName(debugger.getEncoderName());
  MediaFormat mediaFormat =MediaFormat.createVideoFormat("video/avc",
               640,480);
        mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 1000000);
        mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 15);
        mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT,
                debugger.getEncoderColorFormat());
        mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 1); //here
        mMediaCodec.configure(mediaFormat, null, null,
                MediaCodec.CONFIGURE_FLAG_ENCODE);
        mMediaCodec.start();

Are you sure that the timestamps of your input buffers are in the proper unit (microseconds), and that you on average feed 15 frames per second? 您确定输入缓冲区的时间戳以正确的单位(微秒)为单位,并且平均每秒进给15帧吗? Timestamps in the wrong unit is probably the most common cause for this. 错误单位中的时间戳可能是最常见的原因。 That would also cause the bitrate of the output stream to be way off what you requested. 这也将导致输出流的比特率偏离您的要求。

If you raise MediaFormat.KEY_I_FRAME_INTERVAL to 2 instead of 1, does the keyframe interval raise to 132 seconds from 66? 如果将MediaFormat.KEY_I_FRAME_INTERVAL提高到2,而不是1,关键帧间隔是否从66提高到132秒? That would indicate an unit error. 那将指示一个单位错误。 If it doesn't react at all, it would indicate that the encoder simply doesn't honor this parameter. 如果它完全不响应,则表明编码器根本不接受该参数。

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

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