fix(camera): add optional pix_fmt for hardware encoders - #442
Conversation
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>
|
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 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>
|
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? |
Closes #440.
Adds an optional
pix_fmtparameter to[camera]. When set, it is forwarded toffmpegcv.VideoWriterin all three timelapse render paths. Empty default keeps the previous behavior.Rockchip h264_rkmpp encoders require
nv12; the default YU12 from ffmpegcv triggersBrokenPipeErrorfrom 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.