Repository navigation
Description
Describe the bug
I'm researching a new m2m interface to migrate our streaming software to it and found that the parameters that the encoder uses produce a flickering video for a variable bitrate. When using a constant bitrate, everything is fine, but I need a variable one because it allows me to achieve zero-latency encoding. There were two very important parameters in the old MAIL interface: MIN_QUANT and MAX_QUANT, by configuring which I could get rid of the mentioned artifact. But if the quantization from 16 to 32 is configured, then everything will be fine.
Unfortunately, the new API does not provide this and without them I get the following result
(Look at the area under the cursor in the terminal):
https://user-images.githubusercontent.com/416259/142009115-0f65da9d-306e-439f-a503-519cd56666b8.mp4
And how it should be (MIN_QUANT=16, MAX_QUANT=32):
https://user-images.githubusercontent.com/416259/142009452-bdcb8587-d94f-4f98-aed9-cf61d38d69c5.mp4
To reproduce
Use variable bitrate to encode H.264. In a contrasting black-and-white image, you will notice pulsating artifacts when an I-frame arrives. The full list of parameters is as follows:
V4L2_CID_MPEG_VIDEO_BITRATE = 5000000
V4L2_CID_MPEG_VIDEO_H264_I_PERIOD = 30
V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE
V4L2_MPEG_VIDEO_H264_LEVEL_4_0
V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER = 1
output FPS = 1/30
How to solve
To solve the problem, we just need the ability to throw MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT/MAX_QUANT into the kernel using V4L2_CID. The problem is that V4L2 does not seem to provide suitable CIDs for this. I suggest making a pair of specific CIDs with a large offset like this:
diff --git a/include/media/h264-ctrls.h b/include/media/h264-ctrls.h
index ec4799154..d1b045fde 100644
--- a/include/media/h264-ctrls.h
+++ b/include/media/h264-ctrls.h
@@ -37,6 +37,8 @@
#define V4L2_CID_MPEG_VIDEO_H264_DECODE_MODE (V4L2_CID_MPEG_BASE+1005)
#define V4L2_CID_MPEG_VIDEO_H264_START_CODE (V4L2_CID_MPEG_BASE+1006)
#define V4L2_CID_MPEG_VIDEO_H264_PRED_WEIGHTS (V4L2_CID_MPEG_BASE+1007)
+#define V4L2_CID_MPEG_VIDEO_H264_QUANT_MIN (V4L2_CID_MPEG_BASE+9901)
+#define V4L2_CID_MPEG_VIDEO_H264_QUANT_MAX (V4L2_CID_MPEG_BASE+9902)I will make all the necessary changes and send you a patch, just tell me which solution you think is preferable. I really need these parameters.
Activity
6by9 commentedon Nov 16, 2021
V4L2 controls
V4L2_CID_MPEG_VIDEO_H264_MAX_QPandV4L2_CID_MPEG_VIDEO_H264_MIN_QPalready exist in the API.https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/ext-ctrls-codec.html
/include/media/h264-ctrls.h is the wrong file to be looking at. As noted in the headers
The Pi H264 codec implements the stateful API, not the stateless (which is only defined for decoders at present).
Files outside of /include/uapi are not considered part of the stable userspace API and will not be exported.
mdevaev commentedon Nov 16, 2021
Thank you, got it. I will make a patch.
mdevaev commentedon Nov 17, 2021
Done: #4705
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
mdevaev commentedon Nov 25, 2021
Fixed by #4705
Thank you!
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
Pass V4L2_CID_MPEG_VIDEO_H264_MIN_QP/MAX_QP to bcm2835-v4l2-codec
271 remaining items
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver
staging: vc04_services: Add a V4L2 M2M codec driver