Repository navigation
Description
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_vencas 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_vencdefaults and the test plan below are updated to match.
This RFC proposes:
- a small set of standard encoder controls in the existing, still empty,
VIDEO_CID_CODEC_CLASS_BASEclass, with numeric IDs and semantics identical to the Linux V4L2 stateful codec controls; - an encoder conformance test that runs against any
zephyr,videoencdevice, so that hardware encoders can be validated the same way on any board.
Problem description
- No standard controls.
controls.hdefinesVIDEO_CID_CODEC_CLASS_BASE(0x00990900, "Stateful codec controls IDs"), but no CID uses it. The only encoder control today isVIDEO_CID_JPEG_COMPRESSION_QUALITYin the JPEG class. - Encoder parameters are hardcoded. For example,
video_stm32_venccurrently:- 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
- Add a
VIDEO_CTRL_TYPE_BUTTONcontrol type for write-only action controls (via the revived video: Improve control framework #96393). - Add codec CIDs to
include/zephyr/video/controls.hunderVIDEO_CID_CODEC_CLASS_BASE. Numeric IDs, menu values and semantics are identical to Linux. The names drop the legacyMPEG_VIDEO_infix (see Naming). - Teach
drivers/video/video_common.cthe type of each new CID and the standard menu strings. - Define which controls may change while streaming.
- Add
tests/subsys/video/encoder, a conformance test for anyzephyr,videoencdevice. - Implement the controls in
video_stm32_venc. The defaults reproduce today's behavior, so existing users see no change. - Use the existing
set_frmival/get_frmivalops 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 nameVIDEO_CID_CODEC_CLASS_BASE. - H.264-specific controls become
VIDEO_CID_H264_*.
Rationale:
- Linux itself renamed this class from
MPEGtoCODEC(V4L2_CID_CODEC_BASE, withV4L2_CID_MPEG_BASEkept as an alias). Only the per-control names still carryMPEG_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 usesH264_I_FRAME_QPorH264_P_FRAME_QPwhere supported.BITRATE_MODEandBITRATEare ignored. - Rate control on (
FRAME_RC_ENABLE=1):- CBR or VBR targets
BITRATE; - CQ targets
CONSTANT_QUALITY; H264_MIN_QPandH264_MAX_QPclamp the QP chosen by rate control.
- CBR or VBR targets
GOP_SIZEis 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_FRAMEmakes 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_IDRrepeats 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_SIZEcomes from the original MPEG-2 capture-card controls, where a GOP starts at every I-frame.H264_I_PERIODwas 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:
wave5mapsGOP_SIZEto the IDR period andH264_I_PERIODto the intra period.s5p-mfcappliesH264_I_PERIODonly in open-GOP mode.mediatekandvenusregister 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'sset_ctrlto trigger the action, and the written value is ignored;- the video shell lists it as
(button)and acceptsvideo 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_WRITEflag. This RFC builds on it rather than introducing a separate design.
- it has no stored value, and
- 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 withvideo_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:
BITRATEand the QP limits go through the encoder's rate-control update call.FORCE_KEY_FRAMEforces 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.canddrivers/video/video_stm32_venc.c, and addstests/subsys/video/encoder/. - There is no API break, because the codec class is currently empty.
video_stm32_jpegis unaffected and keepsVIDEO_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
-
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). -
Runtime changes. The "Change while streaming" column is a proposal. Is switching
BITRATE_MODEwhile streaming worth supporting on any known hardware? -
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?
-
JPEG. Proposal: keep
VIDEO_CID_JPEG_COMPRESSION_QUALITYas is, rather than reconciling it withCODEC_CONSTANT_QUALITYfor MJPEG-style encoders. -
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_SIZEframesforce key frame IDR on the frame after the button header placement SPS/PPS placement matches HEADER_MODEandPREPEND_SPSPPS_TO_IDRprofile and level SPS profile_idc, constraint flags andlevel_idcmatch the controlsbitrate mean P-frame size within a loose band of BITRATE / fps; changingBITRATEwhile streaming changes it accordinglyconstant quality P-frame size grows with CONSTANT_QUALITYrestart 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_venccannot 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,videoencdevice. Today that isstm32n6570_dkwithvideo_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 onnative_simand QEMU. -
Build coverage:
stm32n6570_dkbuilds ofsamples/subsys/video/tcpserversinkand the UVC sample with the H.264 encoder enabled. -
Optional manual check: on hardware, stream with tcpserversink and inspect with
ffprobeor GStreamer.
Activity
github-actions commentedon Oct 15, 2026
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. 🤖💙
changyeon-jo commentedon Oct 15, 2026
Prior art I missed when writing this up:
VIDEO_CTRL_TYPE_BUTTONalong withVIDEO_CTRL_FLAG_EXECUTE_ON_WRITEbefore it was closed as stale. PR 1 here should build on that rather than add its own type. @ngphibang, would you prefer to revive video: Improve control framework #96393, or should I carry the button part forward, crediting your work?drivers/video/, is another option for question 3.I've updated the description accordingly.
ngphibang commentedon Oct 16, 2026
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.
changyeon-jo commentedon Oct 16, 2026
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:
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_vencas their first user.What would you prefer?
josuah commentedon Oct 17, 2026
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.
[-]RFC: Standard video encoder controls, with a reference software encoder[/-][+]RFC: Standard video encoder controls[/+]changyeon-jo commentedon Oct 17, 2026
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:
I've updated the description accordingly (revision 4):
video_stm32_vencas their first user, plus the encoder test intests/subsys/video/encoderfor boards with an encoder (building on the revived video: Improve control framework #96393 for the button type);@ngphibang, does that work for you?
ngphibang commentedon Oct 19, 2026
@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.
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) ?
changyeon-jo commentedon Oct 19, 2026
Thanks @ngphibang, that's helpful.
video_stm32_vencchanges 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.zephyr,videoencdevice for the controls work, if that's useful.chemag commentedon Oct 19, 2026
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.
chemag commentedon Oct 19, 2026
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:
Regarding the software H.264 codecs:
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:
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
changyeon-jo commentedon Oct 19, 2026
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 (azephyrbranch on top of upstream). Happy to review or test.H.264 licensing, what I found:
Measurements from local prototypes (encoder only, portable C without the libraries' SIMD code, single-threaded, Constrained Baseline, one spatial layer):
libopenh264.a, built for Cortex-M33 (mps2/an521) at-Osin a Zephyr build, before the linker drops unused sections.On interfaces: if the software encoders are exposed as
zephyr,videoencdevices, 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?ngphibang commentedon Oct 20, 2026
@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.
changyeon-jo commentedon Oct 20, 2026
Thanks @ngphibang, these are useful reference points.
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.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.
changyeon-jo commentedon Oct 26, 2026
Hi @ngphibang @josuah, a gentle ping on this. Unless you have concerns, I'd like to start sending the PRs for revision 4:
tests/subsys/video/encoder);video_stm32_vencimplementation.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?
ngphibang commentedon Oct 26, 2026
@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 ?
changyeon-jo commentedon Oct 27, 2026
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_vencpart I'll still need someone with an STM32N6570-DK to validate it.josuah commentedon Nov 18, 2026
@chemag something you might want to look at:
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.
josuah commentedon Nov 18, 2026
other advantages of minih264e:
system.hthat allows integration of some platform-specific bitson top of those existing, this means that a minimum H.264 can still be accelerated if need be for any reason
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.
chemag commentedon Nov 20, 2026
@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:
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:
The project involves several repos. I'm sending upstream all the code the demo needs in each of them:
main: Chrome offer/answer interop, RTP, SRTP, DTLS, ICE and STUN robustness, Mbed TLS 4 support, and H.264 loss recovery with PLI. They are going upstream in eight independent groups; the first two are build: support modern CMake and Mbed TLS 4 sepfy/libpeer#289 and rtp: validate packet bounds and preserve SRTP overhead sepfy/libpeer#290.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.
changyeon-jo commentedon Nov 20, 2026
Thanks @josuah. For this RFC I'd like to keep the scope to the standard controls and the
video_stm32_vencimplementation (#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.chemag commentedon Nov 20, 2026
I uploaded the demo as a draft PR: #126586