1

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?

3
  • In addition to vadian's answer, also make sure the Run Shell Script action is set to: Pass input: as arguments Commented Jul 15, 2019 at 16:32
  • ok, it is already adjusted like that. Thanks. Commented Jul 15, 2019 at 16:34
  • 1
    What was the purpose of involving AppleScript at all in the workflow. It seems like a masochistic way to add a layer of complication to something just for the challenge. I would recommend getting the required user input from the Ask For Text Automator action, then passing that and the two Finder files directly to the shell script action. Commented Jul 16, 2019 at 6:21

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

5 Comments

Shouldn't it be return {fileInputPosix, fileOutputPosix, seconds}?
Duuuuhhhh! Obviously. Thanks. But now I am getting a different error when the shell script runs. [NULL @ 0x7ff6f1005000] Unable to find a suitable output format for '1000[0]' 1000[0]: Invalid argument”. How do I get the array elements on bash now?
thanks. I think we are almost there. Now I have a gigantic error message that is probably ffmpeg trying to run with the parameters provides. At the end, FFMPEG fails with the message `At least one output file must be specified”...
I'm not familiar with ffmpeg. And it's another question.
My whole question is about running a FFMPEG using automator + applescript + shell script...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.