Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Asciinema for video recording in Linux

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use Asciinema for video recording in Linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use Asciinema for video recording in Linux"!

Brief introduction

Asciinema is a lightweight and very efficient terminal session recorder. Use it to record, play back and share terminal session records in JSON format. Compared with some desktop recorders, such as Recordmydesktop, Simplescreenrecorder, Vokoscreen, or Kazam, the main advantage of Asciinema is that it can record all standard terminal input, output, and error messages through ASCII text and ANSI escape code encoding.

In fact, even for a long terminal session, the recorded files in JSON format are very small. In addition, the JSON format allows users to use a simple file converter to embed the output JSON format file into HTML code and share it to a public website or to Asciinema.org using an asciinema account. * if there are some errors in your terminal session and you know some ASCI escape code syntax, you can use any editor to modify your recorded terminal session.

Degree of difficulty:

It's simple!

Standard terminal:

#-A given command needs to be run as root or use the sudo command

$- A given command is run with general privileges

Install from the software library

In general, asciinema can be installed using the software libraries of your distribution. However, if you cannot install using the system's software library or if you want to install a version of *, you can use the Linuxbrew package manager to perform an Asciinema installation, as described in the "install from source" section below.

Install on Arch Linux:

# pacman-S asciinema

Install on Debian:

# apt install asciinema

Install on Ubuntu:

$sudo apt install asciinema

Install on Fedora:

$sudo dnf install asciinema

Install from source code

The easiest and recommended way is to use the Linuxbrew package manager to install the * * version of Asciinema from the source code.

prerequisite

The prerequisites listed below are the dependencies to be met to install Linuxbrew and Asciinema:

Git

Gcc

Make

Ruby

Before installing Linuxbrew, make sure that the above packages are installed on your Linux system.

Install ruby on Arch Linux:

# pacman-S git gcc make ruby

Install ruby on Debian:

# apt install git gcc make ruby

Install ruby on Ubuntu:

$sudo apt install git gcc make ruby

Install ruby on Fedora:

$sudo dnf install git gcc make ruby

Install ruby on CentOS:

# yum install git gcc make ruby

Install Linuxbrew

The Linuxbrew package Manager is a replica of Homebrew package Manager, which is popular in Apple's MacOS operating system. Not long after its release, Homebrew is known for its ease of use. If you want to use Linuxbrew to install Asciinema, run the following command to install Linuxbrew on your version of Linux:

$ruby-e "$(curl-fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"

Linuxbrew is now installed in the directory $HOME/.linuxbrew/. All that's left is to make it part of the executable PATH environment variable.

$echo 'export PATH= "$HOME/.linuxbrew/bin:$PATH" > ~ / .bash_profile$. ~ / .bash_profile

To verify that Linuxbrew is installed, you can use the brew command to check its version:

$brew--versionHomebrew 1.1.7Homebrew/homebrew-core (git revision 5229; last commit 2017-02-02)

Install Asciinema

Once Linuxbrew is installed, it becomes extremely easy to install Asciinema:

$brew install asciinema

Check that Asciinema is installed correctly:

$asciinema-- versionasciinema 1.3.0

Recording a terminal session

After some painstaking installation work, it's time to do something interesting. Asciinema is a very easy to use software. In fact, there are only a few command-line options available in the current version 1.3, one of which is-- help.

We first use the rec option to record the terminal session. The following command will start recording the terminal session, after which you will have an option to discard the recorded record or upload it to the asciinema.org website for future reference.

$asciinema rec

After running the above command, you will notice that Asciinema has started recording the terminal session, you can press the CTRL+D shortcut key or execute the exit command to stop recording. If you are using Debian/Ubuntu/Mint Linux system, you can try to make * asciinema recordings as follows:

$su Password: # apt install sl # exit $sl

Once you enter an exit command, you will be asked:

$exit ~ Asciicast recording finished. ~ Press to upload, to cancel. Https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4

If you don't want to upload your private command line skills to the asciinema.org site, there is an option to save the Asciinema record as a local file in JSON format. For example, the following asciinema record will be saved as / tmp/my_rec.json:

$asciinema rec / tmp/my_rec.json

Another very useful asciinema feature is time fine tuning. If your keyboard is slow, or if you are multitasking, there will be a long time between typing and executing commands. Asciinema will record your real-time keystrokes, which means that each pause will be reflected in the length of the final video. You can use the-w option to shorten the interval between keystrokes. For example, the following command reduces the interval between keystrokes to 0.2 seconds:

$asciinema rec-w 0.2

Playback a recorded terminal session

There are two ways to play a recorded session back and forth. * the way is to play the terminal session directly from the asciinema.org website. This means that you have previously uploaded the recording session to the asciinema.org website and need to provide a valid link:

$asciinema play https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4

In addition, you can also use locally stored JSON files:

$asciinema play / tmp/my_rec.json

To download the previous upload record using the wget command, simply add .json to the end of the link:

$wget-Q-O steam_locomotive.json https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4.json $asciinema play steam_locomotive.json

Embed video into HTML

* asciinema also comes with a separate JavaScript player. This means that you can easily share terminal conversations on your website. Next, use a simple piece of index.html code to illustrate this method. First, download everything necessary:

$cd / tmp/ $mkdir steam_locomotive $cd steam_locomotive/ $wget-Q-O steam_locomotive.json https://asciinema.org/a/7lw94ys68gsgr1yzdtzwijxm4.json $wget-Q https://github.com/asciinema/asciinema-player/releases/download/v2.4.0/asciinema-player.css $wget-Q https://github.com/asciinema/asciinema-player/releases/download/v2.4.0/asciinema-player.js

After that, create a new / tmp/steam_locomotive/index.html file that contains the following:

When you are finished, open your web browser and press CTRL+O to open the newly created / tmp/steam_locomotive/index.html file.

Conclusion

As mentioned earlier, the main advantage of using the asciinema recorder to record a terminal session is that its output file is very small, which makes your video easy to share. The above example produces a 58472-character file, which is a 22-second terminal session video with a size of only 58 KB. If we look at the output JSON file, we will find that even this number is already very large, mainly because a "steam locomotive" has run past the terminal. A normal terminal session of this length usually results in a smaller output file.

The next time you want to ask questions about Linux configuration in a forum and it is difficult to describe your problem, just run the following command:

$asciinema rec

Then post the link to the forum post.

Troubleshooting

Run asciinema in UTF-8 environment

Error message:

Asciinema needs a UTF-8 native locale to run. Check the output of `locale` command.

Solution: build and export the UTF-8 locale. For example:

Localedef-c-f UTF-8-I en_US en_US.UTF-8$ export LC_ALL=en_US.UTF-8 here, I believe you have a better understanding of "how to use Asciinema for video recording in Linux". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 285

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report