Using automator and handbrake cli to convert videos automatically

applescriptautomator

I am trying to automate video conversion process using Automator and Handbrake CLI version. I am trying to implement the functionality that whenever a video is downloaded in my dropbox folder on my PC it is converted and put in another folder. Currently i am testing it with a test folder (not on dropbox so i am just copying files to it to test). When a put a single file or multiple files in the folder simultaneously it works. But when i put one file (or many) and script is executing i.e. converting the videos and i put another file in the folder then for that new file script is never called so the new video is not converted.

So how can i achieve this functionality that when script is running and new file is added another instance of script is started for new file.

And also the new file is saving with only the first word in the name if name has many words (i.e. breaking on space)

Here is the screenshot of my automator configuration:

Automator Image

Thanks in advance for your help.

Here is my script from run shell script as you asked @:Tony Williams

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

Best Answer

Process in the background

Ideally, your script needs to complete as quickly as possible. The easiest way is to spin off the processing of the movies into background processes. You can do this by adding a space and an ampersand & to the end of your HandBrakeCLI line.

Move before processing

However, this does not solve the problem of new files being ignored. In fact, your files could now be processed twice if the processing is not finished before the next new file appears.

Your script should move each new file to another unmonitored folder before processing begins. Consider adding a mv command before your HandBrakeCLI line. Alternatively, you could have Automator perform the move.

The destination folder should ideally be on the same drive, so it completes quickly and does not delay the script.