Video

[中文]

  • Component registry: espressif/brookesia_service_video

  • Helper header: #include "brookesia/service_helper/media/video.hpp"

  • Helper class: esp_brookesia::service::helper::Video

Overview

brookesia_service_video provides:

  • Encoding: Capture to compressed or raw formats (resolution, FPS, format per stream).

  • Decoding: H.264, MJPEG, and others to RGB/YUV for display or processing.

Features

Encoder

Input comes from a local video device (default /dev/video0; Kconfig can set path prefix and count).

Each output stream can be one of (per-stream resolution and FPS):

Type

Description

H.264

Common network/storage codec

MJPEG

Frame-wise JPEG-like compression

RGB565 / RGB888 / BGR888

RGB formats

YUV420 / YUV422 / O_UYY_E_VYY

YUV formats

Warning

Multiple simultaneous outputs are not supported yet.

Decoder

Compressed input and pixel output; configure per use case.

Input (Compressed)

Format

Description

H.264

Common video codec

MJPEG

Frame-wise JPEG stream

Output (Pixel)

Format

Description

RGB565 (BE/LE)

16-bit RGB for some panels/framebuffers

RGB888 / BGR888

24-bit RGB/BGR

YUV420P / YUV422P

Planar YUV for pipelines

YUV422 / UYVY422

Packed YUV for capture/display

O_UYY_E_VYY

Packed layout (hardware/pipeline dependent)

Standard Include / Helper Class

  • Standard include: #include \"brookesia/service_helper/media/video.hpp\"

  • Helper class: esp_brookesia::service::helper::Video

Service Interfaces

Functions

Encoder

Open
Description

Open the encoder with config. If display is set, sink format is derived from the selected Display output when Max; width/height are filled from the output area when zero. When stream mode is enabled, frames are emitted automatically through StreamSinkFrameReady; FetchFrame is only for non-stream mode.

Execution
  • Requires scheduler: Required

Parameters
  • Config

    • Type: Object

    • Required: required

    • Description: Encoder config. Example: {"sinks":[{"format":"H264","width":320,"height":240,"fps":30},{"format":"MJPEG","width":320,"height":240,"fps":15}],"enable_stream_mode":true,"source":{"device_path":"/dev/video0","fixed_format":"RGB565","fixed_width":320,"fixed_height":240,"v4l2_buffer_count":2},"display":{"output_name":"Output0","source_name":"Video","source_role":"video","x":0,"y":0,"draw_timeout_ms":1000,"publish_sink_event":false,"activate_source":true,"sink_index":0}}

Schema JSON
Show raw JSON

{
  "name": "Open",
  "description": "Open the encoder with config. If `display` is set, sink format is derived from the selected Display output when `Max`; width/height are filled from the output area when zero. When stream mode is enabled, frames are emitted automatically through `StreamSinkFrameReady`; `FetchFrame` is only for non-stream mode.",
  "require_scheduler": true,
  "default_timeout_ms": 2000,
  "parameters": [
    {
      "name": "Config",
      "description": "Encoder config. Example: {\"sinks\":[{\"format\":\"H264\",\"width\":320,\"height\":240,\"fps\":30},{\"format\":\"MJPEG\",\"width\":320,\"height\":240,\"fps\":15}],\"enable_stream_mode\":true,\"source\":{\"device_path\":\"/dev/video0\",\"fixed_format\":\"RGB565\",\"fixed_width\":320,\"fixed_height\":240,\"v4l2_buffer_count\":2},\"display\":{\"output_name\":\"Output0\",\"source_name\":\"Video\",\"source_role\":\"video\",\"x\":0,\"y\":0,\"draw_timeout_ms\":1000,\"publish_sink_event\":false,\"activate_source\":true,\"sink_index\":0}}",
      "type": "Object",
      "required": true,
      "default_value": null
    }
  ],
  "return_value": null
}
CLI Command
svc_call VideoEncoder0 Open {"Config":null}
Close
Description

Close encoder.

Execution
  • Requires scheduler: Not required

Parameters
  • No parameters.

Schema JSON
Show raw JSON

{
  "name": "Close",
  "description": "Close encoder.",
  "require_scheduler": false,
  "default_timeout_ms": null,
  "parameters": [],
  "return_value": null
}
CLI Command
svc_call VideoEncoder0 Close
Start
Description

Start encoder.

Execution
  • Requires scheduler: Required

Parameters
  • No parameters.

Schema JSON
Show raw JSON

{
  "name": "Start",
  "description": "Start encoder.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [],
  "return_value": null
}
CLI Command
svc_call VideoEncoder0 Start
Stop
Description

Stop encoder.

Execution
  • Requires scheduler: Not required

Parameters
  • No parameters.

Schema JSON
Show raw JSON

{
  "name": "Stop",
  "description": "Stop encoder.",
  "require_scheduler": false,
  "default_timeout_ms": null,
  "parameters": [],
  "return_value": null
}
CLI Command
svc_call VideoEncoder0 Stop
FetchFrame
Description

Fetch an encoder output frame and emit FetchSinkFrameReady. Only available in non-stream mode; stream mode emits StreamSinkFrameReady automatically.

Execution
  • Requires scheduler: Required

Parameters
  • SinkIndex

    • Type: Number

    • Required: optional

    • Default: 0E0

    • Description: Sink index.

Schema JSON
Show raw JSON

{
  "name": "FetchFrame",
  "description": "Fetch an encoder output frame and emit `FetchSinkFrameReady`. Only available in non-stream mode; stream mode emits `StreamSinkFrameReady` automatically.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [
    {
      "name": "SinkIndex",
      "description": "Sink index.",
      "type": "Number",
      "required": false,
      "default_value": 0.0
    }
  ],
  "return_value": null
}
CLI Command
svc_call VideoEncoder0 FetchFrame {"SinkIndex":null}

Decoder

Open
Description

Open the decoder with config. If display is set, sink format is derived from the selected Display output; width/height are used when non-zero, otherwise filled from the output area.

Execution
  • Requires scheduler: Required

Parameters
  • Config

    • Type: Object

    • Required: required

    • Description: Decoder config. Example: {"width":0,"height":0,"source_format":"MJPEG","sink_format":"Max","enable_stream_mode":true,"enable_hw_acceleration":true,"display":{"output_name":"Output0","source_name":"Video","source_role":"video","x":0,"y":0,"draw_timeout_ms":1000,"publish_sink_event":false}}

Schema JSON
Show raw JSON

{
  "name": "Open",
  "description": "Open the decoder with config. If `display` is set, sink format is derived from the selected Display output; width/height are used when non-zero, otherwise filled from the output area.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [
    {
      "name": "Config",
      "description": "Decoder config. Example: {\"width\":0,\"height\":0,\"source_format\":\"MJPEG\",\"sink_format\":\"Max\",\"enable_stream_mode\":true,\"enable_hw_acceleration\":true,\"display\":{\"output_name\":\"Output0\",\"source_name\":\"Video\",\"source_role\":\"video\",\"x\":0,\"y\":0,\"draw_timeout_ms\":1000,\"publish_sink_event\":false}}",
      "type": "Object",
      "required": true,
      "default_value": null
    }
  ],
  "return_value": null
}
CLI Command
svc_call VideoDecoder0 Open {"Config":null}
Close
Description

Close decoder.

Execution
  • Requires scheduler: Required

Parameters
  • No parameters.

Schema JSON
Show raw JSON

{
  "name": "Close",
  "description": "Close decoder.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [],
  "return_value": null
}
CLI Command
svc_call VideoDecoder0 Close
Start
Description

Start decoder.

Execution
  • Requires scheduler: Required

Parameters
  • No parameters.

Schema JSON
Show raw JSON

{
  "name": "Start",
  "description": "Start decoder.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [],
  "return_value": null
}
CLI Command
svc_call VideoDecoder0 Start
Stop
Description

Stop decoder.

Execution
  • Requires scheduler: Required

Parameters
  • No parameters.

Schema JSON
Show raw JSON

