How to change MediaCodec encoding bitrate on the f

2019-02-20 00:38发布

I want to change the encoding bitrate including H264 and AAC by Android MediaCodec dynamically , according to the current network.

How to update the encoding bitrate in Android MediaCodec dynamically ?

PS: I found PARAMETER_KEY_VIDEO_BITRATE and setParameters is available on API 19

PARAMETER_KEY_VIDEO_BITRATE

Change a video encoder's target bitrate on the fly. The value is an Integer object containing the new bitrate in bps.

Constant Value: "video-bitrate"

setParameters

Communicate additional parameter changes to the component instance.

Throws IllegalStateException if in the Uninitialized state.

Is there any way to do it under API 19 ?

2条回答
闹够了就滚
2楼-- · 2019-02-20 01:06

Your format needs to support adaptive bitrate. Eg. I was able to set the bitrate using the following. Make sure you're in api 19 or above though.I was encoding the H264 frames into an FLV container.

Bundle bitrate = new Bundle(); bitrate.putInt(MediaCodec.PARAMETER_KEY_VIDEO_BITRATE, targetBitrate); mEncoder.setParameters(bitrate);

查看更多
走好不送
3楼-- · 2019-02-20 01:08

Stopping the Codec, setting the parameters and restarting it worked for me.

查看更多
登录 后发表回答