文档管理中心
您当前正在浏览新版开发者文档中心,目录分类和层级有所调整。点击左侧当前文档分类名称前的“☰”图标,可切换文档分类。 了解新版目录
最佳实践应用质量功耗应用功耗优化前台任务低功耗前台资源合理使用视频场景编解码低功耗规则

视频场景编解码低功耗规则

规则

  • 视频应用需使用视频硬件编解码器。
  • 视频场景应使用专用硬件解码器(VDEC),其功耗效率显著优于CPU软解码。因此,应使用平台的视频硬件编解码器进行视频播放。

开发步骤

调用OH_AVCodec相关接口,使用视频硬件编解码器处理视频。

收起
自动换行
深色代码主题
复制
  1. // To create a decoder using a codec name, if the application has special requirements, such as selecting a decoder that supports a certain resolution specification,
  2. // the capability can be queried first, and then the decoder can be created based on the codec name.
  3. OH_AVCapability *capability = OH_AVCodec_GetCapability(OH_AVCODEC_MIMETYPE_VIDEO_AVC, false);
  4. const char *name = OH_AVCapability_GetName(capability);
  5. // Create a decoder through mimetype
  6. // Hard solution: Create H264 decoder. When there are multiple optional decoders, the system will create the most suitable decoder
  7. OH_AVCodec *videoDec = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
  8. // Hard solution: Create H265 decoder
  9. OH_AVCodec *videoDecH = OH_VideoDecoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_HEVC);

调测验证

  • 方法一:在命令提示符窗口中,输入hdc shell top命令,查看当前系统的top进程的CPU占用率。如果av_codec_service进程的CPU负载率超过 5%,则说明视频硬解码已启用。