Skip to content

Conversation

hfruchet-st
Copy link
Contributor

@hfruchet-st hfruchet-st commented Jul 9, 2025

This PR introduces H264 hardware video compression thanks to VENC peripheral of STM32N6.

A new stm32 video encoder driver has been introduced which relies on vc8000nanoe software stack [1].
This is a first basic porting to enable H264 encoding use-case.
RAM memory resources required by VENC encoding process are allocated in external PSRAM, camera frames
captured by DCMIPP and encoded by VENC are also allocated in external PSRAM.
The video encoder driver currently lack of controls to configure the encoding process, default configuration
targets H264 1080p 2Mb/s constant bitrate.

In order to test, the tcpserversink video sample has been enhanced to support video compression in order to stream small H264 compressed video chunks instead of big raw uncompressed images [2].

[1] zephyrproject-rtos/hal_stm32#295
[2] #95862

Copy link

github-actions bot commented Jul 9, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_stm32 zephyrproject-rtos/hal_stm32@d768bcb zephyrproject-rtos/hal_stm32@18186af zephyrproject-rtos/[email protected]

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

Copy link

sonarqubecloud bot commented Jul 9, 2025

@avolmat-st avolmat-st self-requested a review July 9, 2025 11:12
@josuah josuah added the area: Video Video subsystem label Jul 19, 2025
Copy link
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for preparing VENC!

This will really make video over network on Zephyr interesting.

It seems like Zephyr lacks a few APIs from Linux (no H.264 format definition, no planar API for NV12...), so if anything feels like missing, let us know so that the missing API can be provided in parallel.

@josuah josuah added the platform: STM32 ST Micro STM32 label Jul 19, 2025
hfruchet-st referenced this pull request in avolmat-st/zephyr-stm32-mw-isp Aug 13, 2025
No specific processing is necessary currently as part of the
stm32_dcmipp_isp_start function hence remove the assert(0)
currently preventing stop of the isp.

Signed-off-by: Alain Volmat <[email protected]>
hfruchet-st referenced this pull request in avolmat-st/hal_stm32 Aug 13, 2025
Allow to call HAL_DCMIPP_PIPE_SetConfig when the pipe state
is READY. Currently it is only possible to use this function
if the pipe state is RESET and ERROR states.
Indeed, it is possible to reconfigure the PIPE as soon as the
pipe is not currently being used, aka in the READY state.
With that done, it becomes possible to change the PIPE
configuration between two use-cases without having to
DeInit / Init the HAL_DCMIPP or use the unitary pixel packer
functions.

Signed-off-by: Alain Volmat <[email protected]>
@ngphibang ngphibang self-requested a review August 14, 2025 06:29
Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of comment, driver aside.
Please split the PR and do a specific PR for the first commits that are not directly linked to the VENC driver. These can be reviewed and integrated faster.
For the changes on the sample, I let video team decide if this should be kept within the tcpserver sample or split into a different sample

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some pending comments, not sure why they were missing

@hfruchet-st hfruchet-st force-pushed the iso_stm32n6_1080p_h264_streaming branch from a32b1da to deac1fb Compare September 11, 2025 14:14
@github-actions github-actions bot removed the manifest label Sep 11, 2025
@hfruchet-st hfruchet-st marked this pull request as ready for review September 11, 2025 14:19
Pull hal_stm32 vc8000nanoe library.

Signed-off-by: Hugues Fruchet <[email protected]>
Addition of description for the STM32 Video encoder (VENC).

Signed-off-by: Hugues Fruchet <[email protected]>
The STM32 video encoder (VENC) peripheral is a hardware
accelerator allowing to compress RGB/YUV frames into
H264 video bitstream chunks.

Signed-off-by: Hugues Fruchet <[email protected]>
Add node describing the venc in stm32n6.dtsi

Signed-off-by: Hugues Fruchet <[email protected]>
@JarmouniA
Copy link
Contributor

Bot added unrelated labels and reviewers.

@JarmouniA JarmouniA requested review from djiatsaf-st and removed request for tejlmand October 6, 2025 15:52
Copy link

sonarqubecloud bot commented Oct 6, 2025

Please retry analysis of this Pull-Request directly on SonarQube Cloud

ret = encoder_start(data, output);

/* Output buffer is now filled with SPS/PPS header, return it to application */
goto out;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that when starting the encoder, this will only produce data into the output buffer, and input buffer is not used in such case. Is that correct ?

I feel that in the way it is currently done, the first input frame is going to be lost / unused and returned to the application (and thus back to the camera side) without actually having been used.

If that's the case it might be better to add a comment here, with maybe a TODO / FIXME or something like that in order to address in a further PR.

LOG_DBG("output=%p, encOut.streamSize=%d", output, encOut.streamSize);

k_fifo_put(&data->out_fifo_in, output);
k_fifo_put(&data->out_fifo_out, output);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same output cannot be put back into both side of the output queue. Doing so would mean that for example the encoder could override the output frame while it is currently used by the application (currently tcpserversink), is my understanding correct ? It should only be put into the out_fifo_out I think.


out:
k_fifo_put(&data->in_fifo_out, input);
k_fifo_put(&data->out_fifo_out, output);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing k_fifo_put of output into the out_fifo_out leads to pushing the output buffer twice into out_fifo_out if we consider the k_fifo_put already done above ??


static int stm32_venc_get_caps(const struct device *dev, struct video_caps *caps)
{
caps->format_caps = fmts;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the format_caps should depends on the caps->type and return different format depending on INPUT or OUTPUT. Currently that might be RGB565/NV12 for the INPUT and H264 for the OUTPUT ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Boards/SoCs area: Devicetree Bindings area: Tests Issues related to a particular existing or missing test area: Video Video subsystem manifest manifest-hal_stm32 platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants