If you can execute a script after a video upload, you can use that one-liner above, but you have to output to a temp file, delete the original, then rename/move the temp to the original location. In php, you can execute shell commands like:
exec("timeout -s SIGKILL 60 ffmpeg -y -i " . $originalVideoPath . " -c:v libx264 -strict -2 -movflags +faststart -loglevel quiet -threads 2 " . $tempName . " > /dev/null 2>&1");
I copied and pasted this from a production app I have. So I also make use of ātimeout -s SIGKILL 60ā in the event it takes more than 60 seconds to process a video, it just kills the processing so it doesnāt run forever. If someone uploads a literal 4k movie, that will happen. The ā-movflags +faststartā generates a preview thumbnail for the video if it doesnāt exist. You may have seen videos that are black frames with no preview, this fixes that. the -threads 2 limits amount of compute power to use, you donāt want 100% and then > /dev/null 2>&1 sends output to the trash instead of printing it.
And then after that runs, you can move, rename and delete the two videos accordingly using filexists() to see if a temp video was made.
Hope this helps, there may be drawbacks that prevent you from going this route.