- Alberto Solavagione
- Davide Scovotto
ScreenRecorderProject is a library based on the famous third party library FFmpeg which offers the possibility to record the desktop and optionally the audio from the system microphone. It is possible to interact with this library through a CLI integrated in this project.
Using the command line a user can:
- Specify an audio device (microphone)
- Specify the location where to save the video recorded (with .mp4 format)
- Specify if the audio recording is requested
- Specify the portion of the screen that you want to record
Once the user has set all the initial options then can:
- Start the recording
- Pause/Resume the recording
- Stop the recording
- Exit
The ScreenRecorderProject library is composed by two files Recorder.cpp and Recorder.h. The major APIs offered by this library are:
-
OpenVideoDevice()/OpenAudioDevice(): these APIs open the device for recording the desktop and for capturing the audio from the microphone. In Windows is used gdigrab for the screen and dshow for the audio. In Linux instead is used x11grab for the screen and alsa for the audio.
-
InitOutputFile(): allocate and prepares the context for the output file based from the file extension
-
InitializeVideoDecoder()/InitializeAudioDecoder(): prepare and allocate the resources for the video/audio decoder contexts and opens them
-
SetUp_VideoEncoder()/SetUp_AudioEncoder(): prepare and allocate the resources for the video/audio encoder contexts and opens them
-
lastSetUp(): write the stream header to the output media file
-
startCapture(): this is the core API, it calls the above APIs for open the video/audio device and initialize the video/audio decoder and encoder and sets up the output file of the resulting video.
After the initialization/configuration process it starts 4 threads:- manageCapture is a lambda function that internally calls captureMenu()
- acquireFrames is a lambda function that calls acquireVideoFrames()
- encodeDecodeVideo is a lambda function that calls encodeDecodeVideoStream()
- captureAudio is a lambda function that calls AudioDecEnc()
-
captureMenu(): is an API that permits to start/stop and pause/resume the recording by setting shared global variables with the other threads in order to synchronize the above actions.
-
acquireVideoFrames(): this API acquires from the video device raw packets and inserts them in a queue
-
encodeDecodeVideoStream(): this API performs the decoding and the encoding. It takes a raw packet from the queue and passes it to the decoder which outputs the decoded frame then the frame is scaled and re-encoded in a mpeg4 container and wrote on the output file
-
AudioDecEnc(): this API performs similar actions to the ones of the video but for the audio
- Download the required libraries and tools
sudo apt install qt5-qmake build-essential libasound2-dev libavcodec-dev libavdevice-dev libavfilter-dev libavformat-dev libavutil-dev
- Install c++ 20
sudo apt install gcc-10 gcc-10-base gcc-10-doc g++-10
sudo apt install libstdc++-10-dev libstdc++-10-doc
- Clone the repository
git clone https://github.com/AlbertoSvg/ScreenRecorderFinal.git
- Go in the project folder
cd ScreenRecorderFinal
- Generate the Makefile
qmake ScreenRecorder.pro
- Compile it
make clean; make all
- Allow the binary to be executed
chmod 777 ScreenRecorder
- Run it
./ScreenRecorder
- Since in Windows the whole process of installation of the required libraries and compilation of the software is much more complicated than Linux, we suggest to simply download the precompiled software from this link.
- If you really want to compile it from scratch, here is the link that guides you for downloading and compiling the FFmpeg library.
- Download the software from this link (Windows) or this link (Linux)
- Run the software
- The first thing that the software ask you is to specify the audio device.
In Linux to find out what audio device you have to insert you can initially install the alsa-utils package withsudo apt install alsa-utils
and then use the commandarecord -l
to list all the capture devices and choose the appropriate one.
For example in the case reported in the picture the correct device to insert ishw:0,0
.
In Windows to find out what audio device you have to insert, you need to type Device Manager in the search box on the Windows' taskbar, then select from the menu the Device Manager. Then navigate to Audio inputs and outputs and copy the name of the appropriate audio input device (like in the picture below). - The second thing to insert is the path and name of the output file (recorded video).
For example
./output.mp4
.
IMPORTANT: specify the file format(.mp4)
. - The third thing is to specify if you want the audio recording
(Y,N)
. - The final thing is the definition of the screen area to record. This is possible by inserting 4 offsets (X1, Y1, X2, Y2). The offsets must be multiple of 2 and lower than the width and height of the screen.
- After all these initial configurations you can start the recording by pressing
1
.