0

I have a folder ~/Downloads

I'm checking (using entr) it for .webm videos and when new file is added I need it to be converted to .mp4 BUT can't figure out the arguments passed...

ls . | entr handbrakecli --encoder x264 --width 700 --format av_mp4 --optimize --non-anamorphic --rate 30 -i <new_webm> -o <same_name_append_mp4>
3

2 Answers 2

2

entr is a "utility for running arbitrary commands when files change", it doesn't specifically monitor for new files (it can pass one new file to the command, but I couldn't get this to work reliably). You can work around this (as you did) by having entr monitor the directory itself, but you still need to take care of identifying which files actually are new and avoid re-processing.

cd ~/Downloads
mkdir -p videos
while :; do
  ls . | entr -dz find . -depth 1 -type f -iname "*.webm" -exec sh -c '
      f="$1"
      mv -- "$f" videos/
      handbrakecli --encoder x264 --width 700 --format av_mp4 --optimize --non-anamorphic --rate 30 -i "videos/$f" -o "videos/${f%.webm}.mp4" 
      # rm "videos/$f"
      ' _ {} \;
done

This uses find to identify new WebM files, moves them to a different directory (to avoid reprocessing) and runs Handbrake on them. Uncomment the last line to automatically remove WebM files after processing. To terminate, press Ctrl-Z and then run kill -9 %1.

PS: As @gilby already mentioned in the comments: Get Hazel, works like a charm.
PPS: Also, the answers on Monitor a folder for changes, and run a command when a change is detected provide some additional ways to trigger shell scripts after the content of a directory changes.

2
  • Why buy Hazel if all can be done with one command in terminal (just can't get it to work 100% automatically) Commented Jan 5 at 9:57
  • @PavelPervoy Maybe exactly because of that? You can also use Automator to define Folder Actions.
    – nohillside
    Commented Jan 5 at 10:02
0

Changed entr to fswatch:

fswatch . | find . -type f -name "*.webm" -exec handbrakecli --encoder x264 --width 700 --format av_mp4 --optimize --non-anamorphic --rate 30 -i "{}" -o "{}.mp4" \;

Problem is - script exits after video conversion. Need to restart it each time.

Still no stable solution ;(

1
  • while :; do YOUR CODE HERE; done :-) But you still will reprocess all webm files each time.
    – nohillside
    Commented Jan 5 at 9:07

You must log in to answer this question.

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