0

I am trying to setup a Shell Script to work within an automator watch folder...

Everything works with the exception of the Run Shell Scrip portion...

Essentially when a file shows up in the watch folder, it runs the shell scrip which calls FFMPEG and then will move the file to an archive folder for safe keeping. However right now automator is telling me everything worked but now file is being created.

I have the Shell set to /bin/sh and Pass input set to as arguments

Here is my script:

for f in "$@"
do
name=$(basename "$f")
dir=$(dirname "$f")
ffmpeg -i "$f" -b 250k -strict experimental -deinterlace -vcodec h264 -acodec aac "$dir/mp4/${name%.*}.mp4"
echo "$dir/mp4/${name%.*}.mp4"
done

it does echo the correct filename, but does not actually run ffmpeg

I have tried adding -exec before it like I have seen in some scripts but still nothing...

Zombo
  • 1
  • 62
  • 391
  • 407
Chris James Champeau
  • 984
  • 2
  • 16
  • 37
  • Does the script output anything to stderr? – that other guy Feb 14 '13 at 02:11
  • Not sure exactly how to use stderr but when I add it to the end of the code, after the echo...It tells me that line 4: ffmpeg command not found – Chris James Champeau Feb 14 '13 at 02:16
  • It runs great in my terminal just can't figure out why it wont work within this shell script – Chris James Champeau Feb 14 '13 at 02:19
  • Off-topic for your question, but your ffmpeg command can be improved. ffmpeg command-line usage questions are better suited at [Super User](http://superuser.com/) (since SO is programming specific). I recommend asking a "how to I improve this command for web playback" question at SU. – llogan Feb 14 '13 at 02:34
  • Thanks for the info...I never thought to ask there... Also got it working after using the stderr which led me to needing the absolute path to ffmpeg – Chris James Champeau Feb 14 '13 at 02:41

2 Answers2

5

FFmpeg searches STDIN while it is running. This is to allow the user to hit q to stop encoding, among other tasks. This could cause a problem with a script. Perhaps to workaround try this:

# notice --+
#          |
#          v
ffmpeg -nostdin -i "$f" -b 250k -strict experimental -deinterlace \
  -vcodec h264 -acodec aac "$dir/mp4/${name%.*}.mp4"

mysterious error with ffmpeg on OSX

Community
  • 1
  • 1
Zombo
  • 1
  • 62
  • 391
  • 407
  • Pretty sure its the most recent version...ffmpeg version 1.1.2 Copyright (c) 2000-2013 the FFmpeg developers built on Feb 6 2013 10:44:49 with gcc 4.2.1 (GCC) (Apple Inc. build 5666) (dot 3) – Chris James Champeau Feb 14 '13 at 01:57
1

Not sure if it is because I am running on a Mac OS X Server but I imagine it is, I had to include the absolute path to ffmpeg...which fixed it

for f in "$@"
do
name=$(basename "$f")
dir=$(dirname "$f")
/opt/local/bin/ffmpeg -i "$f" -b 250k -strict experimental -deinterlace -vcodec h264 -acodec aac "$dir/mp4/${name%.*}.mp4"
echo "$dir/mp4/${name%.*}.mp4"
done
Chris James Champeau
  • 984
  • 2
  • 16
  • 37