本示例基于Surface模式实现高效视频编解码,支持HDR视频录制及HDR转SDR转码功能,通过硬件加速和色彩空间优化技术,提升视频质量处理效率。
Access rate limit exceeded. Please log in to continue.
HDR-to-SDR Video Transcoding
Overview
This sample demonstrates how to implement high-performance video codec via surface mode, and how to record HDR footage and convert it to SDR by leveraging hardware acceleration and color-space optimization.
Effect
| 首页 | 播放页 |
|---|---|
![]() |
![]() |
| 录制页 | 转码页 |
![]() |
![]() |
How to Use
- Open the application, tap HDR video recording, and select Recorder or AVCodec for encapsulation.
- Tap to record a video. After the recording is complete, tap to play or pause the video.
- Tap Save Video and confirm.
- Return to the home page and tap HDR video transcode.
- Tap the screen to select a video, and tap AVCodec transcode or Video_Processing Color Conversion to transcode HDR to SDR and display the video.
Project Directory
├──entry/src/main/cpp // Native layer
│ ├──CMakeLists.txt // Compilation entry
│ ├──capbilities // API capability
│ ├──AudioCapturer.cpp // Audio capturer
│ ├──AudioEncoder.cpp // Audio encoder
│ ├──Demuxer.cpp // Demuxer
│ ├──Muxer.cpp // Muxer
│ ├──AudioDecoder.cpp // Audio decoder for transcoding
│ ├──Demuxer.cpp // Demuxer for transcoding
│ │ ├──VideoDecoder.cpp // Video decoder for transcoding
│ │ ├──VideoEncoder.cpp // Video encoder
│ │ └──include // API capability definition
│ ├──common // Common modules
│ │ ├──SampleCallback.cpp // Codec callback
│ │ ├──SampleCallback.h // Codec callback definition
│ │ ├──SampleInfo.h // Common class
│ │ └──dfx // Log implementation
│ ├──render // Display module
│ │ ├──PluginManager.cpp // Display module management
│ │ ├──PluginRender.cpp // Display module logic
│ │ └──include // API definition of the display module
│ ├──sample
│ │ ├──player // Playback API for transcoding
│ │ │ ├──Player.cpp // Playback API implementation for transcoding
│ │ │ ├──Player.h // Playback API definition for transcoding
│ │ │ ├──PlayerNative.cpp // API call entry for transcoding
│ │ │ └──PlayerNative.h // API call entry definition
│ │ └──recorder // Recording API
│ │ ├──Recorder.cpp // Recording API implementation
│ │ ├──Recorder.h // Recording API definition
│ │ ├──RecorderNative.cpp // API call entry
│ │ └──RecorderNative.h // API call entry definition
│ └──types // APIs exposed by the native layer
│ ├──libplayer // APIs exposed by the playback module for transcoding to the UI layer
│ └──librecorder // APIs exposed by the recorder to the UI layer
├──ets // UI layer
│ ├──common // Common modules
│ │ ├──CommonConstants.ets // Common constants
│ │ └──utils // Common utility
│ │ ├──DateTimeUtils.ets // Time utility
│ │ ├──FileUtil.ets // File utility
│ │ ├──PermissionsUtils.ets // Permission application utility
│ │ └──VideoOperationUtils.ets // File saving utility
│ ├──controller // Controller
│ │ ├──AVCodecController.ets // AVCodec controller
│ │ ├──AvPlayerController.ets // AVPlayer controller
│ │ └──RecordController.ets // Recorder controller
│ ├──entryability // Application entry function
│ │ └──EntryAbility.ets
│ ├──entrybackupability
│ │ └──EntryBackupAbility.ets
│ ├──model
│ │ └──CameraDateModel.ets // Camera parameter data class
│ ├──pages
│ │ ├──CameraPage.ets // Camera recording page
│ │ ├──Index.ets // Home page
│ │ ├──Recording.ets // Video recording page
│ │ └──Transcode.ets // Video transcoding page
│ └──view // Component module
│ ├──MultiStatusButton.ets // Check box component
│ └──SaveDialog.ets // Save dialog
├──module.json5 // Module configuration
└──resources // Static resources
How to Implement
Video recording:
- Use cameraInput to obtain the data collected by the camera and create a camera input.
- Create a previewOutput object to obtain the preview output stream, connect to the XComponent through the surface ID, and send the stream to the XComponent for display.
- Create a VideoOutput object by using the surface ID and output the stream to a file.
- The method implementation of the Recorder is encapsulated in RecordController.ets, and that of the AVCodec is encapsulated in AVCodecController.ets
Video transcoding:
- After a user selects a file, the playNative() transcoding API is called.
- Before transcoding, call the init function to initialize the demuxer, muxer, encoder, and decoder, with context parameters saved simultaneously.
- Call the Start function to initiate decoding, which starts a decoding thread. This thread includes an input child thread and an output child thread.
- The input child thread leverages demuxed bufferInfo to call the decoder's PushInputData API, storing the frame buffer and index into the input queue. The output child thread stores the preceding frame information as bufferInfo and pops it out of the queue. Then the FreeOutputData API is called to display the frame and release the buffer.
Required Permissions
ohos.permission.CAMERA: allows an application to use the camera.
ohos.permission.MICROPHONE: allows an application to use the microphone.
ohos.permission.WRITE_MEDIA: allows an application to write media files.
Constraints
-
This sample is only supported on Huawei phones running standard systems.
-
The HarmonyOS version must be HarmonyOS 6.0.0 Release or later.
-
The DevEco Studio version must be DevEco Studio 6.0.0 Release or later.
-
The HarmonyOS SDK version must be HarmonyOS 6.0.0 Release SDK or later.
Introduction
本示例基于Surface模式实现高效视频编解码,支持HDR视频录制及HDR转SDR转码功能,通过硬件加速和色彩空间优化技术,提升视频质量处理效率。
Customize your domain


