Skip to content

Ambrevar/emacs-gif-screencast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Emacs GIF Screencast

One-frame-per-action GIF recording for optimal quality/size ratio.

See Helm System Packages for examples.

Rationale

Most Emacs screencasts are done by first recording a video, then converting it to a GIF. It seems like a waste of resources considering the little animation Emacs features.

Most of the time, one user action equals one visual change. By exploiting this fact, this package tailors GIF-screencasting for Emacs and captures one frame per user action. It’s much more efficient than capturing frames even at a frequency as low as 10 per second. You could roughly expect 3 to 10 times smaller files compared to videos of the same quality. (Benchmarks are welcome.)

Conversely, should your Emacs demo feature self-animated content (such as output scrolling in Eshell), no frame will be captured. A workaround consists in hammering some no-op key such as forward-char or end-of-line.

Another neat perk of action-based captures is that it produces editable GIF files: programs such as Gifsicle or The GIMP can be used to edit the delays or rearrange frames.

This is particularly useful to fix mistakes in “post-processing”, without having to record the demo all over again.

Features, pros and cons

  • Recordings can be paused and resumed.
  • Resulting GIF files are editable, which allows for post-processing / fixing.
  • Quality is top notch.
  • File-size is optimal.
  • The result might feel a tad jittery sometimes.
  • It won’t render self-animated content such as auto-scrolling, this is workable however.
  • It should be much lighter on memory and CPU than video recording.

Implementation

Upon start, it adds gid-screencast-capture to pre-command-hook which makes every command (including those called by key presses) take a screenshot. On each screenshot, it records the timestamp.

If paused then resumed, the timestamps are offset by the length of the pause.

When stopped, it compiles the screenshots together into a GIF file using the timestamps to set the appropriate delays for each frame.

Setup

You’ll need a screenshot program and a GIF converter. Defaults are:

  • gif-screencast-program: scrot
  • gif-screencast-convert-program: convert (from the ImageMagick suite)
  • Optional: gif-screencast-optimize-program: Gifsicle

You can pass arguments to the screenshot program via git-screencast-args to command it to capture only part of the screen, e.g. you can restrict the capture to the Emacs frame with scrot’s argument --focused

You might want to set some bindings for convenience.

(with-eval-after-load 'gif-screencast
  (define-key gif-screencast-mode-map (kbd "<f8>") 'gif-screencast-toggle-pause)
  (define-key gif-screencast-mode-map (kbd "<f9>") 'gif-screencast-stop))

Start recording with gif-screencast!

macOS

macOS requires some additional settings:

(with-eval-after-load 'gif-screencast
  (setq gif-screencast-args '("-x")) ;; To shut up the shutter sound of `screencapture' (see `gif-screencast-command').
  (setq gif-screencast-cropping-program "mogrify") ;; Optional: Used to crop the capture to the Emacs frame.
  (setq gif-screencast-capture-format "ppm") ;; Optional: Required to crop captured images.

mogrify is part of the ImageMagick suite.

Display pressed keys while recording

The KeyCast package is useful to dispay the pressed keys in the modeline while recording.

About

[MOVED TO GITLAB] One-frame-per-action GIF recording for optimal quality/size ratio

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published