<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/make-a-trailer-for-your-slidedeck-with-av/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://masalmon.eu/2018/10/07/trailer/"> Posts on Maëlle's R blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>rOpenSci post-doc hacker <a rel="nofollow" href="https://github.com/jeroen/" target="_blank">Jeroen Ooms</a> has just released a cool new package, <a rel="nofollow" href="https://github.com/ropensci/av" target="_blank"><code>av</code></a>, <a rel="nofollow" href="https://ropensci.org/technotes/2018/10/06/av-release/" target="_blank">that he wrote “will become the video counterpart of the magick package which [rOpenSci uses] for working with images.”</a>. <code>av</code> provides bindings to the FFmepg libraries for editing videos. It’s already become a renderer for <a rel="nofollow" href="https://github.com/thomasp85/gganimate" target="_blank"><code>gganimate</code> by Thomas Lin Pedersen</a>, but <code>av</code> allows more than making videos of graphics. In this post, I’ll show how to use <code>av</code> and <code>webshot</code> to make a trailer/sneak preview of a slidedeck, i.e. a short video featuring the first few slides on music!</p>

<h1>Why make a trailer of your slidedeck?</h1>
<p>No, making a trailer of a slidedeck isn’t only a pretext for trying out <code>av</code>! In case you hadn’t noticed, I’m all about promoting your work once you’ve put in the work. I’ve even written <a rel="nofollow" href="https://masalmon.eu/2018/07/16/soapbox/" target="_blank">a whole post about blog promotion</a>. Promoting a slidedeck after a talk, or a talk before the event, is quite similar to promoting a blog post both in terms of benefits and technically. In particular, a tweet about it will be more powerful if featuring an illustration, and why not making it animated?</p>
<p>For more tips about advertising for a thing via a talk, check out the excellent <a rel="nofollow" href="https://www.tidyverse.org/articles/2018/07/carpe-talk/" target="_blank">“Carpe Talk” article on tidyverse.org</a> by <a rel="nofollow" href="https://jennybryan.org/" target="_blank">Jenny Bryan</a> and <a rel="nofollow" href="https://maraaverick.rbind.io/" target="_blank">Mara Averick</a>.</p>
<h1>Capture the first few slides</h1>
<p>In this post, I’ll use <a rel="nofollow" href="https://jeroen.github.io/uros2018" target="_blank">the slidedeck that Jeroen shared after giving a talk about R infrastructure after the uRos conference</a>. I’ll capture the first few slides minus the ones where he introduced himself, because I wanted the focus of the trailer to be on the talk topic. I didnd’t know <code>webshot::webshot()</code> was vectorized, thanks to Jeroen for telling me that which shortened the code below.</p>
<pre><code>fs::dir_create(&quot;slides&quot;)

urls &lt;- sprintf(&quot;https://jeroen.github.io/uros2018/#%d&quot;,
                c(1:2, 5:10))
webshot::webshot(urls, 'slides/webshot.png')
</code></pre>
<p>At that point, I had a folder with 8 PNGs. If your talk isn’t html, but say Power Point, you could export to PDF, and use <a rel="nofollow" href="https://github.com/ropensci/pdftools" target="_blank">the rOpenSci <code>pdftools</code> package</a> <a rel="nofollow" href="https://github.com/ropensci/pdftools#bonus-feature-rendering-pdf" target="_blank">to render slides to images</a>. Note that the PNGs I got didn’t have the right font, which is something I could solve by using decktape instead of <code>webshot</code>, to render the html slides to PDF and then to PNG with <code>pdftools</code>.</p>
<h1>Create the video</h1>
<p>The video creation was extremely simple and fast once I had selected a soundtrack. Note that having a soundtrack is optional!</p>
<p>Jeroen’s talk was about building stuff so I looked for construction sounds and selected <a rel="nofollow" href="https://www.zapsplat.com/music/road-construction-environment-with-jackhammer/" target="_blank">this sample published by Audio Hero on Zapsplat</a></p>
<pre><code>slides &lt;- fs::dir_ls(&quot;slides&quot;)
slides &lt;- c(slides[1], slides, slides[length(slides)])

av::av_encode_video(slides,
                    # it could be a fraction!
                    framerate = 1,
                    # if too short there'll be silence 
                    # at the end
                    # if too long it'll be truncated
                    audio = audio,
                    output = &quot;trailer.mp4&quot;)
</code></pre>
<p><video width="100%" controls><source src="https://masalmon.eu/figure/source/2018-10-07-trailer/trailer.mp4">Trailer of Jeroen’s slidedeck. Your browser does not support the video tag.</video></p>
<p>Tada! Thanks <a rel="nofollow" href="https://www.zapsplat.com/music/road-construction-environment-with-jackhammer/" target="_blank">to Audio Hero for the sound sample</a>. Now, if you want to read more of that cool slidedeck, you’ll find it <a rel="nofollow" href="https://jeroen.github.io/uros2018/#1" target="_blank">here</a>.</p>
<h1>Conclusion</h1>
<p>In this post, I was able to write R code to take screenshots of the first few slides of a slidedeck, and to combine them in a video with sounds related to the slidedeck topic. That new <code>av</code> package is quite promising!</p>
<p>Regarding <a rel="nofollow" href="https://r-resources.massey.ac.nz/rmarkdown/" target="_blank">accessibility</a> of the produced trailer, on Twitter you can’t add an alternative description to a video, so it might be nice to either replace the music with a voice over, or to tweet once with music/sound and once with voice over? I guess the tweet itself can also help counterbalance the information lost by being informative and featuring a link to the actual slidedeck. If you’re as much into listening to your own voice as I am into listening to mine (i.e. <strong>not at all</strong>!), you might want to try <a rel="nofollow" href="https://github.com/ropensci/googleLanguageR" target="_blank">rOpenSci’s <code>googleLanguageR</code> package </a> that helps use <a rel="nofollow" href="https://cloud.google.com/text-to-speech/" target="_blank">Google text to speech API</a>.</p>
<p>Finally, if you use a cool Xaringan theme like <a rel="nofollow" href="https://github.com/emitanaka/ninja-theme" target="_blank">Emi Tanaka’s ninja theme</a>, you’d a bit disappointed to create a preview that loses the nice animated transitions. Luckily, <a rel="nofollow" href="https://ropensci.org/technotes/2018/10/06/av-release/" target="_blank">in his tech note</a> Jeroen promised “In future versions we also want to add things like screen capturing and reading raw video frames and audio samples for analysis in R.” so one could depend on screen capturing rather than screen shooting. I’m looking forward to future versions of <code>av</code>, and encourage you to give it a try!</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://masalmon.eu/2018/10/07/trailer/"> Posts on Maëlle's R blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/SdDNYqsLNe4" height="1"></a></div>