Based on the comments, it seems like OBS is a good fit for you. It was designed to stream video and sound over the internet, but if you go to Settings > Broadcast Settings, there's an option called "Save to file" which you can check to... well, save to a file. You can also fiddle with Mode, which should let you avoid streaming at all.
It's also even easier than providing a PID -- just click Edit Scene in the main screen, then add a source, and it's really easy from there. I don't know if it can record while minimized, if only because your platform may not render window updates when it's minimized, but that's fairly easy to test.
Unfortunately, it doesn't look like they have very much command-line interface support, but there are a few options that I could find documented. You may see more if you look further through that thread or through the source.
According to some sleuthing by the OP, there's also a command line option,
--startrecording, which starts recording (as opposed to streaming). See the GitHub repo if you want to try to glean some more info from it. Note that the link may not always point to exactly the right spot, due to the code being updated over time.