Automation with Screenshot

I have already achieved automated execution using https://github.com/PierreMarchand20/asciinema_automation.

However, I also want to output some screenshot after running certain commands later.

My initial attempt was:

  • Manually writing a list of keywords

  • using grep to find the corresponding timestamps in the .cast file

  • and then using ffmpeg to extract the frame corresponding to the mp4.

But I strangely found that the duration of the generated gif/mp4 did not match the cast file. (I’m not sure why)

So I changed my approach.

  • I slightly modified asciinema_automation and added a custom command #mark inside it. Then, when asciinema_automation run this instruction, it will try to insert a mark to the .cast file
  • Since I cannot directly append to the .cast file while asciinema rec is running, I chose to first record the current file line number like [42, Mark], [128, AnotherMark ] and then insert them into the .cast file after rec finishes.
  • Then I can use agg from this PR https://github.com/asciinema/agg/pull/103 to generate beautiful pngs.

For example

# Compile and run hello.c
gcc hello.c -o hello
./hello

# this is expect from asciinema_automation
#$ expect Hello, World!

#$ wait 500
# insert a mark to .cast file
#mark HelloWorldDone
#$ wait 500

Ah, thank you very much to everyone who contributed the work mentioned above