How to encode gpu images and push to rtsp with ffmepg

My process is as follows:

I decoded camera stream with cuvid, and converted to RGB format in cuda memory.
Drawed some boxes and points on this RGB image.
Converted RGB image to I420 image in cuda memory.
Use video codec sdk to encode this I420 image with func “EncodeFrame”
streaming the packet to a rtsp server.

But it failed with blurred screen.
Please give me some help to do this job.

Is there any sample I can learn?