AUTOMATOR - Trying to issue a command inside a shell script with parameters received from AppleScript

笑着哭i 提交于 2019-12-14 03:07:23

问题


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

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

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

When the applescript ends, I have 3 variables:

  1. inputVideo, containing the POSIX input video path
  2. outputVideo, containing the POSIX output video path
  3. seconds, containing the time in seconds.

The applescript ends with these lines

    return fileInputPosix & fileOutputPosix & seconds
end run

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

The last line extracts a frame using FFMPEG.

I am having this error

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

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

any ideas?


回答1:


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)}

To pass the variables to the shell script just write

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

or if you need the variables

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

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


来源:https://stackoverflow.com/questions/57043436/automator-trying-to-issue-a-command-inside-a-shell-script-with-parameters-rece

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!