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)
开发步骤
- 添加头文件。
#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>
- 文件解析器。
// 创建文件操作符 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;
}
- 获取视频轨道信息,查询文件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信息。解码器解析码流,生产对应的视频帧数据以及元数据。
说明
<