When sharing or editing an HDR Vivid video, you can call the AVCodec capability to convert the video to the SDR format.

This feature is available only for hardware decoders.
This feature is supported only in surface mode. For details about the output differences between the surface mode and buffer mode, see Video Decoding.
When this feature is enabled, the stream resolution cannot be changed, and the error code AV_ERR_UNSUPPORT is reported through the callback function OH_AVCodecOnError() .
After OH_VideoDecoder_Configure is successfully called and before OH_VideoDecoder_Start is called, you must call OH_VideoDecoder_Prepare.
If OH_VideoDecoder_Reset is called to reset the decoder to the initial state, you must call OH_VideoDecoder_Configure, OH_VideoDecoder_Prepare, and OH_VideoDecoder_SetSurface again.
You can configure OH_MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE to output SDR images after decoding. Currently, only HDR Vivid streams can be input, and only OH_COLORSPACE_BT709_LIMIT streams can be output.
target_link_libraries(sample PUBLIC libnative_media_avsource.so) target_link_libraries(sample PUBLIC libnative_media_vdec.so) target_link_libraries(sample PUBLIC libnative_media_core.so)
The word sample in the preceding code snippet is only an example. Use the actual project directory name.
Add the header files.
#include <multimedia/player_framework/native_avcodec_videodecoder.h> #include <multimedia/player_framework/native_avcapability.h> #include <multimedia/player_framework/native_avcodec_base.h> #include <multimedia/player_framework/native_avformat.h> #include <multimedia/player_framework/native_avbuffer.h> #include <fstream>
Add the header files and the file to parse by referring to HDR Vivid Video Playback, and check whether the video format is HDR Vivid.
If the video format is not HDR Vivid, decode the video by referring to Video Decoding.
If the video format is HDR Vivid, proceed to the next step.
If the input source is not HDR Vivid, the error code AV_ERR_VIDEO_UNSUPPORTED_COLOR_SPACE_CONVERSION is reported through the callback function OH_AVCodecOnError().
Create a decoder instance.
Query the decoder capabilities supported by the system and create a hardware decoder based on the query result.
In the code snippet below, the following variables are used:
// 3.1 Obtain the HEVC decoder capability of the specified hardware.
OH_AVCapability *capability = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_HEVC, false, HARDWARE);
if (capability == nullptr){
// Handle exceptions.
}
// 3.2 Obtain the name of an HEVC hardware decoder.
const char *name = OH_AVCapability_GetName(capability);
// 3.3 Create an HEVC hardware decoder instance.
OH_AVCodec *videoDec = OH_VideoDecoder_CreateByName(name);
Currently, this feature is available only for hardware decoders. Therefore, you must create a decoder by name.
Call OH_VideoDecoder_RegisterCallback() to set callback functions.
For details, see "Step 3: Configure the asynchronous callback function" in Decoding an HDR Vivid Video.
Call OH_VideoDecoder_Configure() to configure the decoder.
The video frame width, video frame height, and video pixel format must be configured, and the output format must be SDR. The following is an example:
DEFAULT_WIDTH: 320 pixels
DEFAULT_HEIGHT: 240 pixels
DEFAULT_PIXELFORMAT: AV_PIXEL_FORMAT_NV12 (the pixel format of the YUV file is NV12)
// Video frame width.
int32_t width = 320;
// Video frame height.
int32_t height = 240;
// Video pixel format.
constexpr OH_AVPixelFormat DEFAULT_PIXELFORMAT = AV_PIXEL_FORMAT_NV12;
OH_AVFormat *format = OH_AVFormat_Create();
// 5.1 Configure the video width, height, and pixel format.
OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, width);
OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, height);
OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, DEFAULT_PIXELFORMAT);
// 5.2 Specify the SDR output format.
OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE, OH_COLORSPACE_BT709_LIMIT);
// 5.3 Configure the decoder.
int32_t ret = OH_VideoDecoder_Configure(videoDec, format);
if (ret != AV_ERR_OK) {
// Handle exceptions.
}
OH_AVFormat_Destroy(format);
You can configure OH_MD_KEY_VIDEO_DECODER_OUTPUT_COLOR_SPACE to output SDR images after decoding. Currently, only HDR Vivid streams can be input, and only OH_COLORSPACE_BT709_LIMIT streams can be output.
For details about the subsequent steps, see Video Decoding in Surface Mode.