AUTOMATOR-尝试在Shell脚本中发出带有从AppleScript接收到的参数的命令 [英] AUTOMATOR - Trying to issue a command inside a shell script with parameters received from AppleScript

查看:185
本文介绍了AUTOMATOR-尝试在Shell脚本中发出带有从AppleScript接收到的参数的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating this automator script for macOS that receives videos and extract a frame at a given time in seconds.

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

After receiving the videos from finder, it runs this applescript asking for the time in seconds, to extract the frame.

时间存储在Applescript变量"seconds"中.

The time is stored into the Applescript variable "seconds".

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

When the applescript ends, I have 3 variables:

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

applescript以这些行结尾

The applescript ends with these lines

    return fileInputPosix & fileOutputPosix & seconds
end run

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

and passes the variables to a shell script that starts with these lines:

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]: 不是目录"

The action "Run Shell Script" encountered an error: "ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers built with Apple LLVM version 10.0.0 (clang-1000.11.45.5) configuration: --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]: Not a directory"

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

I think I am having some concatenation error on the command line string

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

If I would type this last line on terminal I would type like this:

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

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

where aaa.mp4 is the input video and aaa.png is the frame at t=1000s.

有什么想法吗?

推荐答案

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

According to the error message the line fileInputPosix & fileOutputPosix & seconds returns one single string.

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

Maybe you want to return a list then you have to add braces and to replace the ampersand characters with commas and you have to convert the numeric value to text

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

只需将变量传递给shell脚本

To pass the variables to the shell script just write

/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

这篇关于AUTOMATOR-尝试在Shell脚本中发出带有从AppleScript接收到的参数的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