You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用grabVideoStills和ffmpeg提取视频帧时遇错误求助

视频逐帧提取工具运行故障求助

一、grabVideoStills(R语言工具)运行错误

执行的命令:

grabVideoStills(
  01_H35_combined_small.mp4,
  imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli",
  overWriteDir = FALSE,
  sampleWindow = 1
)

报错信息:

imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli",
Error: unexpected ',' in "imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli","
>   overWriteDir = FALSE,
Error: unexpected ',' in "  overWriteDir = FALSE,"
>   sampleWindow = 1
> )
Error: unexpected ')' in ")"

问题原因与解决:

  • 第一个参数(视频文件名)未用引号包裹,R会将01_H35_combined_small.mp4识别为变量而非字符串,导致语法解析错误。
  • 修改后的正确命令:
grabVideoStills(
  "01_H35_combined_small.mp4",
  imageDir = "C:/Users/pb/OneDrive/PD/MAG/split_stimuli",
  overWriteDir = FALSE,
  sampleWindow = 1
)

二、ffmpeg命令运行错误

执行的命令(直接在R控制台输入):

ffmpeg -i 01_H35_combined_small.mp4 %04d.png

报错信息:

Error: unexpected numeric constant in "ffmpeg - i 01"

添加引号后仍报错:

Error: unexpected string constant in "ffmpeg - i "01_H35_combined_small.mp4""

问题原因与解决:

  • ffmpeg是命令行工具,不能直接在R控制台中输入执行,R会将其识别为无效的R代码。
  • 需通过R的system()或system2()函数调用ffmpeg命令,正确写法示例:
# 使用system()
system('ffmpeg -i "01_H35_combined_small.mp4" "%04d.png"')

# 或使用system2()(参数拆分更清晰,推荐)
system2("ffmpeg", args = c("-i", "01_H35_combined_small.mp4", "%04d.png"))
  • 注意:确保ffmpeg已添加到系统环境变量中,否则需指定ffmpeg的完整路径(如"C:/Program Files/ffmpeg/bin/ffmpeg.exe")。

内容的提问来源于stack exchange,提问作者PBAB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 17:08:11