视频接口
Video 方法
| 方法 | 参数 | 响应 data | 说明 |
|---|---|---|---|
video.start | device_id: string 必填,width?: number,height?: number,fps?: number,pixel_format?: string=mjpeg,profile?: CaptureProfile | device_id,stream_id,session_token,pixel_format,width,height,fps | 创建视频流。 |
video.stop | device_id: string 必填 | device_id,stream_id,stopped: true | 停止当前连接下指定设备的视频流。 |
video.set_format | device_id: string 必填,pixel_format?: string=mjpeg,width?: number=1280,height?: number=720,fps?: number=15 | device_id,stream_id,pixel_format,width,height,fps | 更新当前 stream 格式。 |
video.set_profile | device_id: string 必填,profile: CaptureProfile 必填;profile.output 可包含 quality、target_size | device_id,page_processing,single_page,applied | 更新视频实时处理 profile,并缓存后续采集使用的输出参数。 |
pixel_format 支持 mjpeg、jpeg、bgr24;其中 jpeg 会归一为 mjpeg。video.start 未传 width、height、fps 时,会按 1280*720、15fps 注册 stream,最终返回值以 provider 实际选中的格式和分辨率为准。
CaptureProfile 对视频的影响
video.start 可以在创建视频流时应用 profile;video.set_profile 可以在视频流已启动后更新实时处理 profile。CaptureProfile 的完整结构请参考 采集接口 / CaptureProfile。
当前视频流实际使用的 CaptureProfile 字段:
| 字段 | 说明 |
|---|---|
capture.page_processing | 仅当值为 single_page 时,会启用单页实时识别相关逻辑。 |
capture.single_page.realtime_detect_rects | 是否开启实时识别框。开启后,stream.frame_meta 可能返回 detected_rects 和 detected_rects_source。 |
capture.single_page.multi_target_paging | 仅在实时识别框开启时生效,用于返回多个目标识别框。 |
output.quality | 缓存为后续 capture.take 或设备硬拍任务的 JPG/JPEG 输出质量,不影响当前 Video WS 帧质量。 |
output.target_size | 缓存为后续 capture.take 或设备硬拍任务的目标输出尺寸,不影响当前 Video WS 帧分辨率。 |
video.set_profile 要求指定设备的视频流已经启动;未启动时会返回 stream not ready 类错误。视频流分辨率仍通过 video.set_format 控制。需要设置 output.target_size 时,客户端应先读取 device.open.data.capture_output.target_sizes,再把选中的档位写入 profile.output.target_size。翻页自动检测目前没有公开 CaptureProfile 参数,暂不作为已支持的视频能力描述。
Video WS 帧事件
如需了解客户端如何配对 stream.frame_meta 与二进制帧并渲染到页面,请参考 设备与视频 / 渲染视频帧。
对外 SDK 默认使用 Video WSS:
wss://sdk-runtime.localhost:18091?session_token=<session_token>&stream_id=<stream_id>自定义 TLS 部署时,使用证书匹配的 wss://<tls-host>:18091;session_token 与 stream_id 查询参数不可省略。
每帧先推送 stream.frame_meta 文本事件,再推送二进制帧。二进制帧格式由当前 pixel_format 决定:mjpeg/jpeg 输出 JPEG 编码帧,bgr24 输出 BGR24 原始帧。
payload 字段:device_id、stream_id、frame_seq、timestamp_ms、width、height、pixel_format,可选 detected_rects 和 detected_rects_source。