@amazon-devices/keplermediadescriptor
Kepler MediaDescriptor API提供了可查询设备编解码器功能的功能。API还会考虑联网设备支持,并根据设备限制返回其编解码器功能。
开始使用
先决条件
KeplerMediaDescriptor API依赖于以下接口:
有关如何安装Kepler SDK的说明,请参阅Kepler SDK设置。
设置
将以下库依赖项添加到package.json文件的dependencies部分。
"@amazon-devices/keplermediadescriptor": "~1.0.0",
用法
使用此程序包获取设备的视频和音频功能,并相应地播放您的内容。一些常见的用例包括:
- 用于确定设备是否支持指定的视频/音频编解码器。
- 对于给定的视频编解码器,确定设备是否支持特定的配置文件级别或帧速率或比特率或分辨率。
- 确定设备是否支持特定MIME类型。
- 确定连接的设备(Fire TV Stick用例中的TV/AVR等)是否支持Dolby编解码器。
从程序包中导入所需的接口
import {
KeplerMediaDescriptor,
MediaFormat,
VideoDecoderConfig,
VideoFormat,
AudioDecoderConfig,
AudioFormat,
MediaFormatProfileLevel,
} from "@amazon-devices/keplermediadescriptor";
查询视频解码器功能。
此示例说明如何使用编解码器名称查询功能。它还设置了其他可选属性,例如分辨率、比特率和fps。
let mediaFormat : MediaFormat = new MediaFormat(CodecMimeType.MIME_AVC);
// 12Mbps比特率
mediaFormat.bitrateKbps = 12000;
// 1080p分辨率
let videoFormat = new VideoFormat();
videoFormat.resolution = {
width = 1080,
height = 1920
};
// 60fps帧速率
videoFormat.frameRate = 60;
// 使用解码器配置一次性发送
// 所有属性。
const decoderConfig = new VideoDecoderConfig();
decoderConfig.mediaFormat = mediaFormat;
decoderConfig.videoFormat = videoFormat;
decoderConfig.formatProfileLevel = profileLevel;
注意: 您也可以在MIME字符串中包含编解码器值。
// 具有主配置文件和级别4.2的avc编解码器
let mime = "video/mp4; codecs="avc1.640028""
let profileLevel = new MediaFormatProfileLevel(mime);
decoderConfig.formatProfileLevel = profileLevel;
在VideoDecoderConfig对象准备就绪后,您可以调用查询方法。如果返回的功能数组包含至少一个条目,则表示设备支持所请求的属性。
let videoCaps = await KeplerMediaDescriptor.queryMediaCapabilities(decoderConfig);
if (videoCaps.length > 0) {
console.info("设备支持请求的配置");
}
阅读返回的视频功能
从queryMediaCapabilities API返回的功能信息中,包含了有关设备支持情况的更多信息。
// 遍历支持的功能
for (let index = 0; index < videoCaps.length; index++) {
let videoCapability = videoCaps[index];
// 检查硬件是否支持编解码器
if (videoCapability.mediaCodecFeaturesCapabilities.hardwareBacked) {
console.log("硬件支持编解码器。")
}
// 获取编解码器支持的最小和最大分辨率:
let resolutions = videoCapability.videoFormatCapabilities.resolutions;
console.log("最小分辨率为", resolutions[0], "最大分辨率为", resolutions[1]);
// 获取编解码器在给定分辨率下支持的最大帧速率
let maxFps = videoCapability.videoFormatCapabilities.getMaxFrameRate(resolutions[1]);
// 获取解码器支持的所有颜色格式:
console.log(videoCapability.videoFormatCapabilities.colorFormats);
// 检查编解码器是否支持解密
if (videoCapability.decoderFeaturesCapabilities.decryptionSupported) {
console.log("此编解码器支持解密");
}
}
查询音频解码功能
与视频功能类似,您可以查询设备的音频解码支持情况。
let mediaFormat = new MediaFormat(CodecMimeType.MIME_AAC);
let audioFormat = new AudioFormat();
audioFormat.channelCount = 2;
audioFormat.sampleRate = 44100;
const decoderConfig = new AudioDecoderConfig();
decoderConfig.mediaFormat = mediaFormat;
decoderConfig.audioFormat = audioFormat;
let audioCaps = await KeplerMediaDescriptor.queryMediaCapabilities(decoderConfig);
查看Dolby支持
您可以使用queryMediaCapabilities() 方法来确定设备的Dolby支持。对于Fire TV Stick,该方法会考虑连接的电视和AVR等项目。
let mediaFormat = new MediaFormat(CodecMimeType.MIME_AC3); // 或MIME_EAC3
const decoderConfig = new AudioDecoderConfig();
decoderConfig.mediaFormat = mediaFormat;
let audioCaps = await KeplerMediaDescriptor.queryMediaCapabilities(decoderConfig);
if (audioCaps.length > 0) {
console.log("设备支持Dolby数字音频");
}
阅读返回的音频功能
// 遍历支持的功能
for (let index = 0; index < audioCaps.length; index++) {
let audioCapability = audioCaps[index];
if (audioCapability.decoderFeaturesCapabilities.decryptionSupported) {
console.log("编解码器支持解密");
}
}
常见问题解答
- 问: 我能否在一次调用中获得设备支持的所有编解码器?
- 使用
CodecMimeType.MIME_VIDEO_UNSPECIFIED和CodecMimeType.MIME_AUDIO_UNSPECIFIED作为通配符。## 模块
- index
- KeplerMediaDescriptor
- MediaCapabilitiesImpl
- turbo-modules/KeplerMediaDescriptorInterface
- turbo-modules/KeplerMediaDescriptorInterface
- turbo-modules/KeplerMediaDescriptorTurboModule
- turbo-modules/KeplerMediaDescriptorTurboModule
- turbo-modules/LevelValues
- turbo-modules/LevelValues
- turbo-modules/NativeInterface
- turbo-modules/NativeInterface
- turbo-modules/ProfileValues
- turbo-modules/ProfileValues
Last updated: 2025年11月14日

