wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Add screenshot/gif/video api

Open prabirshrestha opened this issue 3 years ago • 4 comments

Opening a new issue based on this https://github.com/wez/wezterm/issues/294#issuecomment-706785821

Would it be possible to have a wezterm lua api to take screenshots? I can then bind a key to perform these actions.

wezterm.screenshot({ output = "1.png", input = {wezterm.pane(1) }  })
local id = wezterm.start_recording({ output = "1.gif", fps = 30, input = {wezterm.window} })
wezterm.stop_recording(id)

Trying to find a recording tool that works cross platform is a mess that installs tons of tools and barely works.

Might also need temp files/folders api. Could take inpirations from luv api.

local tmpdir = wezterm.tempdir()
local tmpfile = wezterm.tmpfile()

Another option is to be able to output to asciinema format but unfortunately this doesnt have gif.

prabirshrestha avatar Mar 07 '21 19:03 prabirshrestha

I think having some methods (and corresponding key assignment actions) like these would be nice:

  • pane:screenshot(filename) - save as png
  • pane:start_recording(filename, [fps, format])
  • pane:stop_recording() (I don't want to support multiple recordings for the same pane, so there's no id/context parameter for this)

I would lean towards supporting gif first. Maybe support writing a series of png frames in lieu of more complex video file encoding, depending on whether there is a good encoder available in the rust ecosystem.

I also like the idea of supporting asciinema; that would help replace the wt-record stuff that is mentioned in our bug reporting stuff. Thankfully, the file format is open source and quite simple, so it shouldn't be terribly difficult to support.

wez avatar Mar 07 '21 23:03 wez

The api looks good to me. I'm ok only having one recording at a time. screenshot api might also want to take options for format, quality in future. It might make sense to support window level recording first since that way one can use it to record multiple panes and include demo gifs.

Another option is to support wezterm rec that records asciicast-v2 format and then have another command wezterm convert -in=rec.cast -out=rec.gif --fps=30 --background=.... This would easily allow to share as well as change colors.

I'm also primarily interested in gifs first since this is really the paint point that I have currently.

prabirshrestha avatar Mar 08 '21 21:03 prabirshrestha

I looked at this a bit yesterday; it's currently blocked because EGL doesn't seem to be compatible with the apis that read pixel buffers. Need to figure this out.

wez avatar Mar 08 '21 21:03 wez

Fyi asciinema 3 cli dev branch is now written in rust. Would be neat to see integration to start and stop recording in wezterm. 🤞

There is now https://github.com/asciinema/agg (rust) to convert these to gif. You can also use https://github.com/charmbracelet/vhs and play asciinema inside it to produce other formats.

sedlund avatar Apr 12 '24 22:04 sedlund