126 lines
5.3 KiB
Markdown
126 lines
5.3 KiB
Markdown
# CERES - Capture Encode Record and Export Screen
|
||
|
||
## Overview
|
||
|
||
**CERES** is a Linux-based screen recorder that captures video (and optionally audio) from your screen using X11 and ALSA. It also supports webcam preview and capture. The program uses FFmpeg libraries to encode the captured video and audio into a single output file and GTK+3 to provide a graphical user interface (GUI) for user interaction.
|
||
|
||
## Code Architecture & Review
|
||
|
||
The code is organized into several modular components:
|
||
|
||
- **GUI Module (gui.c / gui.h):**
|
||
This module creates and manages the user interface using GTK+3. It provides controls for:
|
||
- Selecting the recording source (full screen, specific window, or specific monitor).
|
||
- Choosing recording quality, resolution, and frame rate (FPS).
|
||
- Selecting the audio codec (AAC, PCM, or Opus).
|
||
- Toggling audio capture and webcam preview.
|
||
- Displaying real-time information (elapsed recording time, file size, and output filename).
|
||
|
||
- **Screen Capture Module (recorder.c / recorder.h):**
|
||
This component is responsible for capturing the screen (or a specific window) using X11 functions. It supports:
|
||
- Interactive window selection (via pointer grab and click).
|
||
- Full-screen capture with monitor geometry obtained via XRandR.
|
||
- Dynamic updates of window geometry when capturing a window.
|
||
|
||
- **Audio Capture Module (audio.c / audio.h):**
|
||
This module uses the ALSA library to capture audio from the system’s default PCM device. It allows:
|
||
- Starting and stopping audio capture.
|
||
- Dynamically toggling audio capture during recording.
|
||
|
||
- **Encoding Module (encoder.c / encoder.h):**
|
||
FFmpeg libraries are used for encoding both video and audio streams. In this module:
|
||
- Video is encoded using H.264.
|
||
- Audio can be encoded using AAC, PCM (lossless), or Opus.
|
||
- The encoded file is saved to `~/Videos/Screenrecords/` with an autogenerated name (which can be renamed after recording).
|
||
|
||
- **Main Application (main.c):**
|
||
The main file initializes GTK+3, creates the GUI, and sets up the various threads for screen capture, audio capture, and webcam preview. It also includes command-line processing for additional options:
|
||
- `--help` prints a help message.
|
||
- `--version` prints version information.
|
||
- `--debug` enables more verbose debug output during execution.
|
||
|
||
## Dependencies
|
||
|
||
To build and run **CERES**, ensure that the following dependencies are installed on your system:
|
||
|
||
- **GTK+ 3.0:** for the GUI components
|
||
(Package: `libgtk-3-dev` on Debian/Ubuntu)
|
||
|
||
- **FFmpeg Libraries:** including libavcodec, libavformat, libavutil, libswscale, libavdevice, libswresample
|
||
(Packages: `libavcodec-dev`, `libavformat-dev`, `libavutil-dev`, `libswscale-dev`, `libavdevice-dev`, `libswresample-dev`)
|
||
|
||
- **ALSA Library:** for audio capture
|
||
(Package: `libasound2-dev`)
|
||
|
||
- **X11 and XRandR:** for screen capture and monitor geometry
|
||
(Packages: `libx11-dev`, `libxrandr-dev`)
|
||
|
||
## Build Instructions
|
||
|
||
The project comes with a Makefile that automatically compiles all source files and links the required libraries. To build the project, follow these steps:
|
||
|
||
1. Install the necessary dependencies. For example, on Debian/Ubuntu run:
|
||
```bash
|
||
sudo apt-get install libgtk-3-dev libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavdevice-dev libswresample-dev libasound2-dev libx11-dev libxrandr-dev
|
||
```
|
||
|
||
2. In the project root directory, run:
|
||
```bash
|
||
make
|
||
```
|
||
This will compile the sources in the `src/` directory, output object files into the `obj/` directory, and create the executable named `screen_recorder`.
|
||
|
||
3. To clean up object files and the executable, run:
|
||
```bash
|
||
make clean
|
||
```
|
||
|
||
## Usage Instructions
|
||
|
||
After building the application, you can run it from the command line. The program supports the following options:
|
||
|
||
- **--help**
|
||
Display a help message with usage instructions and exit.
|
||
|
||
```bash
|
||
./screen_recorder --help
|
||
```
|
||
- --version
|
||
Display the application version (defined in version.h) and exit.
|
||
|
||
```bash
|
||
./screen_recorder --version
|
||
```
|
||
|
||
- --debug
|
||
Enable additional debug output (verbose logging of key operations).
|
||
|
||
```bash
|
||
./screen_recorder --debug
|
||
```
|
||
|
||
When run without these flags, the GUI will start and you can interact with it to choose the recording source, set parameters, and start/stop recordings.
|
||
|
||
## Internal Code Operation
|
||
|
||
### Screen Capture:
|
||
The recorder module uses X11 to grab either the full screen or a selected window. Using XRandR, it determines monitor geometry when a specific monitor is chosen.
|
||
|
||
### Audio Capture:
|
||
Audio is captured via ALSA, with the possibility of toggling it on or off dynamically.
|
||
|
||
### Encoding:
|
||
Video frames (captured as RGB) are converted and encoded in H.264 via FFmpeg. Audio frames are captured in PCM (S16) and then converted and encoded. The output file is written to disk.
|
||
|
||
### Multithreading:
|
||
Separate threads are used for capturing audio, capturing video, and (optionally) capturing webcam frames to avoid blocking operations and improve efficiency during long recordings.
|
||
|
||
## Future Improvements
|
||
* Implement an AVFrame pooling system or ring buffer to reduce allocation overhead.
|
||
|
||
* Investigate hardware-accelerated encoding (NVENC/QuickSync/VA-API) for improved performance.
|
||
|
||
* Explore asynchronous file I/O to prevent disk write delays during long recordings.
|
||
|
||
* Enhance debug logging throughout the code.
|