Capturing PC Screen with FFmpeg: [fgdigrab] TP Framerate Issue
In this article, we will discuss how to capture a PC screen, specifically while playing a game, and send the raw video over a network via TP (multicast stream) using the FFmpeg tool. The video will be in YUV422P10 format with a framerate of 59.94.
Introduction to FFmpeg
FFmpeg is a free and open-source multimedia framework that can record, convert, and stream audio and video. It is available on various platforms, including Windows, Linux, and macOS. FFmpeg is widely used for its powerful features, such as its ability to handle various codecs and formats.
The fgdigrab Input Device
The fgdigrab input device is a component of FFmpeg that allows you to capture the screen of your PC. It is a hardware-accelerated video capture device that can capture the screen in various formats and resolutions. The fgdigrab input device can also capture audio from the default audio device.
Capturing the Screen
To capture the screen, we will use the following command:
ffmpeg -f gdigrab -framerate 59.94 -i title="Game" out.yuvThis command will capture the screen of the game with a framerate of 59.94 and save it as a YUV422P10 file named out.yuv. The title parameter specifies the window title of the game that we want to capture.
Sending the Video Over a Network
To send the video over a network, we will use the following command:
ffmpeg -re -f rawvideo -vcodec rawvideo -s 1920x1080 -r 59.94 -i out.yuv -f mpegts -c copy -sdp_file out.sdp udp://127.0.0.1:1234This command will read the out.yuv file, encode it as an MPEG-TS stream, and send it over a UDP multicast stream to the localhost on port 1234. The -sdp_file parameter specifies the file where the session description protocol (SDP) information will be saved. The SDP information is necessary for the receiver to decode the stream correctly.
Receiving the Video
To receive the video, we will use the following command:
ffplay -protocol_whitelist file,udp,rtp -i out.sdpThis command will read the out.sdp file, parse the SDP information, and start playing the video. The -protocol_whitelist parameter specifies the protocols that ffplay will use to receive the stream.
FFmpeg is a powerful tool that can capture the screen of your PC and send the raw video over a network via TP (multicast stream). The fgdigrab input device allows you to capture the screen in various formats and resolutions. By using the commands discussed in this article, you can capture the screen of your PC and send it over a network for remote viewing.