If you're targeting Windows OS, the option recommended by Engine seems ideal.
For Linux I ended up using an RTSP server(FFSERVER) as a VideoCapture input, then screencasting using FFMPEG with "x11grab".
FFMPEG for Windows will accept the "screen-capture-recorder" application as an input, but I don't have any experience setting up an RTSP server on windows.
For my setup this translated to code that looked like this:
cv::VideoCapture cap;
cap.open("http://localhost:8090/live.flv"); // open the default camera
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('F', 'L', 'V', '1'));
and
cv::resize(frame, frame, cv::Size(200, 200));
cv::VideoWriter outStream("http://localhost:8090/feed2.ffm",
CV_FOURCC('F', 'L', 'V', '1'), 10, cv::Size(200, 200), true);
The 200x200 resolution was necessary to minimize latency so if you can grab the screen buffer directly to avoid unnecessary screencasting/encoding that sounds better from a performance standpoint...