目录

Video Color Space Conversion

With the C APIs provided by the VideoProcessing module, you can implement Color Space Conversions (CSCs) of HDR2SDR, HDR2HDR, and SDR2SDR.

A typical usage scenario is video editing and sharing.

Specifications

When the video CSC algorithm is SDR2SDR, the supported format combinations are as follows:

When the video CSC algorithm is HDR2SDR, the supported format combinations are as follows:

When the video CSC algorithm is HDR2HDR, the supported format combinations are as follows:

Supported resolution specifications

Minimum Resolution (Unit: Pixel) Maximum Resolution (Unit: Pixel)
32*32 8192*8192

Constraints

  1. To ensure the conversion efficiency, you are advised to carry out a maximum of five conversion tasks concurrently.

  2. 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.

Development Guidelines

For details, see sample code.

[h2]Linking the Dynamic Libraries in the CMake Script

target_link_libraries(sample PUBLIC libvideo_processing.so)

[h2]How to Develop

  1. 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>
  2. (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();
  3. (Optional) Check for capability support. Perform this operation before using the corresponding capability.

    // Input and output formats.
    VideoProcessing_ColorSpaceInfo inputFormat;
    VideoProcessing_ColorSpaceInfo outputFormat;
    inputFormat.metadataType = OH_VIDEO_HDR_HDR10;
    inputFormat.colorSpace = OH_COLORSPACE_BT2020_PQ_LIMIT;
    inputFormat.pixelFormat = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
    outputFormat.metadataType = OH_VIDEO_HDR_HLG;
    outputFormat.colorSpace = OH_COLORSPACE_BT2020_HLG_LIMIT;
    outputFormat.pixelFormat = NATIVEBUFFER_PIXEL_FMT_YCBCR_P010;
    
    // Capability query.
    bool isSupport = OH_VideoProcessing_IsColorSpaceConversionSupported(&inputFormat, &outputFormat);
  4. Create a CSC module.

    The application may create a CSC module by using a video processing engine type. In the code snippet below, the following variables are used:

    • videoProcessor: CSC module instance.
    • VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION: CSC type
    • VIDEO_PROCESSING_SUCCESS: expected return value.
    // Create a CSC module instance by specifying the video processing engine type.
    OH_VideoProcessing* videoProcessor = nullptr;
    VideoProcessing_ErrorCode ret = OH_VideoProcessing_Create(&videoProcessor, VIDEO_PROCESSING_TYPE_COLOR_SPACE_CONVERSION);
  5. 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);
  6. Obtain a surface.

    // Obtain an input surface.
    OHNativeWindow *inWindow = nullptr;
    ret = OH_VideoProcessing_GetSurface(videoProcessor, &inWindow);
  7. 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);
  8. Call OH_VideoProcessing_Start() to start CSC.

    // Start CSC.
    ret = OH_VideoProcessing_Start(videoProcessor);
  9. Call OH_VideoProcessing_Stop() to stop CSC.

    // Stop CSC.
    ret = OH_VideoProcessing_Stop(videoProcessor);
  10. Release the video processing instance.

    OH_VideoProcessingCallback_Destroy(callback);
    callback = nullptr;
    OH_VideoProcessing_Destroy(videoProcessor);
    videoProcessor = nullptr;
  11. Release the video processing resources.

    OH_VideoProcessing_DeinitializeEnvironment();