See the No Root section.
I use old Android devices as headless, remotely-controlled servers and IP cameras. I don't see anything fits my requirements of being open source, hardware-encoded, and customizable. Beside this is fun and give you total control of your flow. This is adapted from an internal project.
Currently the script is encoding H.264, but you can modify the script to stream H.265 (if your device supports it) by changing video_codec to h265 for scrcpy-server and -f h264 to -f hevc for ffmpeg.
