1

I am trying to automate the process of video conversion using handbrake and automator.

Here is the script that i am using in Run Shell Script action of Automator Folder Action:

for f in "$@"
do
    Applications/HandBrakeCLI -i "$f" -t 1 \ 
    --angle 1 -c 1 -o "/Users/abc/Desktop/TestVidDest/$(basename $f)" \
    -f mp4  -4  -O  --decomb="fast" -w 1280 -l 720 --modulus 16 \
    -e x264 -b 3800 -2  -T  --cfr -a 1 -E faac -6 dpl2 -R 48 -B 128 \
    -D 0 --gain 0 --audio-fallback ffac3 --x264-preset=slow  \
    --x264-profile=high  --x264-tune="film"  --h264-level="4.0" \
    --verbose=1  &
done

The problem is when I manually run this script from Automator it works fine but when new files are added in the folder then this script is called but videos are not converted. If I remove '&' from the end of the command then it works with new files but not in hidden mode and I want it to run in hidden mode.

So if anybody can guide me about what i am doing wrong here???

Log from the console:

Console Log

4
  • possible duplicate of Using automator and handbrake cli to convert videos automatically Commented Jan 27, 2014 at 12:20
  • @GrahamMiln yes that question was too asked by me and i do not know why but untill now your answer there was not visible to me. So now i have read your answer there. But the problem is when i put "&" at the end of the command it does work if i press run button on automator but it does not work when a file is added to folder (although the script is called, i checked it by showing an alert box before calling handbrake). So any suggestions why this is happening so??? Commented Jan 27, 2014 at 12:31
  • The console log is unreadable in that picture. Could you copy and paste the actual text please. Commented Jan 27, 2014 at 12:42
  • I am sorry! I tried first to copy the text but I was not able to do so that is why I added the screenshot. But you can view large image by view image in the right click. Commented Jan 27, 2014 at 13:09

1 Answer 1

1

First, I'm assuming that you accidentally chopped the '/' character off the front of the path to Handbrake in your example. Second, when you say "hidden mode" you mean run in the background.

What happens if you run the command from the command line?

How do you know the command isn't running when you run it in background mode? Are you doing a "ps" command from the command line to see if it is running or not?

Have you tried adding ">>~/HB_log.txt 2>&1" just before the "&" command so that you get a log of both the output and the errors it might be putting out?

If only the first part of the name is being used then I assume that the quote characters around the name are being stripped - try escaping them with a '\'. Like so '\"/Users/abc/Desktop/TestVidDest/$(basename $f)\" ' and see what happens.

I also suspect that problems with the name might be upsetting the entire line and causing your problem.

I would actually write a shell script that you could test externally and then call your shell script from Automator.

4
  • Thanks a lot! after adding ">>~/HB_log.txt 2>&1" it is working perfectly. But can you please explain why handbrake is not running in the background without adding this. Because as far as i know this just adds a log file??? Commented Jan 27, 2014 at 13:04
  • And one other issue, the name of the output is not being set right. If name of the file has two words that is "abc def.mp4" then output file is stored as "abc.mp4". Can you please help with this issue? Commented Jan 27, 2014 at 13:47
  • What does the log say when you run it? Commented Jan 27, 2014 at 14:03
  • If only the first part of the name is being used then I assume that the quote characters around the name are being stripped - try escaping them with a '\'. Like so '\"/Users/abc/Desktop/TestVidDest/$(basename $f)\" ' and see what happens. Commented Jan 27, 2014 at 14:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .