Skip to main content

A asciicast to gif utility

Project description

ttygif

A full featured text to gif conversion utility, that just works.

Why use ttygif?

  • its fast, and easy to install
  • can be used with a pipe
  • it can be scripted
  • it can read asciicast files
  • it runs headless
  • perfect fit for CI/CD

install

## requirements gcc and python development libs
pip install ttygif --user

It's portable

ttygif is self contained with no dependencys other than python. GIF encoding and termal emulation are both implimented with internal cython code. No system fonts are required. All you need to get ttygif to work is a c compiler, python and its development libs. ttygif is a cython project.

usage

ttygif version 1.0.792
usage: ttygif [-h] [--input FILE] [--output FILE] [--loop COUNT] [--delay MS]
              [--record FILE] [--dilation RATE] [--fps FPS] [--width WIDTH]
              [--height HEIGHT] [--debug]

tty output to gif

optional arguments:
  -h, --help       show this help message and exit
  --input FILE     asciinema .cast file (default: None)
  --output FILE    gif output file (default: None)
  --loop COUNT     number of loops to play, 0=unlimited (default: 0)
  --delay MS       delay before restarting gif in milliseconds (default: 100)
  --record FILE    output generated cast data to file (default: None)
  --dilation RATE  process events at a faster or slower rate of time (default:
                   1)
  --fps FPS        encode at (n) frames per second (0-25) 0=speed of cast
                   file, min 3ms (default: 0)
  --width WIDTH    change character width of gif, default is 80 or what is in
                   the cast file (default: None)
  --height HEIGHT  change character height of gif, default is 25 or what is in
                   the cast file (default: None)
  --debug          show debuging statistics (default: None)

cast file to gif

ttygif --input  232377.cast --output ls_pipe.gif --fps=33

pipe to gif

ls -lhatsR | ttygif --output ls_pipe.gif --fps=0

slow down gif

ls -lhatsR | ttygif --output ls_pipe.gif --fps=0 --dilate 10

speed up gif

ls -lhatsR | ttygif --output ls_pipe.gif --fps=0 --dilate .5

Supported fonts

ESCAPE CODE SUPPORT

  • the letters n and m in the middle of the escape sequence are numeric substitutions
  • ignore whitespace
Type Code Name
CSI ^[ n A CUU Cursor up
CSI ^[ n B CUD Cursor down
CSI ^[ n C CUF Cursor Forward
CSI ^[ n D CUB Cursor Back
CSI ^[ n E CNL Cursor Next Line
CSI ^[ n F CPL Cursor Previous Line
CSI ^[ n G CHA Cursor Horizontal Absolute
CSI ^[ n;m H CUP Cursor Position
CSI ^[ n J ED Erase Display
CSI ^[ n K EL Erase Line
CSI ^[ n P DCH Delete Character
CSI ^[ n X ECH Erase Character
CSI ^[ n d VPA Vertical Position Absolute
CSI ^[ n ` HPA Horizontal Position Absolute
CSI ^[ n;m f HVP Horizontal / Vertical position
CSI ^[ n;m m Set Text Attributes
CSI ^[ s SCP Save Cursor Position
CSI ^[ u RCP Restore Cursor Position
DEC ^[ n;m r DECSTBM Set Top and Bottom Margins
DEC ^[? 7 h DECAWM Auto Wrap Mode / Set
DEC ^[? 7 l DECAWM Auto Wrap Mode / Reset
DEC ^[ 25 h DECTCEM Text Cursor Enable Mode / Set
DEC ^[ 25 l DECTCEM Text Cursor Enable Mode / Reset
DEC ^[?1049h Alternate Screen / Set
DEC ^[?1049l Alternate Screen / Reset
^[?2004h Enable Bracket Paste Mode
^[?2004l Disable Bracket Paste Mode

Features still left to handle

  • documentation
  • font mapping for utf 8,16,13 characters to base 256 map
  • embed event stream in gif as control header data
  • time period ( capture partial recording based on time stamps x-y)
  • add progress bar to top/bottom of gif with n of y H:M:I:S
  • palette flags, monochrome, grayscale, system, custom, count [n]<256
  • gif color consoladataion, for lower bit count (<8) compression
  • asciicast v1 support
  • cursor emulation
  • image underlay (branding)
  • image overlay (branding)
  • cliping
  • origin x,y
  • logging with ansi stripping
  • split every n seconds or size
  • export as frames
  • theme/solarized/bright/microsoft
  • frames, windows 95, x11, mac, fedora, gnome, cinnamon
  • start and end frames, with delays

The benchmark for speed

  • A medium density 60 second screen recording can be rendered to gif in less than 5 seconds.

ttygif-assets

The following resources are located in the ttygif-assets repo

Examples

some random pics from the asciinema.org website, and my computer

htop

htop

pipe

htop

Terminal ray tracing

asciicast-174524

term-tris dt cannon

asciicast-232377

Denariusd compile on 30 cores!

asciicast-234628

surpirsed Pikachu

asciicast-236096

CACA_DRIVER=ncurses cacademo

asciicast-687

Notes

asciicast may split data between events, causing escape codes not to be recognised. ttygif moves all trailing unformed escape codes to the next event. the gif techincal minimum for internal delays is 1ms. I default to 3ms. Testing shows various applications randnomly do not obey values from 1ms to 10ms.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttygif-1.1.551.tar.gz (1.4 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page