2

All,

I am using MediaCodec class to generate video/avc video stream. stream encoding is fine but, I want to use B frames for better compression. Though I have set profile to AVCProfileHigh encoder is not generating B frames. Video stream has only I and P frames.

Below is media profile configuration.

mFormat.setInteger(MediaFormat.KEY_PROFILE, MediaCodecInfo.CodecProfileLevel.AVCProfileHigh);

Does MediaCoder support B Frames ?? If Yes, then hoe to configure the B frames.

sudhir kesti
  • 31
  • 1
  • 4

2 Answers2

6

This depends on the device. Android O and P briefly enabled B-frames automatically for AVC High profile encoding, but many apps started crashing as they did not expect out-of-order frames, so it got disabled shortly after launch. Also MediaMuxer failed on some stress streams with B-frames (e.g. if a B-frame is referring back from a frame over 1 second in the future). This is fixed in Android Q, though the back reference is still limited to 30 minutes.

Technically, apps can opt into getting B frames with MediaFormat.KEY_OUTPUT_REORDER_DEPTH format key (after setting high profile), but support for this in not required by devices, and is not hooked up in AOSP.

Lajos Molnar
  • 791
  • 6
  • 9
1

There is no guarantee that all devices will support it, but some devices might.

However, at least in earlier versions of Android, you had to set the level parameter at the same time, if you tried to set the profile parameter, otherwise it wouldn't be used. See https://stackoverflow.com/a/26293422/3115956 for more details about this. The thing with setting the level parameter is that you need to choose a level that is high enough to support the chosen resolution and frame rate.

mstorsjo
  • 12,983
  • 2
  • 39
  • 62