asciinema-rs icon indicating copy to clipboard operation
asciinema-rs copied to clipboard

Gif output support

Open piaoger opened this issue 7 years ago • 13 comments

I might be a good idea to build a new tool or sub-command which convert cast to gif(or svg). Original asciinema2gif is useful but installing deps is boring :) asciinema2gif: link

piaoger avatar Mar 28 '18 00:03 piaoger

I think it could go in this tool. I see two logical entry points:

  1. For new recordings: asciinema rec /path/to/file.cast --format gif/svg/whatever
  2. For existing recordings: asciinema convert /path/to/file.cast --format gif/svg/whatever

LegNeato avatar Mar 28 '18 19:03 LegNeato

Some quick notes after investigation:

  • I think the best way forward would be to use https://github.com/jwilm/alacritty to parse and render the tty. There appears to be a way to get their display grid (https://github.com/jwilm/alacritty/blob/master/tests/ref.rs).
  • We could go from the alacritty display grid to our own render, but seems hard.
  • alacritty uses glutin under the covers (https://github.com/jwilm/alacritty/blob/master/src/window.rs).
  • Likely need to wait for https://github.com/jwilm/alacritty/issues/450.
  • Glutin has a headless renderer (https://docs.rs/glutin/0.13.1/glutin/struct.HeadlessRendererBuilder.html).
  • An example of how to save the GL data to an image is at https://github.com/bwasty/gltf-viewer/blob/14342da1ae8ba6d832f0088a92743e8a3a428329/src/viewer.rs#L328 and how to use a headless context is at https://github.com/bwasty/gltf-viewer/blob/14342da1ae8ba6d832f0088a92743e8a3a428329/src/viewer.rs#L86.
  • Looks like there may be a bug with the headless glutin context on linux: https://github.com/tomaka/glutin/issues/988

LegNeato avatar Mar 28 '18 20:03 LegNeato

I've been poking at this and have been able to render a static image using alacritty. There are some outstanding issues but nothing that can't be resolved, so this is definitely going to be possible somewhat soon.

output

LegNeato avatar Apr 03 '18 17:04 LegNeato

Update: I got gif support working, including clamping to 60fps and having proper duration between frames to keep file size down:

output

I'm going to clean it up a bit, report my findings to alacritty so they can merge their WIP diff, and then we will support gifs!

LegNeato avatar Apr 04 '18 02:04 LegNeato

It seems we can have gif support soon🤔

piaoger avatar Apr 17 '18 01:04 piaoger

not sure if gifski is helpful which is gapl licensed. https://github.com/ImageOptim/gifski

piaoger avatar Apr 17 '18 01:04 piaoger

There are also (Node) projects that render as SVG: https://github.com/marionebl/svg-term-cli https://github.com/derhuerst/asciicast-to-svg

Would outputting multiple filetypes in one invocation be a good idea?

polyzen avatar Jul 14 '18 01:07 polyzen

I've implemented a minimal virtual terminal in Rust for asciinema recently, for the purpose of integrating it into web player (rust-wasm) and screenshot generation: https://github.com/asciinema/vt-rs

It's working nicely, although I haven't had a chance of preparing README, publishing to crates.io, nor integrating into web player. Not sure if useful to you at this stage but I thought mentioning it won't hurt :)

ku1ik avatar Jul 18 '19 15:07 ku1ik

Sweet, looks awesome! I'll look into integrating, the alacritty changes have stalled.

LegNeato avatar Jul 18 '19 16:07 LegNeato

I've just started working on finding a way to render gif's. I'm posting what I find in a forum topic.

I think it might be simple enough to support SVG, animated PNG, and Gif with one solution.

I'm going to try to put the converter logic into its own crate lib/cli because I think it would be useful to people who still want to use the normal asciinema CLI, but we can also include the crate as a library to asciinema-rs so that it is built-in to this tool as well.

zicklag avatar Mar 14 '20 17:03 zicklag

Found someone using this tool: https://github.com/nbedos/termtosvg

piaoger avatar May 24 '20 10:05 piaoger

@piaoger Yes, I've used that before. It is very nice. My biggest problem came when I needed to paste a recording into GitHub and they for some reason don't support SVG in comments!

I forgot to post an update by my https://github.com/katharostech/cast2gif/ program is actually basically working. It needs some new features to be a little nicer, but it is functional now. It's a rust crate so we could incorporate it into asciinema-rs.

zicklag avatar May 24 '20 13:05 zicklag

@zicklag
yes. I found cast2gif and you also mentioned termtosvg in the post after that.Let me try asciinema-rs and cast2gif together.

piaoger avatar May 24 '20 13:05 piaoger