【红霉素实战开发】HarmonyOS-HDR Vivid能力详解

HDR Vivid视频播放

开发者可以调用本模块的Native API接口,实现在视频播放中支持HDR Vivid标准。

视频播放的主要流程,是将视频文件“解封装 > 解码 > 送显/播放”。

HDR Vivid视频解析

从视频文件中,可以解析出其是否为HDRVivid视频,如果视频源为HDRVivid视频,可以解析相关的信息,如CuvvBox信息、元数据、Color信息等。

在 CMake 脚本中链接动态库

target_link_libraries(sample PUBLIC libnative_media_codecbase.so)
target_link_libraries(sample PUBLIC libnative_media_avdemuxer.so)
target_link_libraries(sample PUBLIC libnative_media_avsource.so)
target_link_libraries(sample PUBLIC libnative_media_core.so)

开发步骤

  1. 添加头文件。
#include <multimedia/player_framework/native_avdemuxer.h>
#include <multimedia/player_framework/native_avsource.h>
#include <multimedia/player_framework/native_avcodec_base.h>
#include <multimedia/player_framework/native_avformat.h>
#include <multimedia/player_framework/native_avbuffer.h>
#include <fcntl.h>
#include <sys/stat.h>
  1. 文件解析器。
// 创建文件操作符 fd,打开时对文件句柄必须有读权限(filePath 为待解封装文件路径,需预置文件,保证路径指向的文件存在)
std::string filePath = "test.mp4";
int fd = open(filePath.c_str(), O_RDONLY);
struct stat fileStatus {};
// 获取fileSize 
size_t fileSize = 0;
if (stat(filePath.c_str(), &fileStatus) == 0) {
   fileSize = static_cast<size_t>(fileStatus.st_size);
}
else {
    printf("get stat failed");
    return;
}
// 为 fd 资源文件创建 source 资源对象
OH_AVSource *source = OH_AVSource_CreateWithFD(fd, 0, fileSize);
if (source == nullptr) {
   printf("create source failed");
   return;
}
  1. 获取视频轨道信息,查询文件HDR类型。
int32_t trackCount = 0;
uint32_t audioTrackIndex = 0;
uint32_t videoTrackIndex = 0;
int32_t trackType;
   // 从文件 source 信息获取文件轨道数
OH_AVFormat *sourceFormat = OH_AVSource_GetSourceFormat(source);
if (sourceFormat == nullptr) {
   printf("get source format failed");
   return;
}
OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &trackCount);
OH_AVFormat_Destroy(sourceFormat);
for (uint32_t index = 0; index < (static_cast<int32_t>(trackCount)); index++) {
   // 获取轨道信息
   OH_AVFormat *format = OH_AVSource_GetTrackFormat(source, index);
   if (format == nullptr) {
      printf("get track format failed");
      return;
   }
   // 判断轨道类型
   static_cast<OH_MediaType>(trackType) == OH_MediaType::MEDIA_TYPE_AUD ? audioTrackIndex = index : videoTrackIndex = index;
   // 查询文件HDR类型,是否为HDRVivid视频。
   int32_t isHDRVivid;
   int32_t ret = OH_AVFormat_GetIntValue(format, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &isHDRVivid);
   if (ret != AV_ERR_OK) {
      printf("is not HDRVivid ");
      return;
   }
   OH_AVFormat_Destroy(format); // 销毁
}

HDR Vivid视频解码

应用创建H265解码器,并配置宽、高、format信息。解码器解析码流,生产对应的视频帧数据以及元数据。

说明

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值