You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 07:42:42