blogs/linux

Raspberry Pi Hardware Video Encoding

11/05/2023

Trying to find out how to use the hardware h264 encoder in the Raspberry Pi chips has been such a struggle. There's a lot of information to dig through, most of it confusing and often conflicting.

Or, if you just want to copy a stream which is __already__ encoded, it's a similar story.

If you search anything like `opencv raw dump` or `ffmpeg omx` you'll struggle to find anything helpful. Only when I searched for `pi zero csi ffmpeg` did I find my answer. Here it is:

`ffmpeg -f v4l2 -input_format h264 -video_size 1920x1080 -framerate 25 -i /dev/video0 -vcodec copy -an test.h264`

With that code we can stream 1080p at 25 FPS to a .h264 file on a Pi Zero 2(!), and you just need to remux the file into the .mp4 container. Although the code I stole is specifically about CSI, this should also work on USB cameras that do hardware encoding.

So if you've struggled like I have, there's how you do it.

Helpful Commands

27/09/2022

Some helpful Linux commands I'm safekeeping here.

ps -fA | grep "command"

Reports a snapshot of current processes. Helpful for finding python processes, for example.

scp from.txt pi@ipaddress.local:/to.txt

Copy over SSH.

crontab -e

Avoid doing crontab -r. :(

shrink a disk image

https://askubuntu.com/questions/1174487/re-size-the-img-for-smaller-sd-card-how-to-shrink-a-bootable-sd-card-image



Zac Hah 2024