Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recording a timeframe not a single shot #80

Open
muschellij2 opened this issue Mar 11, 2019 · 1 comment
Open

Recording a timeframe not a single shot #80

muschellij2 opened this issue Mar 11, 2019 · 1 comment

Comments

@muschellij2
Copy link

I've been playing around with https://github.com/romainfrancois/rsciinema @romainfrancois and we've been able to get an asciicast to an GIF with the help of asciicast2gif, see (romainfrancois/rsciinema#11 for an example).

As asciicast2gif relies mainly on PhatomJS (https://github.com/asciinema/asciicast2gif/blob/master/src/asciinema/gif/main.cljs#L156) (but to be fair a lot of other JS/node), I was wondering if it'd be possible to use rmdshot but have it take multiple shots over time or a range of time.

Example below

Here we create an asciicast which can has an RMarkdown/Shiny output object that will render when put in an Rmd. The output will

library(rsciinema)
input = paste0("library(magrittr); # a comment is a gra", backspace(), "eat thing to do", 
               "\niris %>% \n  dplyr::group_by(Species) %>%\n  ", 
               "dplyr::summarise_all(mean) \n # a new line")
data = asciicast( input, speed = 0.2)
  out = asciinema(data = data, autoplay = TRUE, loop = FALSE)
  tfile = tempfile()
  dput(out, file = tfile)
  dout = readLines(tfile)

  x = c("---", "output: rsciinema::asciinema_document", "---", "",
        "```{r, echo = FALSE}", 
        "library(rsciinema)",
        dout,
        "```"
        )
  tfile = tempfile(fileext = ".Rmd")
  writeLines(x, con = tfile, sep ="\n")

Setting multiple files for rmdshot/webshot did not achieve the results we're looking for. Just wanted to know if any insight possible or if a better approach would be to hack the asciicast2gif JS to it's core, then use the PhantomJS install from webshot.

@wch
Copy link
Owner

wch commented Aug 7, 2019

I have some rough code for recording frames of a web page using chromote:

library(chromote)
b <- ChromoteSession$new(width = 480, height = 360)
frames <- list()
cancel_save_screencast_frames <- b$Page$screencastFrame(callback_ = function(value) {
  frames[[length(frames) + 1]] <<- value
  cat(".")
})
b$Page$navigate("http://giphygifs.s3.amazonaws.com/media/73FzKOYDpp7VK/giphy.mp4")
b$Page$startScreencast(format = "png", everyNthFrame = 2)


# Stop after 6 seconds
later(
  function() {
    b$Page$stopScreencast()
    cancel_save_screencast_frames()

    lapply(seq_along(frames), function(i) {
      writeBin(jsonlite::base64_dec(frames[[i]]$data), sprintf("frame%02d.png", i))  
    })
    b$close()
    message("done")
  },
  6
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants