Skip to content

Instantly share code, notes, and snippets.

@Robinlovelace
Last active May 17, 2018 09:27
Show Gist options
  • Save Robinlovelace/b75c17f4ed0a98a332dbd214243487be to your computer and use it in GitHub Desktop.
Save Robinlovelace/b75c17f4ed0a98a332dbd214243487be to your computer and use it in GitHub Desktop.
Demo of using gifski (+ youtube-dl) from within R
``` r
library(future)
plan(multiprocess)
devtools::install_github("r-rust/gifski")
#> Using GitHub PAT from envvar GITHUB_PAT
#> Skipping install of 'gifski' from a github remote, the SHA1 (6f921380) has not changed since last install.
#> Use `force = TRUE` to force installation
system("pip3 install youtube-dl")
system("youtube-dl https://youtu.be/CzxeJlgePV4 -o v.mp4")
system("ffmpeg -i v.mp4 -t 00:00:03 -c copy out.mp4")
system("ffmpeg -i out.mp4 frame%04d.png ")
f = list.files(pattern = "frame")
gifski::gifski(f, gif_file = "g.gif", width = 200, height = 200)
#>
#> Frame 0 (1%) ...
#> Frame 73 (100%)
#> Finalizing encoding... done!
#> [1] "g.gif"
file.remove(f)
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [15] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [29] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [43] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [57] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
#> [71] TRUE TRUE TRUE TRUE
```
devtools::session_info()
#> Session info -------------------------------------------------------------
#> setting value
#> version R version 3.4.4 (2018-03-15)
#> system x86_64, linux-gnu
#> ui X11
#> language en_GB:en
#> collate en_GB.UTF-8
#> tz Europe/London
#> date 2018-05-17
#> Packages -----------------------------------------------------------------
#> package * version date source
#> backports 1.1.2 2017-12-13 CRAN (R 3.4.3)
#> base * 3.4.4 2018-03-16 local
#> codetools 0.2-15 2016-10-05 CRAN (R 3.3.1)
#> compiler 3.4.4 2018-03-16 local
#> curl 3.2 2018-03-28 CRAN (R 3.4.4)
#> datasets * 3.4.4 2018-03-16 local
#> devtools 1.13.5 2018-02-18 CRAN (R 3.4.4)
#> digest 0.6.15 2018-01-28 CRAN (R 3.4.3)
#> evaluate 0.10.1 2017-06-24 CRAN (R 3.4.1)
#> formatR 1.5 2017-04-25 CRAN (R 3.4.1)
#> future * 1.8.1 2018-05-03 cran (@1.8.1)
#> gifski 0.1.0 2018-05-15 Github (r-rust/gifski@6f92138)
#> git2r 0.21.0 2018-01-04 CRAN (R 3.4.3)
#> globals 0.11.0 2018-01-10 CRAN (R 3.4.3)
#> graphics * 3.4.4 2018-03-16 local
#> grDevices * 3.4.4 2018-03-16 local
#> htmltools 0.3.6 2017-04-28 cran (@0.3.6)
#> httr 1.3.1 2017-08-20 cran (@1.3.1)
#> knitr 1.20 2018-02-20 cran (@1.20)
#> listenv 0.7.0 2018-01-21 CRAN (R 3.4.3)
#> magrittr 1.5 2014-11-22 CRAN (R 3.3.2)
#> memoise 1.1.0 2017-04-21 CRAN (R 3.4.1)
#> methods * 3.4.4 2018-03-16 local
#> parallel 3.4.4 2018-03-16 local
#> R6 2.2.2 2017-06-17 cran (@2.2.2)
#> Rcpp 0.12.16 2018-03-13 CRAN (R 3.4.4)
#> rmarkdown 1.9 2018-03-01 CRAN (R 3.4.4)
#> rprojroot 1.3-2 2018-01-03 CRAN (R 3.4.3)
#> stats * 3.4.4 2018-03-16 local
#> stringi 1.2.2 2018-05-02 CRAN (R 3.4.4)
#> stringr 1.3.1 2018-05-10 CRAN (R 3.4.4)
#> tools 3.4.4 2018-03-16 local
#> utils * 3.4.4 2018-03-16 local
#> withr 2.1.2 2018-04-07 Github (jimhester/withr@79d7b0d)
#> yaml 2.1.19 2018-05-01 CRAN (R 3.4.4)
```
@Robinlovelace
Copy link
Author

Here's the result:
g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment