New Camera Stack - can't control video compression quality

I'm using the latest octopi build of the new camera stack from the Pi Imager on a Pi 3B+ with an ov5647-based Pi NoIR camera (with auto IR-cut). The camera worked immediately upon booting the new image using the default settings in libcamera.conf. The camera responds to changes in resolution and framerate requested in libcamera.conf. But, at this point, I've been unable to discover any means for reducing the Q factor of the video stream. This leaves me with a 1024x768, 24fps stream which consumes ~23mbps (way too much). As a point of reference, the current octopi build using the MJPG streamer when started with usb-option Q=10 in octopi.txt results in a 1024x768, 24fps stream which consumes ~8mbps. If Q is left at its' default (85?) on MJPG, the stream is 1024x768, 24 fps at ~23mbps. With the new camera stack build I've closely followed the camera-streamer configuration FAQ, just haven't yet succeeded in controlling the Q factor of new stack with this camera.

Below are the output of the webcam option endpoint & the current libcamera.conf:

No options passed.

Set: /option?name=value

CAMERA Properties:
- property: SensorSensitivity (00000009, type=5): 1.000000
- property: ScalerCropMaximum (00000008, type=7): (0, 0)/2592x1944
- property: ColorFilterArrangement (0000000a, type=3): 2
- property: PixelArrayActiveAreas (00000007, type=7): [ (16, 6)/2592x1944 ]
- property: PixelArraySize (00000005, type=8): 2592x1944
- property: Rotation (00000002, type=3): 0
- property: Location (00000001, type=3): 2
- property: UnitCellSize (00000004, type=8): 1400x1400
- property: Model (00000003, type=6): ov5647

CAMERA Options:
- available option: AeConstraintMode (00000004, type=3): [0..3]
- available option: Saturation (00000011, type=5): [0.000000..32.000000]
- available option: AeExposureMode (00000005, type=3): [0..3]
- available option: AwbMode (0000000d, type=3): [0..7]
- available option: Brightness (00000009, type=5): [-1.000000..1.000000]
- available option: AeEnable (00000001, type=1): [false..true]
- available option: AnalogueGain (00000008, type=5): [1.000000..63.937500]
- available option: ExposureTime (00000007, type=3): [92..760636]
- available option: ScalerCrop (00000016, type=7): [(0, 0)/128x128..(0, 0)/2592x1944]
- available option: AeMeteringMode (00000003, type=3): [0..3]
- available option: AwbEnable (0000000c, type=1): [false..true]
- available option: ColourCorrectionMatrix (00000015, type=5): [-16.000000..16.000000]
- available option: NoiseReductionMode (00000027, type=3): [0..4]
- available option: ColourGains (0000000f, type=5): [0.000000..32.000000]
- available option: ExposureValue (00000006, type=5): [-8.000000..8.000000]
- available option: Sharpness (00000013, type=5): [0.000000..16.000000]
- available option: FrameDurationLimits (00000019, type=4): [23123..760729]
- available option: Contrast (0000000a, type=5): [0.000000..32.000000]

- available option: compressionquality (009d0903, type=1): [1..100]

VIDEO Options:
- available option: videobframes (009909ca, type=1): [0..0]
- available option: videogopsize (009909cb, type=1): [0..2147483647]
- available option: videobitratemode (009909ce, type=3): [0..1]
		0: Variable Bitrate
		1: Constant Bitrate
- available option: videobitrate (009909cf, type=1): [25000..25000000]
- available option: sequenceheadermode (009909d8, type=3): [0..1]
		0: Separate Buffer
		1: Joined With 1st Frame
- available option: repeatsequenceheader (009909e2, type=2): [0..1]
- available option: forcekeyframe (009909e5, type=4): button
- available option: h264minimumqpvalue (00990a61, type=1): [0..51]
- available option: h264maximumqpvalue (00990a62, type=1): [0..51]
- available option: h264iframeperiod (00990a66, type=1): [0..2147483647]
- available option: h264level (00990a67, type=3): [0..15]
		0: 1
		1: 1b
		2: 1.1
		3: 1.2
		4: 1.3
		5: 2
		6: 2.1
		7: 2.2
		8: 3
		9: 3.1
		10: 3.2
		11: 4
		12: 4.1
		13: 4.2
		14: 5
		15: 5.1
- available option: h264profile (00990a6b, type=3): [0..4]
		0: Baseline
		1: Constrained Baseline
		2: Main
		4: High


### Options for libcamera based cameras (PiCam, Arducam, ...)

# The port on which the webcam server for the camera should listen on. If you have only
# one camera, leave at 8080. If you have more, change to 8081, 8082, etc. The primary
# camera will be considered the one with 8080.

# The resolution to request on the camera sensor. Defaults to 1280x720.

# The height to use for the video stream. Defaults to 720.

# The height to use for the snapshots. Defaults to 1080.

# The framerate to set on the camera. Defaults to 15fps.

# Additional options. By default enables continuous auto focus (if possible).
OPTIONS='--camera-video.options="videobitratemode=0" --camera-video.options="videobitrate=25000"'

What I hoped to do with the two options above was to simply enable VBR compression at the lowest possible bitrate as a starting point for tuning the stream, but regardless of entered value, the stream never goes below ~23mbps. Even tested '--camera-stream.options="compressionquality=10"' (without success) even though there are no "STREAM options" reported in the enumerated return from the option endpoint.

Any idea what the problem is? Am I entering the options correctly? I have this build on its' own sdcard so I can easily swap between builds & test any changes you might recommend.

Thanks for a wonderful product (both Octoprint & Octopi!),


The --camera-video.options= controls the H264/WebRTC output. To control MJPEG output you have to use: --camera-snapshot.options=compressionquality=10 since there's no additional reencode to stream, and everything is served using single snapshot as snapshot and stream.

1 Like

Bingo. With that as the only option, the resulting stream is ~5mbps. On to to stream tuning.

Thanks for the speed-of-light reply!

P.S. - can H.264 be enabled for the webcam stream on this camera stack?

It is implicitly enabled already when you go to /webrtc or /video endpoint. But there are unofficial/not-released plugin yet to use webrtc feed.

Got it. Thanks again for your help. Off to Github for the plugin!

It's this one.

1 Like

Thanks! Setting it up now...

Maybe I'm stupid but how do you install the OctoPrint-CameraStreamer-Control plugin?

Use the download zip link from GitHub in plugin manager > get more > ...from URL and click install.

I'll be honest and say I didn't include instructions on how to install to avoid people installing it just yet :sweat_smile:

It's not finished but I hope to get stuck in to it in around 2 weeks time. It is functional if you do try it but not quite ready for prime time, and I don't want bug reports just yet.

Thanks, Charlie. Your plugin has worked without problem so far, but I'll wait until you finish it before switching to the new camera stack full time.

Using h.264/webrtc on the new camera stack is a revelation. With '--camera-video.options="videobitratemode=0" --camera-video.options="videobitrate=4000000"' the 1024x768, 24fps stream via /webrtc consumes ~3.5mbps with high visual quality and one-tenth (~100ms. vs ~1s.) the latency. I'm sold.