As you don't state what OS you are using I would recommend Handbrake as an excellent free mp4 / h264 encoder. It's cross platform and has options for Windows, Mac and Linux.
It does have a gui but all the actual work appears to be done in a command line program which on my machine appears to be in the install directory as HandBrakeCLI.exe. There is a guide as to how to use the command line version at https://handbrake.fr/docs/en/1.1.0/cli/cli-guide.html but it appears that it may possibly be slightly out of date (but probably still largely relevant) as there is a note about it on this page.
It is multithreaded and can easily use all the processors you have available.