With the C APIs provided by the VideoProcessing module, you can generate HDR Vivid dynamic metadata.
A typical usage scenario is video editing, as shown in the figure below.

The following data input format combinations are supported:
Format combination 1
| Parameter | Data Input Format |
|---|---|
| ColorSpace | OH_COLORSPACE_BT2020_PQ_LIMIT |
| MetadataType | OH_VIDEO_HDR_VIVID |
| pixelFormat | NATIVEBUFFER_PIXEL_FMT_YCBCR_P010, NATIVEBUFFER_PIXEL_FMT_YCRCB_P010, NATIVEBUFFER_PIXEL_FMT_RGBA_1010102 |
Format combination 2
| Parameter | Data Input Format |
|---|---|
| ColorSpace | OH_COLORSPACE_BT2020_HLG_LIMIT |
| MetadataType | OH_VIDEO_HDR_VIVID |
| pixelFormat | NATIVEBUFFER_PIXEL_FMT_YCBCR_P010, NATIVEBUFFER_PIXEL_FMT_YCRCB_P010, NATIVEBUFFER_PIXEL_FMT_RGBA_1010102 |
Format combination 3
| Parameter | Data Input Format |
|---|---|
| ColorSpace | OH_COLORSPACE_BT2020_HLG_LIMIT |
| MetadataType | OH_VIDEO_HDR_HLG |
| pixelFormat | NATIVEBUFFER_PIXEL_FMT_YCBCR_P010, NATIVEBUFFER_PIXEL_FMT_YCRCB_P010, NATIVEBUFFER_PIXEL_FMT_RGBA_1010102 |
Format combination 4
| Parameter | Data Input Format |
|---|---|
| ColorSpace | OH_COLORSPACE_BT2020_PQ_LIMIT |
| MetadataType | OH_VIDEO_HDR_HDR10 |
| pixelFormat | NATIVEBUFFER_PIXEL_FMT_YCBCR_P010, NATIVEBUFFER_PIXEL_FMT_YCRCB_P010, NATIVEBUFFER_PIXEL_FMT_RGBA_1010102 |
Supported resolution specifications
| Minimum Resolution (Unit: Pixel) | Maximum Resolution (Unit: Pixel) |
|---|---|
| 32*32 | 8192*8192 |
To ensure the conversion efficiency, you are advised to carry out a maximum of five conversion tasks concurrently.
Only dynamic metadata of the OH_VIDEO_HDR_VIVID type can be generated. After conversion, metadataType is changed to OH_VIDEO_HDR_VIVID.
Do not directly call video processing APIs or perform other time-consuming operations in the video processing callback function. Instead, call them in the thread of the application.
target_link_libraries(sample PUBLIC libvideo_processing.so)
Add the header files.
#include <multimedia/video_processing_engine/video_processing.h> #include <multimedia/video_processing_engine/video_processing_types.h> #include <native_window/external_window.h> #include <native_buffer/native_buffer.h> #include <ace/xcomponent/native_interface_xcomponent.h> #include <multimedia/player_framework/native_avformat.h>
(Optional) Initialize the environment.
This is usually executed on the initial use within a process to preemptively handle certain time-consuming operations.
OH_VideoProcessing_InitializeEnvironment();
(Optional) Check for capability support. Perform this operation before using the corresponding capability.
// Input format. VideoProcessing_ColorSpaceInfo videoInfo; videoInfo.metadataType = OH_VIDEO_HDR_HDR10; videoInfo.colorSpace = OH_COLORSPACE_BT2020_PQ_LIMIT; videoInfo.pixelFormat = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010; // Check whether the input format can be converted to the HDR Vivid metadata type. bool isSupport = OH_VideoProcessing_IsMetadataGenerationSupported(&videoInfo);
Create a dynamic metadata generation module.
The application may create a dynamic metadata generation module by using a video processing engine type. In the code snippet below, the following variables are used:
// Create a dynamic metadata generation module instance by specifying the video processing engine type. OH_VideoProcessing* videoProcessor = nullptr; VideoProcessing_ErrorCode ret = OH_VideoProcessing_Create(&videoProcessor, VIDEO_PROCESSING_TYPE_METADATA_GENERATION);
Configure the asynchronous callback function.
// Declare the callback function (userData is the user data passed during callback registration, for example, this pointer.) void OnError(OH_VideoProcessing* videoProcessor, VideoProcessing_ErrorCode error, void* userData); void OnState(OH_VideoProcessing* videoProcessor, VideoProcessing_State state, void* userData); void OnNewOutputBuffer(OH_VideoProcessing* videoProcessor, uint32_t index, void* userData); // Create a callback instance. VideoProcessing_Callback* callback = nullptr; ret = OH_VideoProcessingCallback_Create(&callback); // Bind the callback function. OH_VideoProcessingCallback_BindOnError(callback, OnError); OH_VideoProcessingCallback_BindOnState(callback, OnState); OH_VideoProcessingCallback_BindOnNewOutputBuffer(callback, OnNewOutputBuffer); // Register the callback function. ret = OH_VideoProcessing_RegisterCallback(videoProcessor, callback, this);
(Optional) From API version 22, the mode for generating dynamic video metadata can be configured. Currently, two modes are supported: contrast and brightness. If no mode is configured, the contrast mode is used by default.
// Create a format instance. OH_AVFormat* parameter = OH_AVFormat_Create(); // Specify the brightness mode. OH_AVFormat_SetIntValue(parameter, VIDEO_METADATA_GENERATOR_STYLE_CONTROL, VIDEO_METADATA_GENERATOR_BRIGHT_MODE); // Set parameters. OH_VideoProcessing_SetParameter(videoProcessor, parameter);
Obtain a surface.
// Obtain an input surface. OHNativeWindow *inWindow = nullptr; ret = OH_VideoProcessing_GetSurface(videoProcessor, &inWindow);
Set the surface.
You can obtain an OHNativeWindow instance from the XComponent. For details, see Native Window Development.
windowOut in SetSurface of the video processing engine is obtained from the OnSurfaceCreatedCB callback function of the XComponent. Parameters such as the metadata type, data format, and color space need to be set for windowOut.
// Set the metadata type, data format, and color space. uint8_t metadataType = OH_VIDEO_HDR_HLG; OH_NativeWindow_SetMetadataValue(windowOut, OH_HDR_METADATA_TYPE, sizeof(uint8_t), (uint8_t *)&metadataType); OH_NativeBuffer_Format format = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010; OH_NativeWindow_NativeWindowHandleOpt(windowOut, SET_FORMAT, format); OH_NativeBuffer_ColorSpace colorSpace = OH_COLORSPACE_BT2020_HLG_LIMIT; OH_NativeWindow_SetColorSpace(windowOut, colorSpace); // Set the output surface. VideoProcessing_ErrorCode ret = OH_VideoProcessing_SetSurface(videoProcessor, windowOut);
Call OH_VideoProcessing_Start() to start dynamic metadata generation.
// Start dynamic metadata generation and conversion. ret = OH_VideoProcessing_Start(videoProcessor);
Call OH_VideoProcessing_Stop() to stop dynamic metadata generation.
// Stop dynamic metadata generation. ret = OH_VideoProcessing_Stop(videoProcessor);
Release the video processing instance.
OH_VideoProcessingCallback_Destroy(callback); callback = nullptr; OH_VideoProcessing_Destroy(videoProcessor); videoProcessor = nullptr;
Release the video processing resources.
OH_VideoProcessing_DeinitializeEnvironment();