我正在尝试用R中的几个png文件创建一个简短的动画 . 我尝试了包 magick
但它只有在我将它们保存到.gif时才有效 . 当我尝试保存为.mp4时,它将生成一个.mp4文件,但是一旦打开它,将只显示第一个图像 .
我的代码是
library(magick)
productPath <- ('/Users/abc/Desktop/products/')
list <- list.files(productPath, '*.png')
imagesPath <- paste0(productPath, list)
images <- image_read(imagesPath)
animation <- image_animate(images, fps = 20, loop = 1)
image_write(animation, paste0(productPath, 'test.mp4'))
我发现还有一个名为 animation
的包,但我真的不知道如何用该包导入png文件 . 有解决方案?任何一个包都应该没问题 . 谢谢!
1 回答
你可以这样做(假设图像在当前目录中):
默认情况下,这会创建
animation.mp4
.