AUTOMATOR-尝试在Shell脚本中发出带有从AppleScript接收到的参数的命令

时间:2019-07-15 16:01:09

标签: bash applescript automator

我正在为macOS创建此自动化脚本,该脚本可以在几秒钟内在给定时间接收视频并提取帧。

从finder接收视频后,它将运行此applescript,询问以秒为单位的时间,以提取帧。

时间存储在Applescript变量“ seconds”中。

当applescript结束时,我有3个变量:

  1. inputVideo,包含POSIX输入视频路径
  2. outputVideo,包含POSIX输出视频路径
  3. 秒,包含以秒为单位的时间。

applescript以这些行结尾

    return fileInputPosix & fileOutputPosix & seconds
end run

并将变量传递到以以下几行开头的shell脚本:

fileInput=${@[0]}
fileOutput=${@[1]}
seconds=${@[2]}

/usr/local/bin/ffmpeg -i $fileInput -vf "select=eq(n\,$seconds)" -vframes 1 $fileOutput

最后一行使用FFMPEG提取一帧。

我遇到此错误

  

“运行Shell脚本”操作遇到错误:“ ffmpeg版本   4.1使用Apple LLVM版本10.0.0(clang-1000.11.45.5)构建的FFmpeg开发人员(c)2000-2018版权所有(c):   --prefix = / usr / local / Cellar / ffmpeg / 4.1_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc = clang --host -cflags = --host-ldflags = --enable-ffplay --enable-gpl --enable-libmp3lame --enable-libopus --enable-libsnappy --enable-libtheora --enable-libvorbis --enable-libvpx- -enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-opencl --enable-videotoolbox libavutil 56.22.100 / 56.22.100 libavcodec 58.35.100 / 58.35.100 libavformat 58.20.100 / 58. 20.100 libavdevice 58. 5.100 /   58. 5.100 libavfilter 7. 40.101 / 7. 40.101 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 3.100 / 5. 3.100 libswresample 3. 3.100 / 3. 3.100 libpostproc 55. 3.100 /   55. 3.100 /Users/fireball/Desktop/HD/aaa.mp4/Users/fireball/Desktop/HD/aaa.png1000[0]:   不是目录”

我认为我在命令行字符串上有一些串联错误

如果我要在终端上键入最后一行,我会这样输入:

ffmpeg -i aaa.mp4 -vf "select=eq(n\,1000)" -vframes 1 aaa.png

其中aaa.mp4是输入视频,aaa.png是t = 1000s时的帧。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

根据错误消息,行fileInputPosix & fileOutputPosix & seconds返回一个单个字符串。

也许您想返回一个列表,那么您必须添加大括号并用逗号替换&字符,并且必须将数值转换为文本

return {fileInputPosix, fileOutputPosix, (seconds as text)}

只需将变量传递给shell脚本

/usr/local/bin/ffmpeg -I $1 -vf "select=eq(n\,$3)" -vframes 1 $2

或者如果您需要变量

fileInput=$1
fileOutput=$2
seconds=$3

/usr/local/bin/ffmpeg -i $fileInput -vf "select=eq(n\,$seconds)" -vframes 1 $fileOutput