OBS is your best bet for no cost. Look up some guides on how to get started with it. It's both a streaming and recording tool.
Just add a game capture object under your sources. Would highly recommend having a dual monitor setup if you plan to do any of this sort of stuff as it just makes life a lot easier.
If you don't have a fairly recent NVidia card that supports NVENC or higher end Intel processor that has a built-in GPU with QSV, you're going to have to rely purely on your CPU to encode the video on the fly which most machines can't handle on top of the resources needed to render a modern game.
If OBS is setup correctly and you're still getting a black screen, try using display or window capture instead of game.