LiveKit Server SDK报错:IngressVideoOptions无preset属性及新版适配问题
解决LiveKit Server SDK Ingress视频编码预设配置错误
问题1:preset 属性不存在于 IngressVideoOptions 类型
配置Ingress视频选项时,使用preset属性触发TypeScript错误:
Object literal may only specify known properties, and 'preset' does not exist in type 'IngressVideoOptions'
相关代码:
import { IngressVideoEncodingPreset, TrackSource // ... 其他导入项 } from "livekit-server-sdk"; // ... options.video = { source: TrackSource.CAMERA, preset: IngressVideoEncodingPreset.H264_1080P_30FPS_3_LAYERS, };
问题2:新版本SDK配置 encodingOptions 后提示缺少类属性
适配新版本改用encodingOptions后,出现新错误:
类型'{ source: TrackSource; encodingOptions: { value: IngressVideoEncodingPreset.H264_1080P_30FPS_3_LAYERS; case: "preset"; }; }'缺少类型'IngressVideoOptions'的以下属性:name、equals、clone、fromBinary及另外7个属性。
相关代码:
if (ingressType === IngressInput.WHIP_INPUT) { options.bypassTranscoding = true; } else { options.video = { source: TrackSource.CAMERA, encodingOptions: { value: IngressVideoEncodingPreset.H264_1080P_30FPS_3_LAYERS, case: "preset", }, } }
修复方案
最新版LiveKit Server SDK中,IngressVideoOptions是Protobuf生成的类而非普通接口,不能直接用对象字面量赋值,必须通过类的构造函数或静态方法创建实例:
方法1:使用构造函数创建实例
import { IngressVideoOptions, IngressVideoEncodingPreset, TrackSource, IngressInput } from "livekit-server-sdk"; // ... if (ingressType === IngressInput.WHIP_INPUT) { options.bypassTranscoding = true; } else { options.video = new IngressVideoOptions({ source: TrackSource.CAMERA, encodingOptions: { case: "preset", value: IngressVideoEncodingPreset.H264_1080P_30FPS_3_LAYERS, }, }); }
方法2:使用fromPartial静态方法(推荐)
Protobuf生成的类通常提供fromPartial方法,允许传入部分属性创建实例:
// ... options.video = IngressVideoOptions.fromPartial({ source: TrackSource.CAMERA, encodingOptions: { case: "preset", value: IngressVideoEncodingPreset.H264_1080P_30FPS_3_LAYERS, }, });
额外检查
- 执行
npm list livekit-server-sdk确认SDK版本与官方文档一致 - 若仍有问题,删除
node_modules和package-lock.json后重新执行npm install
内容的提问来源于stack exchange,提问作者Mannu
相关产品推荐
相关产品推荐

