FFMPEG - 我正在尝试使用 ffmpeg select 文件夹中的所有 .mp4 文件并使用文件名作为图像名称对其进行截图

FFMPEG - I'm trying to use ffmpeg to select all the .mp4 files in a folder and screenshot them with the file name as the image name

我以前从未处理过 .bat 文件,所以这对我来说是新的。

我正在尝试将 FFMPEG 用于 select 所有 .mp4 文件夹中的文件 我将 .bat文件,然后每隔30分钟截屏一次,将输入的文件名+图片编号输出为JPEG

这是我到目前为止想出的:

for f in *.mp4; do ffmpeg -i "$f" -vf fps=1/1800 "${f%.mp4}.jpeg";done &&  cp  --copy-contents *.jpeg  ~*outputDirectory* && rm -R *.jpeg

如有任何帮助,我们将不胜感激。

如果我正在解释 ?bash?正确编码应该这样做:

@Echo off
Set "JPEGdir=%UserProfile%\Outputdirectory"
for %%f in (*.mp4) do ffmpeg -i "%%f" -vf fps=1/1800 "%JPEGdir%\%%~nf_%%d.jpeg"
  • for变量需要在批处理中加上%%前缀(cmd行单个%
  • 与其在源文件夹中创建 JPEG、复制和删除,不如直接在目标文件夹中创建它们更容易,方法是使用目标路径并仅使用 filename without drive, path and extension %%~n 作为新名称,附加 ffmpeg追加数字的函数 %d(这个百分号必须用第二个转义)

编辑 添加文件夹创建:

@Echo off
Set "JPEGdir=%UserProfile%\Ouputdirectory"
for %%f in (*.mp4) do (
  If not Exist "%JPEGdir%\%%~nf" MkDir "%JPEGdir%\%%~nf"
  ffmpeg -i "%%f" -vf fps=1/1800 "%JPEGdir%\%%~nf\%%~nf_%%d.jpeg"
)

我从你的 bash 代码中导出了目标文件夹,如果你想要当前目录中的新文件夹,只需 set "JPEGdir=."

这就是我最终得到的结果,现在可以完美运行了:

@Echo off

for %%i in (*.mp4) do (
    ffmpeg -i "%%i" -vf fps=1/1800 "%%~ni_%%d.jpeg"
)