Skip to content

RFC: Standard video encoder controls #122374

Open

Description

@changyeon-jo

Introduction

Zephyr now has in-tree hardware video encoders: H.264 (video_stm32_venc, #92884) and JPEG (video_stm32_jpeg, #96678). Samples such as samples/subsys/video/tcpserversink and the UVC sample select them with the zephyr,videoenc chosen node.

Applications can start an encoder and feed it frames, but cannot configure how it encodes. Rate control, bitrate, GOP length, profile/level and key-frame requests are all fixed inside the driver.

Revision 4 (2026-10-17): following the discussion below, the software H.264 encoder originally proposed here has been dropped from this RFC. The controls now land with video_stm32_venc as their first user.

Update (2026-10-19): software codecs are out of scope for this RFC. Since in-tree code can't depend on an external module, a software encoder would most likely need to be a default module in the main manifest (like mbedtls). That is a separate discussion; see the comments below and #108889.

Update (2026-11-20): the implementation is in draft PR #123737, on top of #96393. The implementation plan, the video_stm32_venc defaults and the test plan below are updated to match.

This RFC proposes:

  1. a small set of standard encoder controls in the existing, still empty, VIDEO_CID_CODEC_CLASS_BASE class, with numeric IDs and semantics identical to the Linux V4L2 stateful codec controls;
  2. an encoder conformance test that runs against any zephyr,videoenc device, so that hardware encoders can be validated the same way on any board.

Problem description

  • No standard controls. controls.h defines VIDEO_CID_CODEC_CLASS_BASE (0x00990900, "Stateful codec controls IDs"), but no CID uses it. The only encoder control today is VIDEO_CID_JPEG_COMPRESSION_QUALITY in the JPEG class.
  • Encoder parameters are hardcoded. For example, video_stm32_venc currently:
    • runs with rate control disabled and a fixed QP of 25 for every frame;
    • emits an IDR frame every 30 frames;
    • uses H.264 level 4.0 and leaves the profile unset;
    • assumes 30 fps and does not implement set_frmival.
  • Common use cases are blocked. Streaming over a limited or lossy link (Wi-Fi, BLE, shared USB bandwidth, cellular through a phone) typically needs:
    • a target bitrate that can be changed while streaming;
    • an immediate key frame after packet loss or when a client joins;
    • a GOP length that trades recovery time against bitrate;
    • a profile/level that the receiver can decode.
  • No portability. Without standard CIDs, each encoder driver would invent private controls. Applications, the video shell and a future multimedia pipeline encoder element (mpipe element: zvid_transform (jpegenc/h264enc/...) #105284) could not configure encoders generically.

Proposed change

  1. Add a VIDEO_CTRL_TYPE_BUTTON control type for write-only action controls (via the revived video: Improve control framework #96393).
  2. Add codec CIDs to include/zephyr/video/controls.h under VIDEO_CID_CODEC_CLASS_BASE. Numeric IDs, menu values and semantics are identical to Linux. The names drop the legacy MPEG_VIDEO_ infix (see Naming).
  3. Teach drivers/video/video_common.c the type of each new CID and the standard menu strings.
  4. Define which controls may change while streaming.
  5. Add tests/subsys/video/encoder, a conformance test for any zephyr,videoenc device.
  6. Implement the controls in video_stm32_venc. The defaults reproduce today's behavior, so existing users see no change.
  7. Use the existing set_frmival / get_frmival ops on the encoder to set the nominal frame rate, which rate control needs.

The controls, the video_stm32_venc implementation and the conformance test are in draft PR #123737.

Detailed RFC

Naming

controls.h currently reuses the Linux CID names verbatim. For the codec class, this RFC proposes to keep the numeric IDs and menu values identical to Linux but drop the MPEG_VIDEO_ infix:

  • Generic encoder controls become VIDEO_CID_CODEC_*, matching the class name VIDEO_CID_CODEC_CLASS_BASE.
  • H.264-specific controls become VIDEO_CID_H264_*.

Rationale:

  • Linux itself renamed this class from MPEG to CODEC (V4L2_CID_CODEC_BASE, with V4L2_CID_MPEG_BASE kept as an alias). Only the per-control names still carry MPEG_VIDEO_ for UAPI compatibility.
  • Zephyr has no such compatibility constraint for this class, because it is empty.
  • Each CID's Doxygen comment names its Linux equivalent, so cross-referencing stays easy. The header's "same name as Linux" note would be amended to describe this exception.

Example:

/**
 * Rate control mode, see enum video_codec_bitrate_mode.
 * Same ID and values as V4L2_CID_MPEG_VIDEO_BITRATE_MODE.
 */
#define VIDEO_CID_CODEC_BITRATE_MODE (VIDEO_CID_CODEC_CLASS_BASE + 206)

enum video_codec_bitrate_mode {
	VIDEO_CODEC_BITRATE_MODE_VBR = 0,
	VIDEO_CODEC_BITRATE_MODE_CBR = 1,
	VIDEO_CODEC_BITRATE_MODE_CQ = 2,
};

/**
 * Target bitrate in bits per second.
 * Same ID as V4L2_CID_MPEG_VIDEO_BITRATE.
 */
#define VIDEO_CID_CODEC_BITRATE (VIDEO_CID_CODEC_CLASS_BASE + 207)

CIDs

All IDs are VIDEO_CID_CODEC_CLASS_BASE + offset, numerically equal to the Linux control in the last column.

Zephyr CID Offset Value Type Change while streaming Linux equivalent
VIDEO_CID_CODEC_GOP_SIZE 203 0x009909cb INTEGER Yes, from next IDR V4L2_CID_MPEG_VIDEO_GOP_SIZE
VIDEO_CID_CODEC_BITRATE_MODE 206 0x009909ce MENU: VBR=0, CBR=1, CQ=2 No ..._BITRATE_MODE
VIDEO_CID_CODEC_BITRATE 207 0x009909cf INTEGER (bit/s) Yes ..._BITRATE
VIDEO_CID_CODEC_FRAME_RC_ENABLE 215 0x009909d7 BOOLEAN No ..._FRAME_RC_ENABLE
VIDEO_CID_CODEC_HEADER_MODE 216 0x009909d8 MENU: SEPARATE=0, JOINED_WITH_1ST_FRAME=1 No ..._HEADER_MODE
VIDEO_CID_CODEC_MB_RC_ENABLE 218 0x009909da BOOLEAN No ..._MB_RC_ENABLE
VIDEO_CID_CODEC_FORCE_KEY_FRAME 229 0x009909e5 BUTTON Yes ..._FORCE_KEY_FRAME
VIDEO_CID_H264_I_FRAME_QP 350 0x00990a5e INTEGER 0..51 Yes ..._H264_I_FRAME_QP
VIDEO_CID_H264_P_FRAME_QP 351 0x00990a5f INTEGER 0..51 Yes ..._H264_P_FRAME_QP
VIDEO_CID_H264_MIN_QP 353 0x00990a61 INTEGER 0..51 Yes ..._H264_MIN_QP
VIDEO_CID_H264_MAX_QP 354 0x00990a62 INTEGER 0..51 Yes ..._H264_MAX_QP
VIDEO_CID_H264_LEVEL 359 0x00990a67 MENU (1.0=0 ... 4.0=11 ... 6.2=19) No ..._H264_LEVEL
VIDEO_CID_H264_PROFILE 363 0x00990a6b MENU (BASELINE=0, CONSTRAINED_BASELINE=1, MAIN=2, EXTENDED=3, HIGH=4, ...) No ..._H264_PROFILE
VIDEO_CID_CODEC_PREPEND_SPSPPS_TO_IDR 644 0x00990b84 BOOLEAN No ..._PREPEND_SPSPPS_TO_IDR
VIDEO_CID_CODEC_CONSTANT_QUALITY 645 0x00990b85 INTEGER 0..100 Yes ..._CONSTANT_QUALITY

Semantics follow Linux:

  • Rate control off (FRAME_RC_ENABLE=0): each frame uses H264_I_FRAME_QP or H264_P_FRAME_QP where supported. BITRATE_MODE and BITRATE are ignored.
  • Rate control on (FRAME_RC_ENABLE=1):
    • CBR or VBR targets BITRATE;
    • CQ targets CONSTANT_QUALITY;
    • H264_MIN_QP and H264_MAX_QP clamp the QP chosen by rate control.
  • GOP_SIZE is the distance between IDR frames. Linux does not document the value 0. This RFC proposes that 0 means only the first frame is an IDR, with further IDRs only on request.
  • FORCE_KEY_FRAME makes the next encoded frame an IDR.
  • HEADER_MODE: SEPARATE returns SPS/PPS in their own first buffer. JOINED_WITH_1ST_FRAME prepends them to the first frame.
  • PREPEND_SPSPPS_TO_IDR repeats SPS/PPS before every IDR. A receiver can then join mid-stream, and a forced key frame decodes on its own.

A driver registers only the controls it really implements, and menu controls may declare a narrower range or skip mask than the standard menu. For example, video_stm32_venc offers SEPARATE headers only.

Why GOP_SIZE and not H264_I_PERIOD

Linux has both controls, but they are not true duplicates:

  • GOP_SIZE comes from the original MPEG-2 capture-card controls, where a GOP starts at every I-frame.
  • H264_I_PERIOD was added later for H.264 open GOP. Linux documents it as "the period between two I-frames" inside an open GOP, while "the period between IDR frames is taken from the GOP_SIZE control". The non-IDR I-frames in between are not clean random-access points.

Drivers are inconsistent in practice:

  • wave5 maps GOP_SIZE to the IDR period and H264_I_PERIOD to the intra period.
  • s5p-mfc applies H264_I_PERIOD only in open-GOP mode.
  • mediatek and venus register both with driver-specific meanings.

Our target use cases (loss recovery and late join) need IDR frames. GOP_SIZE is also the control that every Linux encoder driver implements. This RFC therefore defines only VIDEO_CID_CODEC_GOP_SIZE, as the IDR period. H264_I_PERIOD (and the similar HEVC_REFRESH_PERIOD) can be added later if an encoder needs open-GOP support.

Framework changes (video_common.c, video.h)

  • New VIDEO_CTRL_TYPE_BUTTON:
    • it has no stored value, and video_get_ctrl() returns -EACCES;
    • video_set_ctrl() calls the driver's set_ctrl to trigger the action, and the written value is ignored;
    • the video shell lists it as (button) and accepts video ctrl <dev> <name> without a value;
    • it mirrors V4L2_CTRL_TYPE_BUTTON.
    • video: Improve control framework #96393 adds this type, together with a VIDEO_CTRL_FLAG_EXECUTE_ON_WRITE flag. This RFC builds on it rather than introducing a separate design.
  • Type mapping: extend set_type_flag() for the new CIDs.
  • Standard menus: add menu strings for BITRATE_MODE, HEADER_MODE, H264_LEVEL and H264_PROFILE to video_get_std_menu_ctrl(), so drivers can leave the menu unset when they register the control with video_register_ctrl() (video: Improve control framework #96393).
  • Changes while streaming: changing a "No" control while streaming returns -EBUSY. The driver enforces this, since it owns the streaming state. A framework-level flag could be added later.

Frame rate

Rate control needs the nominal input frame rate. This RFC reuses video_set_frmival() / video_get_frmival() on the encoder device rather than adding a codec CID. This matches Linux stateful encoders, which take the frame interval on the raw (OUTPUT) queue. Encoders without rate control may leave these ops unimplemented.

Software implementations

Software codec implementations are out of scope for this RFC and would not go into the main tree directly. Since in-tree code can't depend on an external module, the likely route is a default module in the main manifest (like mbedtls), which goes through Zephyr's external-source process; #108889 discusses this for JPEG. Any such encoder exposed as a zephyr,videoenc device can use these CIDs and run the conformance test below unchanged.

video_stm32_venc mapping

The defaults keep today's behavior. Values marked proposed are the ones #123737 uses; input from the driver maintainers is welcome:

Control Default Current hardcoded behavior
CODEC_FRAME_RC_ENABLE 0 pictureRc = 0
CODEC_MB_RC_ENABLE 0 mbRc = 0
H264_I_FRAME_QP, H264_P_FRAME_QP 25 qpHdr = 25
H264_MIN_QP, H264_MAX_QP 10, 51 (proposed; only used with rate control on) qpMin = qpMax = 25
CODEC_GOP_SIZE 30 IDR when frame_nb % 30 == 0
H264_LEVEL 4.0 H264ENC_LEVEL_4
CODEC_HEADER_MODE SEPARATE (only value) SPS/PPS returned as the first buffer
H264_PROFILE MAIN (proposed) not set
CODEC_BITRATE_MODE, CODEC_BITRATE VBR, 1 Mbit/s (proposed; only used with rate control on) not used
frame interval 1/30 VENC_DEFAULT_FRAMERATE

video_stm32_venc registers 14 of the 15 controls; it leaves out CODEC_CONSTANT_QUALITY.

Controls marked "No" are applied when the encoder is configured at stream start. Runtime controls are applied between frames:

  • BITRATE and the QP limits go through the encoder's rate-control update call.
  • FORCE_KEY_FRAME forces the next frame to be an IDR, as the driver already does on resync.

Implementation plan

The work is in two PRs:

PR Contents Depends on
#96393 (ngphibang) Button control type, VIDEO_CTRL_FLAG_EXECUTE_ON_WRITE, and video_register_ctrl() in place of video_init_ctrl() –
#123737 (draft) Video shell support for button controls; the 15 CIDs with their types, menus and names, plus API tests; video_stm32_venc frame interval; video_stm32_venc controls; the conformance test #96393

An earlier revision planned a series of six small PRs. They were combined so that the controls, their first user and the test can be reviewed together. #123737 can still be split by control group if reviewers prefer.

The video_stm32_venc changes are build-tested only. Validation on hardware, by the ST maintainers or anyone with the board, is still needed.

Dependencies

  • The series touches include/zephyr/drivers/video.h, include/zephyr/video/controls.h, drivers/video/video_common.c, subsys/video/ctrls.c, subsys/video/shell.c and drivers/video/video_stm32_venc.c, and adds tests/subsys/video/encoder/.
  • There is no API break, because the codec class is currently empty.
  • video_stm32_jpeg is unaffected and keeps VIDEO_CID_JPEG_COMPRESSION_QUALITY.
  • A multimedia pipeline encoder element (mpipe element: zvid_transform (jpegenc/h264enc/...) #105284) is planned as a thin wrapper around a memory-to-memory video device; it could expose these CIDs as element properties. Neither proposal depends on the other.

Concerns and unresolved questions

  1. Naming. Is the proposed exception (Linux IDs, MPEG-free names) acceptable to the video maintainers? The alternative is Linux names verbatim (VIDEO_CID_MPEG_VIDEO_H264_PROFILE).

  2. Runtime changes. The "Change while streaming" column is a proposal. Is switching BITRATE_MODE while streaming worth supporting on any known hardware?

  3. Later scope. Candidates include:

    • BITRATE_PEAK (VBR cap), once an encoder implements it;
    • B-frames;
    • slices (MULTI_SLICE_*);
    • VBV size;
    • intra refresh;
    • AU delimiters;
    • frame skip mode;
    • H264_I_PERIOD / open GOP;
    • HEVC and VP8 controls;
    • per-frame QP or ROI metadata.

    Does any of these belong in the initial series?

  4. JPEG. Proposal: keep VIDEO_CID_JPEG_COMPRESSION_QUALITY as is, rather than reconciling it with CODEC_CONSTANT_QUALITY for MJPEG-style encoders.

  5. stm32_venc defaults. video: add standard encoder controls and stm32_venc support #123737 proposes the Main profile, VBR and 1 Mbit/s for video_stm32_venc. Are these the right defaults? Input from the driver maintainers is welcome.

Alternatives

  • Vendor-private CIDs per driver. Simple for each driver, but applications, the shell and pipeline elements would need driver-specific code.
  • Kconfig or devicetree properties. Build-time defaults only. They cannot provide runtime bitrate adaptation or on-demand key frames, which are the main use cases.
  • A dedicated struct-based encoder API (e.g. video_encoder_config). More type-safe, but it duplicates the control framework, diverges from V4L2, and needs new ops in every driver. Controls come with shell support and control clusters for free.
  • BOOLEAN + WRITE_ONLY for key-frame requests. Needs no new type, but gives the shell and applications a misleading value to write and read. BUTTON also serves future action controls.
  • A software encoder in the main tree for CI (originally proposed here). Dropped: a non-compressing one adds maintenance without being useful on its own, and a real one is an external library, which would come in as a module rather than as main-tree code (see the discussion).

Test plan

  • API tests (tests/subsys/video/api):

    • BUTTON type behavior (set triggers the driver, get is rejected);
    • the new CIDs get the correct types and flags;
    • the standard menus resolve (names and counts);
    • range and skip-mask validation.
  • Encoder conformance test (tests/subsys/video/encoder). Encodes synthetic NV12 frames and parses NAL unit headers on the target, so it needs no camera and no host tools. Planned cases:

    Case Check
    stream header first buffer (SEPARATE) or first IDR (JOINED) carries SPS and PPS
    default GOP IDR exactly every GOP_SIZE frames
    force key frame IDR on the frame after the button
    header placement SPS/PPS placement matches HEADER_MODE and PREPEND_SPSPPS_TO_IDR
    profile and level SPS profile_idc, constraint flags and level_idc match the controls
    bitrate mean P-frame size within a loose band of BITRATE / fps; changing BITRATE while streaming changes it accordingly
    constant quality P-frame size grows with CONSTANT_QUALITY
    restart stop and start produce a new header and IDR

    video: add standard encoder controls and stm32_venc support #123737 implements these except the constant quality case, which video_stm32_venc cannot run, and adds cases for the frame interval, a configured GOP size, fixed-QP encoding and the input formats.

    A case is skipped, not failed, when the device does not register the control, so the same suite runs on every encoder.

  • Where it runs: any board with a zephyr,videoenc device. Today that is stm32n6570_dk with video_stm32_venc: built in CI, run on hardware by the ST maintainers or any lab with the board (west twister -T tests/subsys/video/encoder -p stm32n6570_dk/stm32n657xx/sb --device-testing). A software encoder, if one is later added as a module, would run it on native_sim and QEMU.

  • Build coverage: stm32n6570_dk builds of samples/subsys/video/tcpserversink and the UVC sample with the H.264 encoder enabled.

  • Optional manual check: on hardware, stream with tcpserversink and inspect with ffprobe or GStreamer.

Activity

  1. github-actions commented on Oct 15, 2026

    @github-actions

    Hi @changyeon-jo! We appreciate you submitting your first issue for our open-source project. 🌟

    Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

  2. changyeon-jo commented on Oct 15, 2026

    @changyeon-jo
    Author

    Prior art I missed when writing this up:

    I've updated the description accordingly.

  3. ngphibang commented on Oct 16, 2026

    @ngphibang
    Contributor

    Hi @changyeon-jo ,

    Thanks for the proposal. At 1st glance, I think that makes sense, except the point 2:

    2. a minimal, non-compressing software H.264 encoder.

    I think adding a non-compressing SW-based H.264 simulator just to test the added APIs will add more and more burden to the maintenance. We already have sw_generator, sw_generator_fifo, imaging_emulator, rx_emulator, etc. (but those are at least helpful to generate / receive the test patterns). IMHO, either we add a real SW-based H.264 encoder/decoder (e.g. based on OpenH264 ? but this will be complicated as it is an external to Zephyr) or do not add it.

    Regarding #96393, I will revive it. Thank you for the reminder as I completely forgot about it.

  4. changyeon-jo commented on Oct 16, 2026

    @changyeon-jo
    Author

    Thanks @ngphibang for the quick feedback, and for reviving #96393!

    That's a fair point: a non-compressing encoder would add maintenance without being useful on its own. Before dropping the software encoder from this RFC, would you be open to a real one instead? We'd be happy to go with either of these, whichever you and @josuah prefer:

    • minih264e: single-file C with caller-provided memory, which fits MCUs well, and real Baseline compression with frame- and macroblock-level rate control. CC0, but upstream has been inactive since 2020, so we would maintain a fork.
    • OpenH264: actively maintained and widely used, and it also includes a decoder. BSD-2, but it is C++, much larger, and expects heap allocation and threads.

    Either would go through the external-source process, and would replace the bitstream writer in the prototype while the driver, snippet and test stay. If neither fits, I'll drop the software encoder and land the controls with video_stm32_venc as their first user.

    What would you prefer?

  5. josuah commented on Oct 17, 2026

    @josuah
    Contributor

    SoCs need good multimedia simulation support so thanks for looking into this :)

    There might be mixed hardware/software encoders, like vector-based or GPUs-based. Then it is a different project: a h.264 toolkit to work with the format.

    Ultimately, there might be a lot of such libraries needed: H.265/VP8/9/AV1/png/jpeg/mp3/opus encoders/decoders are present on SoCs that can run Zephyr, and sometimes parsing a bit of the format is useful for various purposes, testing, detection, debugging.

    For various DSP processing there is https://github.com/zephyrproject-rtos/zscilib

    Espressif went with external components like GMF (very different features though) or camera support.

    Then actual low overhead implementations (i.e. made for SRAM/PSRAM rather than huge DDR + cache) can be gathered in one repo along with a matching mpipe plugin and zephyr integration, and its own hardware test suite?

    Then Zephyr maintainers could ask for contributing the missing pieces in such a repo to declare hardware support as complete.

  6. changed the title [-]RFC: Standard video encoder controls, with a reference software encoder[/-] [+]RFC: Standard video encoder controls[/+] on Oct 17, 2026
  7. changyeon-jo commented on Oct 17, 2026

    @changyeon-jo
    Author

    Thanks @josuah, that makes a lot of sense. A separate repository for MCU-oriented codec implementations (SRAM/PSRAM rather than DDR), with an mpipe plugin, Zephyr integration and its own test suite, would keep codec code and its maintenance out of the main tree. Would libmpix be a good home, since it already has a JPEG encoder and the same low-memory focus, or would you rather start a new repository?

    Two corrections to my earlier comment:

    • Please disregard minih264e as an option. Its CC0 dedication isn't an OSI-approved license, so it wouldn't pass Zephyr's external-source policy, and I'm not in a position to contribute to it either. Of the two, only OpenH264 (BSD-2) remains viable, and I'd first want to check how it fits SRAM-class targets before proposing it anywhere.
    • I had framed this as a choice for this RFC; given your feedback, I'd rather decouple it.

    I've updated the description accordingly (revision 4):

    • the controls land with video_stm32_venc as their first user, plus the encoder test in tests/subsys/video/encoder for boards with an encoder (building on the revived video: Improve control framework #96393 for the button type);
    • the software H.264 encoder is dropped from the RFC; any software codec work goes to the separate repository instead.

    @ngphibang, does that work for you?

  8. ngphibang commented on Oct 19, 2026

    @ngphibang
    Contributor

    @changyeon-jo Yes, I think so. For the choice of a H.264 library, it seems OpenH264 is good as it offers both encoding and decoding (but maybe there is another better candidate, I am not sure about this).

    However, integrating an (H.264) external library into Zephyr as a module may be something a bit beyond the video domain itself I think. I see some difficulties for other libraries such as for libsrtp #99132 (then it seems working well when coming as a native implementation though #118474) and libopus.

    For mpipe, we also tend to integrate the Bitbank Jpeg encoder / decoder as a default module to be used by mpipe's img plugin.
    #108889.

    Would libmpix be a good home, since it already has a JPEG encoder and the same low-memory focus, or would you rather start a new repository?

    AFAIU, libmpix is an "external" module (not default and not optional neither), so it seems nothing in the Zephyr tree may use it ? If so, the H.264 library should be integrated as a "default" module (in the manifest, like mbedtls) ?

  9. changyeon-jo commented on Oct 19, 2026

    @changyeon-jo
    Author

    Thanks @ngphibang, that's helpful.

    • I'll go ahead with the controls as in revision 4. One challenge: I don't have an STM32N6570-DK, so I can build-test the video_stm32_venc changes and the encoder test, but not run them. Could you or @josuah advise how to get them validated on hardware? Would avolmat-st or hfruchet-st be the right people to ask? The button type will build on video: Improve control framework #96393 once you've reopened it.
    • Thanks for the pointers on module integration. Agreed that a default module in the main manifest (like mbedtls) seems to be the only mode that lets something in the tree use it, and that it's a wider decision than the video area. I'll look into what that would take for OpenH264 before proposing anything, and follow the JPEGDEC discussion in mpipe: Add img plugin #108889 since it's the same question.
    • On JPEG: I see @chemag is already working on JPEGDEC/JPEGENC as Zephyr integration forks, so I won't start a separate software JPEG encoder. Happy to help there instead, e.g. by wrapping it as a zephyr,videoenc device for the controls work, if that's useful.
  10. chemag commented on Oct 19, 2026

    @chemag

    Hi, @changyeon-jo ,

    As discussed in the img plugin patch (PR#108889), we have updated version and the glue to integrate jpegenc/jpegdec. Right now you can find all the code in https://github.com/chemag/zephyr/tree/jpeg_codec_integration This is Phi Bang's code but with the jpegdec moved to a separate west module, and with the addition of a jpegenc module. We have tests for raw->encoder->decoder->raw and jpeg->decoder->encoder->jpeg, for different pixel formats.

    The patches depend on having 2x new west modules, jpegenc and jpegdec, coming from bitbank2/jpegenc and bitbank2/jpegdec respectively. They are good candidates for zephyr: jpeg codecs oriented to embedded system, with controlled memory access.

    I added some fixes to both packages (see chemag/jpegenc and chemag/jpegdec). I sent the patches upstream, but upstream declined the patches under its contribution policy. As possible alternatives, we can just fork both repos into west modules, and then I'll send my patches for review. Or we can use my repos as (forked) upstream.

  11. chemag commented on Oct 19, 2026

    @chemag

    Hi again @changyeon-jo ,

    I'm also working on software H.264 encoder and decoder integration, and I'd love to compare notes.

    My goal is to build a WebRTC-compatible Zephyr client that can make bidirectional audio/video calls between a browser and an RT1170 board with an attached camera and display. Thanks to @ngphibang for helping with the board.

    Porting a full WebRTC implementation seems too heavy for this target, so I'm using libpeer instead. Browser WebRTC does not negotiate MJPEG, so I'm using software H.264 codecs. Audio currently uses PCMU, although I may evaluate Opus later.

    The work is progressing well. I have sustained bidirectional calls for more than ten minutes, with audio and video active in both directions. I am still investigating intermittent whole-board lockups that prevent longer qualification. The measured M7 die temperature remains between 41 and 44 °C, so on-die thermal shutdown looks unlikely; software, bus-level, and board-level power or heat-soak causes are still under investigation.

    Quality is currently modest, but the immediate goal is to demonstrate that the architecture works. Longer term, I expect to use a board with hardware video encoding and decoding.

    Current media parameters:

    • Video: 320×240 at 5 fps in both directions, using H.264. The board's software encoder emits all-IDR frames.
    • Audio on the wire: PCMU/G.711 μ-law, 8 kHz, mono, with 20 ms packets-160 samples per packet, or 50 packets/s. Board capture: 16 kHz, stereo, 32-bit DMIC samples, reduced to 8 kHz mono PCMU. Board playback: Received PCMU expanded to 16 kHz, stereo, 16-bit PCM through WM8962/I2S. Browser capture: The mic audio track runs at 48 kHz, mono, 16-bit; WebRTC converts it to the negotiated 8 kHz mono PCMU stream.

    Regarding the software H.264 codecs:

    • For encoding, I also found MiniH264E to be a good fit for embedded systems. It is intentionally limited compared with OpenH264, but an encoder can target a constrained, compliant H.264 subset. I expect this encoder to be most useful for testing and prototyping; production systems will generally want a hardware encoder for power and performance reasons.

    I understand there may be licensing constraints or concerns around including it in Zephyr. Could we compare what constraints you found and discuss possible paths forward?

    I needed several patches to integrate it: https://github.com/chemag/minih264/tree/webrtc-zephyr-integration

    I have not found OpenH264 practical within the current RT1170 CPU and memory budget. It is a much more complete encoder and decoder implementation, so I would be interested in comparing measurements if you have tried it on a similar target.

    The demo also requires several libpeer changes, which I plan to send upstream, plus two independent fixes in Zephyr's NXP MCUX-backed drivers:

    • (1) Account for every coalesced cyclic eDMA completion and issue one callback per completed TCD, preventing queue-slot and slab-buffer leakage.
    • (2) Keep MCUX SAI TX in the RUNNING state when its queue empties so a later i2s_write() can reload DMA and resume without PREPARE.

    Both fixes pass focused RT1170 hardware regressions, although neither has been shown to cause the separate whole-board lockup.

    It would be great to compare scope, status, and interfaces so we can reuse each other's work and avoid duplication.

    Regards,
    -Chema

  12. changyeon-jo commented on Oct 19, 2026

    @changyeon-jo
    Author

    Thanks @chemag, great to see this, and a WebRTC call is a very good use case for the controls in this RFC: bitrate changes from congestion feedback, a key frame on PLI, and a GOP setting instead of all-IDR.

    JPEG: I'll have a look at jpeg_codec_integration. Since upstream declined the patches, forking them as modules under zephyrproject-rtos seems like the natural route, and it's what the module process expects anyway (a zephyr branch on top of upstream). Happy to review or test.

    H.264 licensing, what I found:

    • minih264e is a CC0 dedication, not an OSI-approved license, so it fails Zephyr's external-source policy. My employer's open-source policy also doesn't allow me to contribute to public-domain-dedicated projects, including CC0, which is why I dropped it.
    • OpenH264 is BSD-2-Clause: OSI-approved, but non-Apache, so it needs TSC approval plus a governing-board review.
    • h264bsd's sources are Apache-2.0 (from AOSP), so as a decoder it would only need TSC approval.

    Measurements from local prototypes (encoder only, portable C without the libraries' SIMD code, single-threaded, Constrained Baseline, one spatial layer):

    • OpenH264, with Allocate downsampling sample buffers on first use cisco/openh264#4054:
      • Code: about 191 KiB of text in libopenh264.a, built for Cortex-M33 (mps2/an521) at -Os in a Zephyr build, before the linker drops unused sections.
      • Heap: peak about 1.0 MB at 256×192, 1.4 MB at 320×240 and 4.4 MB at 640×480, measured on host builds with glibc's allocator statistics. 32-bit and 64-bit builds agree within 1%, and the Zephyr encoder test at 256×192 passes with a 1.25 MiB malloc arena.
      • Rate control: 497 kbit/s for a 500 kbit/s target, on a synthetic moving test sequence at 320×240 and 30 fps (host build).
    • libavc (Ittiam, used by Android, Apache-2.0, encoder and decoder) also looks promising. It's plain C, and the caller provides all memory, which would fit the bounded-heap approach you used for h264bsd. On the same host test sequences, quality and bitrate accuracy are similar to OpenH264. The memory it requests from the caller is about 2.8 MB at 320×240 with the default build, and about 1.4 MB once a few compile-time table sizes are reduced.
    • OpenH264 runs on native_sim, qemu_x86 and mps2/an521 (QEMU); libavc so far only on the host. I haven't measured CPU load on real hardware, so I'd be very interested in your RT1170 numbers, e.g. frames per second and heap for minih264e at QVGA.

    On interfaces: if the software encoders are exposed as zephyr,videoenc devices, they can share the controls from this RFC and the encoder test, whichever library ends up behind them. Maybe we can keep the module discussion in #108889 so that JPEG and H.264 follow the same pattern?

  13. ngphibang commented on Oct 20, 2026

    @ngphibang
    Contributor

    @chemag: Maybe FYI, performances of x264 & ffmpeg encoder/decoder on i.MX RT (they tried TCM):
    https://www.nxp.com/docs/en/application-note/AN13205.pdf
    https://www.nxp.com/docs/en/application-note/AN12562.pdf

    We tried H.264 decoding on our Android screen mirror demo but the performance was not good so that's why we switched to MJPEG.

  14. changyeon-jo commented on Oct 20, 2026

    @changyeon-jo
    Author

    Thanks @ngphibang, these are useful reference points.

    • AN13205 (encode, RT1170 Cortex-M7 at 1 GHz): x264 ultrafast, Baseline, 23.5 fps at 480x272 and 28.8 fps at 352x288, with hot code in ITCM and data in SDRAM. Running from flash (XIP) is about 2.4x slower, so code placement matters as much as the encoder choice.
    • AN12562 (decode, RT1050 Cortex-M7 at 600 MHz): FFmpeg, 21.9 fps at 720x576 and 34.2 fps at 480x272, including PXP color conversion and display. Keeping the PXP buffers in on-chip RAM instead of SDRAM made that step about 6x faster.

    Both use GPL/LGPL code (x264, FFmpeg), which, if I understand the external-source policy correctly, would make them hard to bring in as Zephyr modules. That's one reason I've also been looking at libavc (Apache-2.0). My numbers so far come only from QEMU (instruction counts, not cycles), so they aren't directly comparable with these. A run on real hardware would be the right next step once there's something to share.

    Good to know about MJPEG for the screen-mirror case, too.

  15. changyeon-jo commented on Oct 26, 2026

    @changyeon-jo
    Author

    Hi @ngphibang @josuah, a gentle ping on this. Unless you have concerns, I'd like to start sending the PRs for revision 4:

    1. the control IDs, menus and documentation, together with the encoder conformance test (tests/subsys/video/encoder);
    2. the video_stm32_venc implementation.

    Since I don't have an STM32N6570-DK, I'd mark the stm32 part as needing hardware testing, unless you prefer another approach (see my question above).

    The force-key-frame control relies on the button type from #96393. @ngphibang, if reviving it is still on your list, I'm happy to base my series on it, or to help with it if that's useful.

    Is there anything you'd like changed before I open them?

  16. ngphibang commented on Oct 26, 2026

    @ngphibang
    Contributor

    @changyeon-jo: Yes, I think it looks good to start the PR.

    I just revived #96393.

    So far, in Zephyr, we only have a H.264 enc driver (with limited mode, no P, B frames enc AFAIU) on ST's N6 (no decoder). The STM32MP25 does have both encoder and decoder but doesn't have yet the same level of SW support in Zephyr as the N6 has (cc @avolmat-st).

    I need to add support for H.264 in mpipe as well but unfortunately I have no HW in hand ... With all of your interests in video / h.264 in Zephyr, may I askl if you have a concrete project and use cases in mind (I mean a HW platform) to help to test and support these things ?

  17. changyeon-jo commented on Oct 27, 2026

    @changyeon-jo
    Author

    Thanks @ngphibang, and for reviving #96393! I'll base the series on it and adapt to video_register_ctrl().

    Regarding your question about hardware: I'm looking at camera and video encoding use cases on MCU-based devices. I'll keep everything testable without hardware (the conformance test runs on native_sim and QEMU), and I'm happy to help test and review video and H.264 changes where I can, including mpipe. For the video_stm32_venc part I'll still need someone with an STM32N6570-DK to validate it.

  18. josuah commented on Nov 18, 2026

    @josuah
    Contributor

    @chemag something you might want to look at:

    My goal is to build a WebRTC-compatible Zephyr client that can make bidirectional audio/video calls between a browser and an RT1170 board with an attached camera and display. Thanks to @ngphibang for helping with the board.

    You might be interested in this: #92843 (reply in thread) where the libpeer author ported WebRTC on their own.

    Furthermore, SRTP support for libpeer was provided by libsrtp, and this work is based on an outdated version. The libsrtp upstream from Cisco itself got upgraded to PSA crypto APIs.

    Meanwhile, SRTP got merged into Zephyr as a stand-alone library, so libpeer would not likely be received upstream without making use of the now-upstream SRTP implementation, but should work at the practical level as libsrtp was shown to work on Zephyr (as seen above). So there are choices.

  19. josuah commented on Nov 18, 2026

    @josuah
    Contributor

    other advantages of minih264e:

    • has a header system.h that allows integration of some platform-specific bits
    • supports "run function in thread" for multithreading
    • support for NEON acceleration (possibly others can be plugged)

    on top of those existing, this means that a minimum H.264 can still be accelerated if need be for any reason

    minih264e is a CC0 dedication, not an OSI-approved license

    it might not be required to modify minih264e, as outside of critical bugfixes and improvements, integration code can be put under Zephyr's own modules/ directory, which reduces the need to modify the upstream project to close to zero.

    Besides, if critical bugfixes need to be integrated before the upstream project reacts, they can be put on the fork.

    CC0 is compatible with Apache2, and derivative work using both CC0 and Apache2 is licensed as Apache2 according to license compatibility matrices I've seen so far.

    => No contributed code would be CC0, the zephyr-maintained fork might be re-license-able as Apache-2.0.

    Not sure what your organization will think but there is a chance that it still work.

  20. chemag commented on Nov 20, 2026

    @chemag

    @josuah thanks for the pointers.

    My demo is a Zephyr application on an NXP MIMXRT1170-EVKB board that makes a full bidirectional audio and video WebRTC call with Chrome running on a desktop:

    Details:

    • uplink video: board camera (OV5640) to Chrome, as H.264.
    • uplink audio: board microphone (DMIC) to Chrome, as PCMU.
    • downlink video: Chrome camera to the board display (RK055), as H.264.
    • downlink audio: Chrome microphone to the board headphones (WM8962), as PCMU.

    Video is 320x240 at 5 fps, H.264 Constrained Baseline. Not Netflix quality, of course, but the board has no HW support for video coding, so I limited the resolution and frame rate.
    Audio is 8 kHz PCMU in 20 ms packets. It should be relatively straightforward to move to Opus.

    On a LAN, over Ethernet, a 30-minute call with real cameras ran with zero decoder errors and zero dropped pictures. That is not a trivial result for this board: the RT1176 has a 1 GHz Cortex-M7 and a 400 MHz Cortex-M4, and everything (WebRTC stack, DTLS-SRTP crypto, H.264 encoding and decoding, audio, display) runs on the Cortex-M7 alone, without any video hardware. The Cortex-M4 is unused.

    The architecture is as follows:

    • Signaling: the board is the SDP offerer. It sends its offer to a small HTTP signaling server on the desktop, which passes it to the browser page and returns Chrome's answer. The server carries only the SDP.
    • Media: ICE, DTLS-SRTP, RTP and RTCP then flow directly between Chrome and the board, through libpeer on top of Zephyr's sockets, Mbed TLS and libsrtp.
    • uplink video: OV5640 capture (Zephyr video API), BGRX to I420 conversion, MiniH264 encoder, libpeer H.264 packetization.
    • downlink video: libpeer FU-A reassembly, h264swdec decoder, I420 to RGB565 conversion, Zephyr display API. Packet loss triggers an RTCP PLI, and decoding resumes at the next IDR.
    • uplink audio: DMIC capture at 16 kHz, 8 kHz PCMU encoding, libpeer.
    • downlink audio: PCMU to PCM, played through the SAI to the WM8962 codec from a dedicated playback thread.

    The project involves several repos. I'm sending upstream all the code the demo needs in each of them:

    Question

    If there's interest, I'm happy to contribute it to Zephyr. If so, what's the right way to publish the application? The options I see are a sample in the Zephyr tree, which would first need libpeer, MiniH264 and h264swdec as external modules, or a standalone west application repository that pulls Zephyr and those projects through its own manifest.

  21. changyeon-jo commented on Nov 20, 2026

    @changyeon-jo
    Author

    Thanks @josuah. For this RFC I'd like to keep the scope to the standard controls and the video_stm32_venc implementation (#123737), so a software H.264 encoder isn't something I'm planning to propose as part of this series. If a software encoder is integrated separately, exposing these controls should let it run the conformance test in #123737 unchanged.

  22. chemag commented on Nov 20, 2026

    @chemag

    I uploaded the demo as a draft PR: #126586

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: Video

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions