Skip to content

Instantly share code, notes, and snippets.

@Frajder
Last active April 3, 2024 06:29
Show Gist options
  • Save Frajder/8d1504985416556d1a91f847573c075c to your computer and use it in GitHub Desktop.
Save Frajder/8d1504985416556d1a91f847573c075c to your computer and use it in GitHub Desktop.
Recording My Desktop Using CLI (xwininfo, recordmydesktop,ffmpeg)

Python 3 Virtual Environment Setup

Why Use a Virtual Environment?

A virtual environment in Python is a self-contained directory that holds your project's Python interpreter, libraries, and scripts. This setup ensures that each project has its own dependencies, regardless of the dependencies of other projects. This isolation prevents conflicts between projects and makes dependency management much easier.

Installing Python and Virtual Environment

First, install Python 3, pip, and the virtual environment package. Open your terminal and run:

sudo apt install python3-pip python3-venv

Creating a New Virtual Environment

To create a new virtual environment, use the following commands. This example creates a virtual environment for a project called "telegram-client":

mkdir -p ~/.venv/telegram-client
python3 -m venv ~/.venv/telegram-client

Activating the Virtual Environment

Before you start working on your project, you need to activate the virtual environment. To do this, run:

source ~/.venv/telegram-client/bin/activate

Once activated, your terminal prompt will change to indicate that you are now working inside the virtual environment.

Working with Different Python Versions

If you have multiple Python versions installed and want to create a virtual environment with a specific Python version, you can specify the Python interpreter. For example, to create a virtual environment with Python 3.8, you would use:

python3.8 -m venv ~/.venv/telegram-client

Ensure that the desired Python version is installed on your system. You can install a specific Python version using a package manager or by downloading it from the Python website.

Using the Virtual Environment

After activating the virtual environment, you can install packages using pip. For example, to work with LonamiWebs/Telethon, you can clone the repository and install its requirements:

git clone https://github.com/LonamiWebs/Telethon.git
cd Telethon
pip install -r requirements.txt

Alternatively, you can install Telethon directly from PyPI using:

pip install telethon

Remember to deactivate the virtual environment when you're done working on your project by running:

deactivate

This guide should help you set up a Python 3 virtual environment and manage dependencies for your projects more effectively.

Recording My Desktop Using CLI (Linux)

Step 1: Select the Window You Wish to Record

Execute the following command to identify the window:

xwininfo | awk '/Window id:/ {print $4}'

Step 2: Click on the Window

Doing so will provide a windowid as shown below:

└─$ xwininfo | awk '/Window id:/ {print $4}'
0x500003e

Step 3: Start Recording by Specifying the windowid

Use the windowid as an input argument in the command:

recordmydesktop --windowid=0x500003e

Step 4: Terminate Recording

Press Ctrl+C (once) when you have finished recording.

Below is an example of the output you will see:

Initial recording window is set to:
X:3000   Y:0    Width:1920    Height:1080
Adjusted recording window is set to:
X:3000   Y:0    Width:1920    Height:1088
Your window manager appears to be Xfwm4

Detected compositing window manager.
Reverting to full screen capture at every frame.
To disable this check, run with --no-wm-check
(although not recommended, as it may produce suboptimal results).

Initializing...
Buffer size adjusted to 4096 from 4096 frames.
Opened PCM device default.
Recording on device default is set to:
1 channels at 22050Hz.
Capturing!
^C
*********************************************                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                              
Cached 856 MB, from 16527 MB that were received.                                                                                                                                                                                                                              
Average cache compression ratio: 94.8%.                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                              
*********************************************
Saved 2074 frames in a total of 2061 requests.
Shutting down...
STATE: ENCODING
Encoding started!
This may take several minutes.
Pressing Ctrl-C will cancel the process (resuming will not be possible, but
any portion of the video already encoded will not be deleted).
Please wait...
Output file: out-1.ogv
[100%]  [Cache File 1]
Encoding finished!
Please wait a moment...

Done.
Written 26568903 bytes
(26556324 of which were video data and 12579 audio data)

Cleaning up cache...
Done!!!
Goodbye!

Step 5: Convert OGV to MP4 (excluding audio in this case):

ffmpeg -i out-1.ogv -c:v libx264 -crf 23 -preset veryfast -an out-1.mp4

Step 6: Trim Part of the Video

To cut the video from 00:01:40 until the end (as needed) and save it as a new file:

ffmpeg -i out-1.mp4 -ss 00:01:40 -c copy zoom-in.mp4

Hopes it helps @Frajder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment