OpenCV Ffmpg recording using HWenc?

Ok, I implemented that patch (I also needed to add NvVideoEncoder *enc into centext_t - .h) but I’m not sure that I understand what it does…
It’s just encode frame after frame inside program memory? No recording?

So now if I want to save it to file what should I do?

Can I now just convert that to cv::Mat the same way as here and then use cv::VideoWriter on it? If so then what parameters I need to set (fourcc) for it to be playable or maybe just throw it into the file binarly like that

ofstream outfile("image.mp4", ios::out | ios::binary); //not sure about extension ?
outfile.write(image.ptr(),image.rows*image.cols*image.channels());
outfile.close();

Do I need to convert it additionally somehow? Cause if I understand correctly to encode I need YUV format, so I can’t just change input_params to BGR like before?