Although I couldn't tell you offhand exactly how to do it, my gut response is that FFMPEG is probably the tool for the job if you want something that works from the commandline. I'd just do a Google search on how to do it. Although I'm still learning OBS, I think it's primarily for interactive usage. I don't know if it has features which would allow it to be automated and run headlessly.