knitr with gganimate,找不到ffmpeg命令

时间:2016-12-20 05:37:57

标签: r ggplot2 knitr gganimate

我正在尝试根据knitr documentation的说明gganimate制作动画情节:

knitr::opts_chunk$set(message = FALSE, warning = FALSE, fig.show = "animate")
# Example from https://github.com/dgrtwo/gganimate
library(ggplot2)
library(gganimate)

# For example, suppose we wanted to create an animation similar to the Gapminder 
# world animation, using Jenny Bryan's gapminder package for the data.
library(gapminder)

theme_set(theme_bw())
p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  scale_x_log10()

# Notice we added frame = year and saved the plot as p. 
# We then display it as an animation with the gg_animate function:
gg_animate(p)

但是,我收到错误:

  

错误:找不到ffmpeg命令。您应该更改animation.fun挂钩选项或安装启用了libvpx的ffmpeg。

我已按照说明here安装ffmpeg,并在命令行中运行ffmpeg -version

C:\ffmpeg\bin>ffmpeg -version
ffmpeg version 3.2.2 Copyright (c) 2000-201
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-versio
nable-nvenc --enable-avisynth --enable-bzli
 --enable-gnutls --enable-iconv --enable-li
s2b --enable-libcaca --enable-libfreetype -
le-libilbc --enable-libmodplug --enable-lib
enable-libopencore-amrwb --enable-libopenh2
pus --enable-librtmp --enable-libsnappy --e
ble-libtheora --enable-libtwolame --enable-
enable-libvorbis --enable-libvpx --enable-l
ibx264 --enable-libx265 --enable-libxavs --
ble-lzma --enable-decklink --enable-zlib
libavutil      55. 34.100 / 55. 34.100
libavcodec     57. 64.101 / 57. 64.101
libavformat    57. 56.100 / 57. 56.100
libavdevice    57.  1.100 / 57.  1.100
libavfilter     6. 65.100 /  6. 65.100
libswscale      4.  2.100 /  4.  2.100
libswresample   2.  3.100 /  2.  3.100
libpostproc    54.  1.100 / 54.  1.100

我现在该怎么办?特别是,“更改animation.fun挂钩选项”意味着什么?

编辑:我刚刚注意到system('ffmpeg -version')返回127状​​态代码,但在命令行中运行正常。

1 个答案:

答案 0 :(得分:1)

重新启动Rstudio并且可能是基础Rsession解决了问题。