Update docs/tech_docs/linux/video_capture.md
This commit is contained in:
@@ -71,4 +71,84 @@ This script is a foundational structure that illustrates capturing video, proces
|
||||
|
||||
Combining `ffmpeg` for recording and audio extraction, `MKVToolNix
|
||||
|
||||
` for video editing, and DeepSpeech for audio transcription into a cohesive, scripted workflow offers a powerful solution for your video production needs on Debian Linux. This approach leverages your Linux expertise, allowing for extensive customization and automation to streamline your video recording and processing tasks.
|
||||
` for video editing, and DeepSpeech for audio transcription into a cohesive, scripted workflow offers a powerful solution for your video production needs on Debian Linux. This approach leverages your Linux expertise, allowing for extensive customization and automation to streamline your video recording and processing tasks.
|
||||
|
||||
---
|
||||
|
||||
Creating a technical guide for using `ffmpeg` to record X11 sessions on Linux involves understanding a few key components: how to use `ffmpeg` for screen capture, determining your display settings with `xdpyinfo`, and potentially targeting specific windows or areas of your screen. Let’s break down the process into digestible steps.
|
||||
|
||||
### 1. Installing Dependencies
|
||||
|
||||
First, ensure you have `ffmpeg` and `xdpyinfo` installed on your system. `xdpyinfo` is used to query X11 display configuration, which is necessary to define the recording area for `ffmpeg`.
|
||||
|
||||
```bash
|
||||
sudo apt update
|
||||
sudo apt install ffmpeg x11-utils
|
||||
```
|
||||
|
||||
### 2. Understanding `xdpyinfo`
|
||||
|
||||
Before recording, you need to determine your screen's dimensions and the display number. `xdpyinfo` provides this information.
|
||||
|
||||
- **Check Display Dimensions**:
|
||||
```bash
|
||||
xdpyinfo | grep 'dimensions:'
|
||||
```
|
||||
This command outputs the dimensions of your screen, which is crucial for setting the recording area in `ffmpeg`.
|
||||
|
||||
- **Identify Display Number**:
|
||||
Your display number (`:0.0` in most cases) is typically set in the `DISPLAY` environment variable. You can echo this variable to find out your display number:
|
||||
```bash
|
||||
echo $DISPLAY
|
||||
```
|
||||
|
||||
### 3. Recording the Entire Screen with `ffmpeg`
|
||||
|
||||
To record your entire screen using `ffmpeg`, use the following command:
|
||||
|
||||
```bash
|
||||
ffmpeg -f x11grab -r 30 -s $(xdpyinfo | grep 'dimensions:'| awk '{print $2}') -i :0.0 -vcodec libx264 -preset ultrafast -crf 17 output.mkv
|
||||
```
|
||||
|
||||
- `-f x11grab`: Tells `ffmpeg` to use the X11 grabbing device.
|
||||
- `-r 30`: Sets the frame rate to 30 fps.
|
||||
- `-s`: Specifies the video size. `$(xdpyinfo | grep 'dimensions:'| awk '{print $2}')` automatically fills in the screen dimensions.
|
||||
- `-i :0.0`: Indicates the input source display (change `:0.0` as per your `$DISPLAY` value).
|
||||
- `-vcodec libx264`: Uses the libx264 codec for video encoding.
|
||||
- `-preset ultrafast`: Sets the encoding to ultrafast mode for less CPU usage (at the cost of increased file size).
|
||||
- `-crf 17`: Sets the Constant Rate Factor to 17, balancing between quality and file size.
|
||||
- `output.mkv`: The name of the output file.
|
||||
|
||||
### 4. Recording a Specific Window
|
||||
|
||||
To record a specific window, you'll first need to find its ID or geometry:
|
||||
|
||||
- **Find a Window ID**:
|
||||
Use `xwininfo`, click on the window you wish to record, and note the `Window id`.
|
||||
|
||||
- **Record a Specific Window**:
|
||||
Replace `-s` and `-i` parameters in the `ffmpeg` command with the window geometry or use the window ID directly if possible. The command varies based on the window's geometry or the method used to capture.
|
||||
|
||||
### 5. Audio Recording
|
||||
|
||||
To include audio in your screen recording, you'll need to specify an audio input source using the `-f` option for `ffmpeg` and the specific audio device:
|
||||
|
||||
```bash
|
||||
ffmpeg -f x11grab -r 30 -s $(xdpyinfo | grep 'dimensions:'| awk '{print $2}') -i :0.0 -f pulse -ac 2 -i default -vcodec libx264 -preset ultrafast -crf 17 -acodec aac output.mkv
|
||||
```
|
||||
|
||||
- `-f pulse`: Specifies PulseAudio as the audio input format.
|
||||
- `-ac 2`: Sets the audio channels to 2 (stereo).
|
||||
- `-i default`: Uses the default PulseAudio input device. You might need to change this based on your audio setup.
|
||||
|
||||
### 6. Optimizing Performance
|
||||
|
||||
Recording can be resource-intensive. Here are a few tips to optimize performance:
|
||||
|
||||
- **Use a lighter codec or preset**: If CPU usage is a concern, consider changing the codec or using a faster preset.
|
||||
- **Lower the frame rate**: Reducing the frame rate can decrease the file size and CPU load.
|
||||
- **Record a smaller area**: Instead of the entire screen, recording a smaller area or a specific window can be more efficient.
|
||||
|
||||
### Conclusion
|
||||
|
||||
This guide provides a foundation for using `ffmpeg` to record X11 sessions on Linux. Tailor these commands to fit your specific needs, whether recording the entire screen, specific windows, or including system audio. Remember, experimentation and optimization based on your hardware and requirements will yield the best results.
|
||||
Reference in New Issue
Block a user