maybe you can try it yourself. When your automation script starts send the adb command:
adb shell screenrecord /sdcard/screen.mp4
When script ends, pull the video:
adb pull /sdcard/screen.mp4
and delete the file from device
adb shell rm /sdcard/screen.mp4
I never tried this, and I think it has a limit of time You can "play" around with bitrate (--bit-rate ) to see if you can raise the limit.