Skip to main content
Associate II
Sep 8, 2025 7:13 PM UTC
Question

STM32N6 VENC Hardware Handshake with MJPEG encoding

The VENC peripheral on the N6 boasts a hardware handshake path with the DCMIPP peripheral, potentially allowing full compression of each frame to occur with very little active RAM. From what I can find, the DCMIPP capture starts, then the VENC is told to start encoding, and the application only then receives notifications when a frame is complete. There should be no further interaction. However, I am unable to get this working for MJPEG. The examples for this sort of streaming are all for h264, and the JPEG is thrown to the side as a one-time encoding. I have reasons on this project to use MJPEG encoding, but I cannot get the VENC to perform this handshake with the supplied example code. I have attempted to modify the JPEG Encoding Example that uses the VENC, and have successfully used the VENC for JPEG encoding of a full in-RAM frame, so I know the peripheral can work. Relatedly, the only articles on the handshake algorithm I can find is for the H264 compression.

I'm looking for any working examples of JPEG handshake streaming, or any assistance on getting it working. There seems to be many missing functions in the VENC middleware related to this. All of the JPEG functions are full-frame encoding, no support for double-buffering, nor any mention of streaming. I had to hunt down and dig through H264 examples to even figure out that the JPEG configuration had hidden the "HW" mode. 

5 replies

ST Employee
Sep 10, 2025 7:35 AM UTC

Hello @chornbeck,

This post has been escalated to the ST Online Support Team for additional assistance. We'll contact you directly.

Best regards,
Maxime

​In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Will_Robertson
Associate III
Dec 23, 2025 12:25 PM UTC

Hello @Maxime_MARCHETTO and @chornbeck 

I was wondering if you could share the outcome of this? This is functionality that could be very helpful to us as well.

Will

Associate
Jan 28, 2026 3:28 PM UTC

@Maxime_MARCHETTO I'd also like to register my interest in getting ST to dedicate some support effort for this.  It would be very helpful if the middleware could support hardware handshake MJPEG encoding in a similar fashion to H.264, especially because it seems the hardware itself could accommodate it.

chornbeckAuthor
Associate II
Dec 23, 2025 3:26 PM UTC

@Will_Robertson Sadly, the support I got for this boiled down to "We never got that working, but one of our guys in Europe maybe got further than others?". I was unable to get it working on my end either, and was forced to drop the issue due to priority shifts. If you figure this out, I'd love to know.

Visitor
Nov 23, 2026 7:40 PM UTC

I got slice-by-slice JPEG encoding working with the DCMIPP ↔ VENC hardware handshake. I can’t share the code, but will outline what I did in broad strokes here for any future visitors to this thread. See https://github.com/STMicroelectronics/STM32CubeN6/tree/main/Middlewares/Third_Party/VideoEncoder for some of the functions I refer to below.

Constraints of the solution up front:

  • I could only get this operating at up to 130 Mpx/s, and that’s with the input buffer in internal SRAM (it’s even slower when using external RAM). A contact at ST confirmed that this is what they see as well, so the 300 Mpx/s in the reference manual is probably inaccurate. You may have to downscale the incoming frame or slow your readout time if the line time is too fast for the VENC to keep up with readout.
  • Line width must be a multiple of 16. Number of lines in a single handshake buffer should also be a multiple of 16. (width / 16) * (num lines / 16) must be a multiple of 4, since VENC consumes 4 macroblocks (16x16 pixels) at a time.

Steps to get this working:

  • Establish a slice buffer with space for two handshake units. You will need first a luma ring (both luma handshake units together), and then a chroma ring (both chroma units together). For YUV420, the chroma ring is half the size of the luma ring (the total is line_width * ring_lines * 3/2).
  • Enable YUV conversion on your pipe, and set up the pixel packer to YUV420 (422 also works in my testing) with pipe pitch equal to the line width.
  • Set up the line-wrapping config on your pipe, enable line wrapping, and set up the LINEMULT field on DCMIPP_P1PPCR. LINEMULT should be half the number of lines it takes to wrap. (e.g. wrap every 32 lines, linemult is 16).
    • afaict, this configuration is what has DCMIPP actually send the venc_rdy signal to VENC.
  • Start the pipe streaming in semi-planar mode to your slice buffer (it will wrap at the end of the slice buffer).
  • Call JpegEncInit with a configuration that sets inputLineBufEn, inputLineBufLoopBackEn, inputLineBufHwModeEn, and has inputLineBufDepth as half the height of your slice buffer in macroblocks (div by 16).
  • Activate VENC every time before each frame begins arriving by calling JpegEncEncode (blocking), providing pointers to the luminance and chroma channels within your slice buffer. I set frameHeader = 1 and lineBufWrCnt = 0.
  • In the case of desync / timeout, I suspend the pipe, call a force reset, release reset on VENC, and re-run JpegEncInit, then resume the pipe.

Hope this helps.