I've built an After Effects render farm which uses the adobe terminal command 'aerender'. I have it running on two Mac Pros, with a total of 24 aerender instances.

It works pretty well but occasionally a render instance will fail (because reasons) and I'll need to hit up on the keyboard to rerun the command. I basically have to babysit each render, which is obviously not ideal. I'd rather have it automatically restart if an error is detected while I go about my day.

I've tried using a double pipe || to start another render if the current one fails, but this doesn't work because when aerender fails it still exits to Terminal in a clean way. The double pipe only works when I Control-C the current render.

My render command is…

/Applications/Adobe\ After\ Effects\ 2020/aerender -project "/Volumes/Videos/Test.aep" -sound ON

If the render fails, it will say something like…

WARNING:After Effects warning: logged 2 errors, please check log.

I assume I need to use grep to search the output for "WARNING:After Effects warning"

I also assume I need to wrap my initial command in another command to monitor for this string.

I'm kinda lost. Any help would be appreciated.

  • while /App... | grep 'WARNING...' ; do echo "repeating command" ; done
    – icarus
    Feb 8 '20 at 21:21
  • If the aerender program has proper exit codes, you could use an until loop: until ..aerender... ; do : ; done. The loop will run unti the aerender command exits successfully.
    – Haxiel
    Feb 9 '20 at 3:42
  • @icarus this almost works. I do get the command to repeat using your suggestion, however i see NO output from aerender at all. I only see the line that grep detects followed by "repeating command". I need to see the regular output of aerender too. Is this achievable? Feb 9 '20 at 4:10
  • @Haxiel i'm not sure. Even when there's a render error, it still seems to exit gracefully. There's no sudden crash. Feb 9 '20 at 4:13
  • 1
    @Haxiel Ok thanks for the explanation. I tried it and it didn't work, unfortunately. It just returned to the command prompt and stayed there. This was for the main kind of error I get, which says that a file can't be written. However, it did work when I forced a different kind of error where it couldnt find the render directory - but this basically never happens. Thanks for your help though, I learned something new that I might be able to put to use in the future! Feb 9 '20 at 5:10

The OP wants to see the output as well, so we need a small script

exec 3>&1   # Make a copy of the stdout fd on fd 3
while "/Applications/Adobe After Effects 2020/aerender" -project "/Volumes/Videos/Test.aep" -sound ON |
     tee /dev/fd/3 | 
     grep 'WARNING:After Effects warning' >/dev/null
    echo "Repeating the command"

There are a couple of things going on here, and I am making a guess about what is supported on macos. The exec makes fd 3 the same as the stdout of the script. I am hoping that macos makes this available as /dev/fd/3. tee is used to send a copy of the output of aerender to this, so the script outputs the same things as the original code.

The output of tee is then fed to grep. I deliberately don't use grep -q as this can stop processing as soon as it sees the first matching pattern, which can lead to tee getting SIGPIPE, which can lead to aerender getting SIGPIPE. If aerender doesn't create much output and only outputs the message once this make be over cautious but it doesn't hurt.

If macos doesn't support /dev/fd/3, then one could try

while O="$("/Applications/Adobe After Effects 2020/aerender" -project "/Volumes/Videos/Test.aep" -sound ON)"
    echo "$O"
    echo "$O" | grep 'WARNING:After Effects warning' >/dev/null
    echo "Repeating the command"

The downside of this is that all the stderr of aerender will be output and then all the stdout will be output, rather than being output in the expected interleaved way.

All of this is untested as I don't have a suitable system to try it on.

  • Wow thanks for this. I removed the double quotes inside of my aerender command as they were causing problems with your script, but now I get the error line 2: /Applications/Adobe\ After\ Effects\ 2020/aerender -project /Volumes/Videos/Test.aep -sound ON: No such file or directory on both version of the script, but if I run this command on its own it works. Hmm. Feb 9 '20 at 6:02
  • I made a trivial edit which shouldn't affect things but might help. Sorry I don't have a mac to actually try it on. The error message you are seeing suggests that you have quotes around the whole command, so it thinks the -project... is part of the command name.
    – icarus
    Feb 9 '20 at 6:09
  • After making that change (removing the quotes around the comment), the first command works perfectly as a single script. Hurrah! Tried it out across my farm by pasting the script text into a bunch of Terminal windows and waited for errors to appear. Sure enough, it restarted the render right after each one. I also modified grep to cover a few more render messages with grep 'warning\|error\|errors'. All I need to do now is hook this into my render farm script which shouldn't be too tricky but I'm too sleepy to attempt that now haha. Thank you! Feb 9 '20 at 9:12
  • Ok maybe not so sleepy! I added it to my farm script. It's a shell script which ssh's into my render mac, then uses osascript to run a long Apple Script command inside of the shell script. The Apple Script opens iTerm, writes your multi-line command back into shell (but with \"$1\" instead of burnt-in project name), then splits iTerm vertically (keeping everything in the same window), and repeats this again and again, etc. Due to the recursive nature of the script, I had to backslash the backslashes a BUNCH of times like `Adobe\\\\ After\\\\ Effects\\\` Crazy, but it works! I owe you one! Feb 9 '20 at 9:48
  • For anyone following this and wants to implement it for their own aerender script, you'll want to REMOVE any reference to 'warning' in the grep line. I forgot that the start of each render often warns about the color depth! Woke up this morning and found that my test scene was in a wild render loop. I replaced it with grep -i 'erro*' >/dev/null which catches both 'error' and 'errors' and uppercase versions (the -i ignores case sensitivity). Feb 9 '20 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.