# Class QMediaExtensions

- Defined in [File QMediaExtensions.java](https://docs.qualcomm.com/doc/80-56386-10/topic/api_file_api_mediacodec_extn_QMediaExtensionsjava.html#file-api-mediacodec-extn-qmediaextensions-java)

## Class Documentation[](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#class-documentation)

- class qti::video::QMediaExtensions[](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#_CPPv4N3qti5video16QMediaExtensionsE)

    - QTI\_MEDIACODEC\_EXTENSION\_VERSION 0.4.

QTI Mediacodec extension APIs encapsulates the video extensions available for Snapdragon devices. These extensions can be set on [MediaCodec](https://developer.android.com/reference/android/media/MediaCodec) object via [configure(..)](https://developer.android.com/reference/android/media/MediaCodec#configure%28android.media.MediaFormat,%20android.view.Surface,%20android.media.MediaCrypto,%20int%29) or [setParameters(..)](https://developer.android.com/reference/android/media/MediaCodec#setParameters%28android.os.Bundle%29) api.

The format of the media data is specified as key/value pairs. Keys are strings. Values can be integer, long, float, String or ByteBuffer.

All the extensions may not be supported on a device. it is imperative that the applications check the support of any extension by querying [MediaCodec.getSupportedVendorParameters(..)](https://developer.android.com/reference/android/media/MediaCodec#getSupportedVendorParameters%28%29) api

List of QTI MedicaCodec extension APIs:

| Name | Value Type | Description |
| --- | --- | --- |
| [KEY\_INIT\_QP\_I\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a77216c8ad5c8ea1ba570d0e1ea556488) | Integer | Enable override of initial QP for I frame |
| [KEY\_INIT\_QP\_P\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ace15d2ada390b068a7f3bfe5d3de3988) | Integer | Enable override of initial QP for P frame |
| [KEY\_INIT\_QP\_B\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a89148be357afbc369aa9d0d3817af403) | Integer | Enable override of initial QP for B frame |
| [KEY\_INIT\_QP\_I\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a41b1c954bc90d450c3adefc52cd8fb33) | Integer | Initial QP value to be used for the I frame. Initial QP must be enabled by setting [KEY\_INIT\_QP\_I\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a77216c8ad5c8ea1ba570d0e1ea556488) |
| [KEY\_INIT\_QP\_P\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ab24a20fbd4f7cb30063c3ab10295257a) | Integer | Initial QP value to be used for the P frame. Initial QP must be enabled by setting [KEY\_INIT\_QP\_P\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ace15d2ada390b068a7f3bfe5d3de3988) |
| [KEY\_INIT\_QP\_B\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a6465c1b6c9d05f51a8650bfd9c628e79) | Integer | Initial QP value to be used for the B frame. Initial QP must be enabled by setting [KEY\_INIT\_QP\_B\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a89148be357afbc369aa9d0d3817af403) |
| [KEY\_ROI\_INFO\_TYPE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1af082f0d6b200422dcae3710db7a5a67b) | String | Region Of Interest payload type |
| [KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755) | String | Region Of Interest payload specified with rectangles |
| [KEY\_ROI\_RECT\_INFO\_EXT](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1aef0f041fae7785a49f47f662b4aa2354) | String | Extended ROI payload to specify additional rectangles |
| [KEY\_ROI\_INFO\_TIMESTAMP](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1aa8714ef29ee90b9ecb670fb79c6e6e53) | Integer | Timestamp of the frame to associate the ROI with |
| [KEY\_ADV\_BITRATE\_MODE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ad3238a9dbfa25acf931fc7bbf18951bd) | Integer | Extended encoder rate-control mode. |
| [KEY\_ADV\_QP\_FRAME\_QP\_VALUE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a1be2578fb20902d9e0bbe2d74d1719d4) | Integer | QP value to be applied for compressing the next frame. Advance QP must be enabled by setting [KEY\_ADV\_BITRATE\_MODE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ad3238a9dbfa25acf931fc7bbf18951bd) to [ADV\_BITRATE\_MODE\_DISABLED](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a9080d42f1e6d39eeb220c5fb875ae583) |
| [KEY\_RESYNC\_MARKER\_SIZE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ada1388bdacd11a1a44659663e704ac4b) | Integer | Resync Marker size in bits. |
| [KEY\_SLICE\_SPACING\_SIZE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a036b844bb3a654c07d046475dcfc8ed8) | Integer | Slice spacing size in Macroblocks. |
| [KEY\_LTR\_MAX\_FRAMES](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ab16a9033e97e90b5af035f51050e29c1) | Integer | Maximum number of LTR frames (slots) the encoder can store at any given time. |
| [KEY\_LTR\_MARK\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1af55c814a609819f0fac521db1bee32f9) | Integer | Index of the slot to store the LRT frame. |
| [KEY\_LTR\_USE\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a6da1ac2ffd915d06a01edf0d43df0233) | Integer | Slot index of a previously stored LTR frame to be used as reference. |
| [KEY\_LTR\_RESPONSE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a089937fe1f1b3e0b854b1cc1aa367c8c) | Integer | Response from encoder to a mark or use operation. |

Public Static Attributes

- static final String KEY\_INIT\_QP\_I\_FRAME\_ENABLE   = "vendor.qti-ext-enc-initial-qp.qp-i-enable"

    - A key to enable override of default QP value used by the encoder for I frames.

The associated value is an integer:

| Value | Description |
| --- | --- |
| 1 | enable initial QP override for I frames |
| 0 | disable initial QP override for I frames |

Enabling I frame QP override will allow setting the initial QP value for I frames via [KEY\_INIT\_QP\_I\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a41b1c954bc90d450c3adefc52cd8fb33)

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_INIT\_QP\_P\_FRAME\_ENABLE   = "vendor.qti-ext-enc-initial-qp.qp-p-enable"

    - A key to enable override of default QP value used by the encoder for P frames.

The associated value is an integer:

| Value | Description |
| --- | --- |
| 1 | enable initial QP override for P frames |
| 0 | disable initial QP override for P frames |

Enabling P frame QP override will allow setting the initial QP value for P frames via [KEY\_INIT\_QP\_P\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ab24a20fbd4f7cb30063c3ab10295257a)

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_INIT\_QP\_B\_FRAME\_ENABLE   = "vendor.qti-ext-enc-initial-qp.qp-b-enable"

    - A key to enable override of default QP value used by the encoder for B frames.

The associated value is an integer:

| Value | Description |
| --- | --- |
| 1 | enable initial QP override for B frames |
| 0 | disable initial QP override for B frames |

Enabling B frame QP override will allow setting the initial QP value for B frames via [KEY\_INIT\_QP\_B\_FRAME](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a6465c1b6c9d05f51a8650bfd9c628e79) 

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_INIT\_QP\_I\_FRAME   = "vendor.qti-ext-enc-initial-qp.qp-i"

    - A key to set override for the initial QP value used by the encoder for I frames.

The associated value is an integer

| Codec | Valid QP range |
| --- | --- |
| AVC | 1 - 51 |
| HEVC | 1 - 51 |

I frame QP override must be enabled via [KEY\_INIT\_QP\_I\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a77216c8ad5c8ea1ba570d0e1ea556488) to set this override 

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_INIT\_QP\_P\_FRAME   = "vendor.qti-ext-enc-initial-qp.qp-p"

    - A key to set override for the initial QP value used by the encoder for P frames.

The associated value is an integer

| Codec | Valid QP range |
| --- | --- |
| AVC | 1 - 51 |
| HEVC | 1 - 51 |

P frame QP override must be enabled via [KEY\_INIT\_QP\_P\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1ace15d2ada390b068a7f3bfe5d3de3988) to set this override 

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_INIT\_QP\_B\_FRAME   = "vendor.qti-ext-enc-initial-qp.qp-b"

    - A key to set override for the initial QP value used by the encoder for B frames.

The associated value is an integer

| Codec | Valid QP range |
| --- | --- |
| AVC | 1 - 51 |
| HEVC | 1 - 51 |

B frame QP override must be enabled via [KEY\_INIT\_QP\_B\_FRAME\_ENABLE](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a89148be357afbc369aa9d0d3817af403) to set this override 

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_ROI\_INFO\_TYPE   = "vendor.qti-ext-enc-roiinfo.type"

    - A key to disable the encoder’s built-in rate-control and allow application to manage it directly.

The associated value is an integer

This key is accepted via MediaCodec::configure() before the encoder is started A key to specify the type of Region Of Interest (ROI) payload.

The associated value is string. Following types are supported

| Value | Description |
| --- | --- |
| “rect” | ROI is specified as **“Rectangles”**. Must use [KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755) to configure ROI |

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_ROI\_RECT\_INFO   = "vendor.qti-ext-enc-roiinfo.rect-payload"

    - A key to configure Region Of Interest (ROI) with a set of rectangles.

This configuration can be applied per-frame to override the QP decision of the encoder within certain regions of interest to keep or enhance the quality.

The region of interest is specified as a set of rectangles. Each rectangle is associated with a QP bias. The QP bias is applied on the encoder-determined QP to determine the final QP per macroblock. A negative value of QP bias will reduce the QP and hence improve quality.

The associated value for this key is a string that contains up to 5 rectangles along with the QP-bias encoded with the following syntax (R1, R2 .. are rectangles, up to 5)

**“R1\_top,R1\_left-R1\_bottom,R1\_right=QP\_1;R2\_top,R2\_left-R2\_bottom,R2\_right=QP\_2;..”**  Below are a couple of examples

| Rectangle info | Description |
| --- | --- |
| “100,100-400,400=-6;” | Specifies 1 rectangle [(100,100) (400,400)] with bias = -6 |
| “100,100-400,400=-6;200,200-300,300=-4” | Specifies 2 rectangles. [(100,100) (400,400)] with bias = -6 and [(200,200) (400,400)] with bias = -4 |

This key is accepted via MediaCodec::setParameters() with every frame

Note

It is important to associate the timestamp with KEY\_ROI\_INFO\_TIMESTAMP

Note

[KEY\_ROI\_RECT\_INFO\_EXT](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1aef0f041fae7785a49f47f662b4aa2354) can be optionally used if the ROI cannot be specified by 5 rectangular regions

- static final String KEY\_ROI\_RECT\_INFO\_EXT   = "vendor.qti-ext-enc-roiinfo.rect-payload-ext"

    - This key is an extension to [KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755) to configure additional rectangles.

[KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755) supports up to 5 rectangular regions. This key allows augmenting the rectangles with 5 more (total of 10 rectangles)

This key is accepted via MediaCodec::setParameters() with every frame

Note

This key cannot be set without setting [KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755)

- static final String KEY\_ROI\_INFO\_TIMESTAMP   = "vendor.qti-ext-enc-roiinfo.type"

    - A key to specify the timestamp (in microseconds) of the frame that the ROI region (specified with [KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755)) corresponds to.

The associated value is an integer indicating the corresponding frame timestamp in microseconds

This parameter is necessary if the applications queued the frames to encoder via a input Surface. Since the submission of frame to encoder (via eglSwapBuffers) is not synchronized with MediaCodec.setParameters(), the specified ROI can go out of sync with the corresponding frame. Attaching timestamp with the ROI enables the encoder to synchronize ROI data with the frame. This key is accepted via MediaCodec::setParameters() with every frame along with the [KEY\_ROI\_RECT\_INFO](https://docs.qualcomm.com/doc/80-56386-10/topic/classqti_1_1video_1_1QMediaExtensions.html#classqti_1_1video_1_1QMediaExtensions_1a095315d427852d75b7ca44dea2ec2755) parameter

Note

It is important to set the ROI bundle (ROI\_RECT\_INFO + ROI\_INFO\_TIMESTAMP) ahead of queuing the frame to ensure the ROI data is not missed

- static final String KEY\_ADV\_BITRATE\_MODE   = "vendor.qti-ext-enc-bitrate-mode.value"

    - A key to set extended rate-control mode for the encoder.

The associated value is an integer:

| Value | Description |
| --- | --- |
| ADV\_BITRATE\_MODE\_DISABLED | Disable encoder’s rate-control |

This key is accepted via MediaCodec::configure() before the encoder is started

- static final int ADV\_BITRATE\_MODE\_DISABLED   = 0

    - Extended bitrate mode to signal disablement of encoder’s rate-control.

This works in conjunction with advanced QP control mode where the application configures per-frame QP using KEY\_ADV\_QP\_BITRATE\_MODE.

- static final String KEY\_ADV\_QP\_FRAME\_QP\_VALUE   = "vendor.qti-ext-enc-frame-qp.value"

    - A key to specify the QP value to be applied for compressing the next frame.

The associated value is an integer

This value has to be configured dynamically per frame This key is accepted via MediaCodec::SetParameters() before the encoder is started

- static final String KEY\_RESYNC\_MARKER\_SIZE   = "vendor.qti-ext-enc-error-correction.resync-marker-spacing.bits"

    - A key to specify the resync marker size in bits.

The associated value is an integer

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_SLICE\_SPACING\_SIZE   = "vendor.qti-ext-enc-slice.spacing"

    - A key to specify the slice spacing in Macroblocks.

The associated value is an integer

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_LTR\_MAX\_FRAMES   = "vendor.qti-ext-enc-ltr-count.num-ltr-frames"

    - A key to specify the maximum number of LTR frames (slots) the encoder can store at any given time.

The associated value is an integer

The default value is 0, which means that no LTR frames are allowed. Setting a nonzero value does not guarantee LTR frames; it is up to the encoder to allow LTR frames.

This key is accepted via MediaCodec::configure() before the encoder is started

- static final String KEY\_LTR\_MARK\_FRAME   = "vendor.qti-ext-enc-ltr.mark-frame"

    - A key to specify the index of the slot to store the LTR Frame.

The associated value is an integer

If the specified slot has a previously stored LTR frame, it will be replaced with the current frame This key is accepted via MediaCodec::SetParameters() before the encoder is started

- static final String KEY\_LTR\_USE\_FRAME   = "vendor.qti-ext-enc-ltr.use-frame"

    - A key to specify the slot index of a previously stored LTR frame to be used as reference.

The associated value is an integer

This key is accepted via MediaCodec::setParameters() with every frame

- static final String KEY\_LTR\_RESPONSE   = "vendor.qti-ext-enc-info-ltr.ltr-use-mark"

    - The encoder use this key to signal a response to mark or use operations.

The associated value is an integer

This key is accepted via MediaCodec::setParameters() with every frame

Last Published: Jun 13, 2023

[Previous Topic
Template Class QMediaCodecCapabilities::ValueRange](https://docs.qualcomm.com/bundle/publicresource/80-56386-10/topics/classqti_1_1video_1_1QMediaCodecCapabilities_1_1ValueRange.md) [Next Topic
Extension Features](https://docs.qualcomm.com/bundle/publicresource/80-56386-10/topics/extension_features.md)