Skip to content

fix(camera): add optional pix_fmt for hardware encoders - #442

Open
SAY-5 wants to merge 2 commits into
nlef:masterfrom
SAY-5:fix/camera-pix-fmt-config
Open

fix(camera): add optional pix_fmt for hardware encoders#442
SAY-5 wants to merge 2 commits into
nlef:masterfrom
SAY-5:fix/camera-pix-fmt-config

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 12, 2026

Copy link
Copy Markdown

Closes #440.

Adds an optional pix_fmt parameter to [camera]. When set, it is forwarded to ffmpegcv.VideoWriter in all three timelapse render paths. Empty default keeps the previous behavior.

Rockchip h264_rkmpp encoders require nv12; the default YU12 from ffmpegcv triggers BrokenPipeError from the rkisp driver. Tested locally via the unit tests for the new config field; live timelapse path runs on the same kwargs forwarding pattern already used for codec/fps.

Fixes BrokenPipeError on Rockchip boards using h264_rkmpp, which requires nv12 pixel format. Empty default preserves existing ffmpegcv autodetection.

Closes nlef#440

Signed-off-by: SAY-5 <say.apm35@gmail.com>
@marat7390

Copy link
Copy Markdown

This PR does not fully fix Rockchip hardware encoding on BTT CB2 / RK35xx.

pix_fmt=nv12 is currently passed directly to ffmpegcv.VideoWriter(), but in ffmpegcv this parameter describes the input raw frame format. Moonraker Telegram Bot provides OpenCV frames in BGR format, so ffmpeg interprets BGR data as NV12. The result is corrupted video with colored/garbled frames.

There is also a second issue: the bot only allows h264 and mpeg4 as fourcc values. On CB2, h264 resolves to h264_v4l2m2m, which fails with:

Could not find a valid device

The working encoder on this platform is h264_rkmpp.

I got timelapse generation working with the following changes:

allow h264_rkmpp as a valid fourcc
keep the raw ffmpeg input as bgr24
convert the encoder output pixel format to nv12
use h264_rkmpp as the encoder

In other words, the generated ffmpeg pipeline should effectively be:

raw BGR24 -> ffmpeg conversion to NV12 -> h264_rkmpp

Setting the input pix_fmt itself to nv12 is not correct unless the Python code actually converts the OpenCV frame to NV12 before writing it to ffmpeg.

With fourcc: h264_rkmpp and output nv12, timelapse generation works correctly on BTT CB2.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@SAY-5

SAY-5 commented Aug 16, 2026

Copy link
Copy Markdown
Author

you are right, ffmpegcv treats pix_fmt as the raw input format, so nv12 there just mislabels the bgr24 frames coming from opencv. pushed a change that leaves the input alone and sets target_pix_fmt on the writer instead, and h264_rkmpp is now an accepted fourcc. if you get a chance, could you retest on the CB2 with fourcc: h264_rkmpp and pix_fmt: nv12?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix BrokenPipeError during timelapse render on Rockchip boards (add pix_fmt parameter)

2 participants