How to convert a terminal recording to a GIF?

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.


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.*