How to enable hardware H.264 encoding (h264_v4l2m2m)? #69
Replies: 5 comments 1 reply
-
I do not recall any difference between Motion and MotionPlus with the pixel formats for the encoding. You may want to quickly just try to set up Motion using the The next option would be to use the extpipe option of either Motion or MotionPlus and then just specify the HW and encoding options for ffmpeg directly into the command used to encode. H264/5 do use the most resources. The Pi's typically used the omx encoder but I've not tested that recently to see if it is still in the latest version of RaspberryPiOS. |
Beta Was this translation helpful? Give feedback.
-
I tried using classic Motion instead of MotionPlus and the performance is basically the same, around 1 FPS in the final mp4 file. If you have any thoughts on how to enable hardware encoding with Motion, I'd be interested. However, I am fairly confident that the OMX encoder is gone. I guess that I would need to use |
Beta Was this translation helpful? Give feedback.
-
You may want to double check omx. I see it as "--enable-omx" in the ffmpeg output as well as in the codec options on my bullseye version.
|
Beta Was this translation helpful? Give feedback.
-
OK. That is a bit disappointing that they did that. Your options....
|
Beta Was this translation helpful? Give feedback.
-
FYI. This is now embedded into the master branch. From my testing, it makes a substantial difference. Essentially no increase in CPU was noted when recording a video. |
Beta Was this translation helpful? Give feedback.
-
I've got a birdhouse cam set up with a Raspberry Pi Zero W and the original Pi Zero camera (5MP OV5647). I realize this is all relatively old hardware, but several years ago I had it working and it worked beautifully. So I decided to set it up again, and in the process installed Raspbian Bullseye… and things have not gone well since.
Anyway, at this point I have abandoned Motion for MotionPlus (I figured if I was going to invest the time in debugging, it might as well be on the 'new' software) and I've got it talking to the camera via the new libcamera API, and recognizing motion / triggering recordings.
However, while it will get frames from the camera and check for motion at a reasonable rate (I'm aiming for 960x720 @ 10FPS, nothing crazy), it's utterly incapable of actually outputting a movie at more than a handful of FPS. Although the actual framerate varies a bit, most recorded MP4 files have framerates around 1.1-1.2 FPS.
Since the system seems able to stream video at ~8 FPS, I suspect the issue is with re-encoding the video to H.264. And it appears that the default H.264 codec that gets used when you select
movie_container mp4
is libx264, running completely on the CPU. Presumably with motion detection taking up 40-60% CPU already, there's just not enough cycles left to compress the output in real-time.To try and force use of the hardware encoder, I changed the movie_container line to
movie_container mp4:h264_v4l2m2m
, but this immediately throws an error "Encoder requires yuv420p pixel format" that I'm not sure how to work around. It doesn't appear that MotionPlus has the same "palette" options that Motion has/had, in terms of forcing specific pixel formats... and I can't figure out if there's some way to convert whatever internal representation MotionPlus uses to yuv420p in preparation for the hardware encoder.Can anyone suggest how to get hardware H.264 encoding working? Or is there another output format that's easier on the hardware to write to disk? I have a fairly big (128GB) MicroSD card in the PiZeroW, so I am not especially space-constrained. But I can't simply switch to a more powerful Raspberry Pi. The Pi Zero W and its camera are basically built-in to the birdhouse at this point, and the wiring for its power supply likely won't support a full-size Pi, even if I could obtain one and figure out how to install it. So throwing more hardware at the problem is not really what I am looking for.
I know that this hardware previously produced much better results, and the capability for HW H.264 encoding is there on the board, so I'm really just hoping there's a way to get back to that high-water mark.
MotionPlus Configuration File
Camera Configuration File
Beta Was this translation helpful? Give feedback.
All reactions