{
  "name": "Stop",
  "description": "Stop decoder.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [],
  "return_value": null
}
CLI Command
svc_call VideoDecoder0 Stop
FeedFrame
Description

Feed a decoder input frame.

Execution
  • Requires scheduler: Required

Parameters
  • Frame

    • Type: RawBuffer

    • Required: required

    • Description: Frame data.

Schema JSON
Show raw JSON

{
  "name": "FeedFrame",
  "description": "Feed a decoder input frame.",
  "require_scheduler": true,
  "default_timeout_ms": null,
  "parameters": [
    {
      "name": "Frame",
      "description": "Frame data.",
      "type": "RawBuffer",
      "required": true,
      "default_value": null
    }
  ],
  "return_value": null
}
CLI Command
svc_call VideoDecoder0 FeedFrame {"Frame":null}

Events

Encoder

StreamSinkFrameReady
Description

Emitted when an encoder stream frame is ready. Stream mode only.

Execution
  • Requires scheduler: Not required

Items
  • SinkIndex

    • Type: Number

    • Description: Sink index.

  • SinkInfo

    • Type: Object

    • Description: Sink info. Example: {"format":"H264","width":320,"height":240,"fps":30}

  • Frame

    • Type: RawBuffer

    • Description: Encoded frame data.

Schema JSON
Show raw JSON

{
  "name": "StreamSinkFrameReady",
  "description": "Emitted when an encoder stream frame is ready. Stream mode only.",
  "require_scheduler": false,
  "items": [
    {
      "name": "SinkIndex",
      "description": "Sink index.",
      "type": "Number"
    },
    {
      "name": "SinkInfo",
      "description": "Sink info. Example: {\"format\":\"H264\",\"width\":320,\"height\":240,\"fps\":30}",
      "type": "Object"
    },
    {
      "name": "Frame",
      "description": "Encoded frame data.",
      "type": "RawBuffer"
    }
  ]
}
CLI Command
svc_subscribe VideoEncoder0 StreamSinkFrameReady
FetchSinkFrameReady
Description

Emitted when an encoder fetched frame is ready. Non-stream mode only.

Execution
  • Requires scheduler: Not required

Items
  • SinkIndex

    • Type: Number

    • Description: Sink index.

  • SinkInfo

    • Type: Object

    • Description: Sink info. Example: {"format":"MJPEG","width":320,"height":240,"fps":15}

  • Frame

    • Type: RawBuffer

    • Description: Encoded frame data.

Schema JSON
Show raw JSON

{
  "name": "FetchSinkFrameReady",
  "description": "Emitted when an encoder fetched frame is ready. Non-stream mode only.",
  "require_scheduler": false,
  "items": [
    {
      "name": "SinkIndex",
      "description": "Sink index.",
      "type": "Number"
    },
    {
      "name": "SinkInfo",
      "description": "Sink info. Example: {\"format\":\"MJPEG\",\"width\":320,\"height\":240,\"fps\":15}",
      "type": "Object"
    },
    {
      "name": "Frame",
      "description": "Encoded frame data.",
      "type": "RawBuffer"
    }
  ]
}
CLI Command
svc_subscribe VideoEncoder0 FetchSinkFrameReady

Decoder

SinkFrameReady
Description

Emitted when a decoder output frame is ready.

Execution
  • Requires scheduler: Not required

Items
  • Width

    • Type: Number

    • Description: Decoded frame width.

  • Height

    • Type: Number

    • Description: Decoded frame height.

  • Frame

    • Type: RawBuffer

    • Description: Decoded frame data.

Schema JSON
Show raw JSON

{
  "name": "SinkFrameReady",
  "description": "Emitted when a decoder output frame is ready.",
  "require_scheduler": false,
  "items": [
    {
      "name": "Width",
      "description": "Decoded frame width.",
      "type": "Number"
    },
    {
      "name": "Height",
      "description": "Decoded frame height.",
      "type": "Number"
    },
    {
      "name": "Frame",
      "description": "Decoded frame data.",
      "type": "RawBuffer"
    }
  ]
}
CLI Command
svc_subscribe VideoDecoder0 SinkFrameReady