我在没有管理员权限的情况下使用 Windows,因此无法在 Windows PATH 变量中设置路径。
该ffmpeg.exe
文件在我的"U:/ProgramFiles/ImageMagick-6.8.5-5/"
文件夹中。
我找到了如何使用包的saveVideo()
功能animate
:
ani.options(ffmpeg = shQuote('U:/ProgramFiles/ImageMagick-6.8.5-5/ffmpeg.exe'))
saveVideo({
par(mar = rep(3, 4))
for (i in seq(pi/2, -4/3 * pi, length = 12)) {
plot(0, 0, pch = 20, ann = FALSE, axes = FALSE)
arrows(0, 0, cos(i), sin(i))
axis(1, 0, "VI"); axis(2, 0, "IX")
axis(3, 0, "XII"); axis(4, 0, "III"); box()
}
},
video.name="mavideo.mp4",
outdir="U:/Data/Rtests/Animation")
但是我还没有找到如何使用块中的选项来编织 Rmd 文件fig.show=animate
,例如:
```{r clock, fig.width=7, fig.height=6, fig.show='animate'}
par(mar = rep(3, 4))
for (i in seq(pi/2, -4/3 * pi, length = 12)) {
plot(0, 0, pch = 20, ann = FALSE, axes = FALSE)
arrows(0, 0, cos(i), sin(i))
axis(1, 0, "VI"); axis(2, 0, "IX")
axis(3, 0, "XII"); axis(4, 0, "III"); box()
}
```
我试图hook_ffmpeg_html()
通过仅更改ffmpeg.cmd
变量来修改函数:
```{r}
hook_ffmpeg_html2 <- function (x, options)
{
........
ffmpeg.cmd = paste("-y", "-r", 1/options$interval,
"-i", fig.fname, mov.fname)
ffmpeg.cmd <- paste('"U:/ProgramFiles/ImageMagick-6.8.5-5/ffmpeg"', ffmpeg.cmd)
......
}
opts_knit$set(animation.fun = hook_ffmpeg_html2)
```
但是这个块不起作用,下面是错误消息:
label: unnamed-chunk-1
Warning in block_exec(params) :
failed to tidy R code in chunk <unnamed-chunk-1>
reason: Error in base::parse(text = text, srcfile = NULL) :
21:14: unexpected symbol
20: options$out.height), if ("controls" %in% mov.opts)
21: "controls=\\"controls