Score:2

How to convert a terminal recording to a GIF?

gh flag

I made a terminal record with the script tool.

mediainfo video 
General
Complete name                            : video
File size                                : 1.29 KiB

I can play it with scriptreplay. Is it possible to convert it to a GIF, for example with ffmpeg or another program?

To clarify, I mean script from the bsdutils package, not a program script. I thought that the saved file is a kind of video, so I can grep some frames/pictures and create a GIF of it.

I hope it is more clear now.

Nmath avatar
ng flag
It's not clear what you are asking. `.gif` is an image file format. What does it have to do with your script? Please edit your question and include more context and details.
Score:5
ca flag

A nice option is to use ttyrec to record your terminal activity and then convert it to a GIF using ttygif.

  1. Install the ttyrec and ttygif packages:

    sudo apt install ttyrec ttygif
    
  2. Open a terminal and start ttyrec to record your terminal:

    ttyrec
    

    Running ttyrec without an argument will save the recording in a file named ttyrecord in your current folder. You can specify a filename as an argument to save the file with this name.

  3. Use your terminal.

  4. Press Ctrl+D to stop recording.

  5. To convert the recording to a GIF, run:

    ttygif ttyrecord
    

    If you saved the recording with another filename, change ttyrecord to the filename you used.

    This command will save the recording as a GIF with the name tty.gif.


Here is a GIF I created with the above procedure that contains the above procedure:

GIF containing the above procedure


Notes

  • If you get this error when you run ttygif:

    Error: WINDOWID environment variable was empty
    

    you need to run the following command before running ttygif:

    export WINDOWID=$(xdotool getwindowfocus)
    

    The above command needs xodtool. You can install it using:

    sudo apt install xdotool
    

    Reference: https://github.com/icholy/ttygif#additional-notes

  • ttygif does nor work with qterminal for some reason. Use another terminal for the conversion instead.

    I have confirmed that it works fine with kitty, it's slow with GNOME terminal, and it's extremely fast with XTerm.

  • The ttygif command can produce big-size directories in /tmp. I recommend removing them manually after the conversion using:

    rm -r /tmp/ttygif.*
    
Raffa avatar
jp flag
Nice colors :) ... +1
BeastOfCaerbannog avatar
ca flag
@Raffa Thank you! I'm using `zsh` with the [spaceship prompt](https://spaceship-prompt.sh/). My terminal is [kitty](https://sw.kovidgoyal.net/kitty/) and the theme I use is [Argonaut](https://github.com/daveyarwood/kitty-themes#argonaut). :)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.