Batch Encode AVI to MP4 w/ Hazel and/or Automator?

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Batch Encode AVI to MP4 w/ Hazel and/or Automator? Sun Sep 21, 2014 12:44 am • by 5x5
Hi. First, thanks in advance for your help. Second, I'm pretty dense when it comes to this stuff, so fair warning. You may need to spell out the steps a bit.

Here's the situation. I have a crapload of TV episodes that are AVI files (like a TB or two). I tend to view these episodes in Quicktime (10) and 1) AVI's have to be converted every time which is really annoying and 2) MP4's are smaller in filesize. I was hoping to easily convert all these AVIs to MP4s using Hazel and/or Automator.

I want it to retain the file name exactly and replace the AVI files (which can get moved to the trash) in the source folders. I have a host of converters to work with including Handbrake, ffmpegX, MPEG Streamclip, iSkysoft Video Converter, MacX Video Converter Pro, Adobe Media Encoder CS6, the built-in one from Mac's services, VLC and even Quicktime itself. I'd like to retain the resolution and settings as much as possible so I don't have to adjust everything every time. A one size fits all kinda deal.

I'd like to be able to run it overnight and let it do it's thing for however many nights that takes. This has got to be possible. My Google-fu only found so much and none of it was a workable solution.

Thanks again!
5x5
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

Search the forums for those programs you listed as I believe others have used them to do this type of thing. I'm not so familiar of the specifics of those programs so you'll find more info in those posts.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for replying. I did try to do some research before I posted, but didn't find much that applied. I just tried searching the forums for those various software titles and most of them only brought up my post; the handbrake one had some others, but nothing I could use.
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

Maybe check the forums for the sites for those programs? Once you get a standalone script that can do the conversion then you can look into integrating that with Hazel.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I don't have nearly that amount of data to convert, but you might want to look into https://github.com/mdhiggins/sickbeard_mp4_automator for guidance. It's a set of Python 2 scripts intended to be used in concert with Sickbeard, Headphones, and CouchPotato for converting downloaded videos from (for example) MKV to MP4. There is a manual script in that package that you might be able to finesse into running via Hazel.

I've used the manual script to batch convert many videos. The command line can be told to look in a target directory and convert everything there automatically. The config file can be set up in order to convert to a specific format (MP4, in my case), download and include subtitles in selected language(s), as well as pulling info from either IMDB or TVDB and tagging the output file. You can also configure it to copy and/or move the output file to a selected location (like, say the Autoimport to iTunes folder) when the conversion is complete.
gvantass
 
Posts: 15
Joined: Tue Aug 12, 2014 1:02 am

Thanks, gvantass. I'll take a look, but it'll probably go over my head.

I actually ended up finding someone on fiverr to help me write a script to use to automate it. It's working within Hazel and kiiiinda works. Not to where I want or need it to be, but close. But I'm not too well versed in this stuff to know what to do to fix it. And I really only use Hazel for basic folder-triggered actions.

At least I have something to work with now, though.
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

So I went on Fiverr to get a script that would help the process. I'm getting there, but it's still not quite doing what I want it to. Maybe someone here with the know-how can help me refine it.

To reiterate, the plan was to drag a folder (or a main folder with subfolders) into the "Start" folder on the desktop, it would run the script and convert to the preset in the script. Ideally, it would then dump the AVI files in the trash (or at least another, separate folder), leaving the converted-- at the proper file size-- MP4 files, in the folders they were moved in.

What's happening is videos really only convert when I put files in without any folders. And even then, it converts to the wrong preset, as the file sizes, which should be between 60-100mb smaller (each), are coming in at the same size or slightly larger. The purpose of choosing the MP4.2 preset I created was to reduce file size and maintain quality. This process works properly when I add them manually and create a queue in the Handbrake software, but not when I want to automate it. But, as I mentioned, I have TONS of these files to do, so manually isn't really a road I want to take.

I'm including links to screenshots (stored on DropBox) of the Hazel rules so you can see what I'm working with.

Thanks!

https://www.dropbox.com/s/fdxdswuj66mp2bs/01%20folder%20recursion.jpg?dl=0

https://www.dropbox.com/s/a517jtkm01huoqq/02%20convert%20a.jpg?dl=0

https://www.dropbox.com/s/fheswbmguiqv1fe/02%20convert%20b.jpg?dl=0
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

5x5 wrote:Hi. First, thanks in advance for your help. Second, I'm pretty dense when it comes to this stuff, so fair warning. You may need to spell out the steps a bit.

Here's the situation. I have a crapload of TV episodes that are AVI files (like a TB or two). I tend to view these episodes in Quicktime (10) and 1) AVI's have to be converted every time which is really annoying and 2) MP4's are smaller in filesize. I was hoping to easily convert all these AVIs to MP4s using Hazel and/or Automator.

I want it to retain the file name exactly and replace the AVI files (which can get moved to the trash) in the source folders. I have a host of converters to work with including Handbrake, ffmpegX, MPEG Streamclip, iSkysoft Video Converter, MacX Video Converter Pro, Adobe Media Encoder CS6, the built-in one from Mac's services, VLC and even Quicktime itself. I'd like to retain the resolution and settings as much as possible so I don't have to adjust everything every time. A one size fits all kinda deal.

I'd like to be able to run it overnight and let it do it's thing for however many nights that takes. This has got to be possible. My Google-fu only found so much and none of it was a workable solution.

Thanks again!
5x5


Why not just use handbrakeCLI to convert AVIs to MP4s? You can set it to auto run on files added to a folder. It just pulls up the command line version and runs. I have found quality is the same even though its re-encoded.
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

Why not just use handbrakeCLI to convert AVIs to MP4s? You can set it to auto run on files added to a folder. It just pulls up the command line version and runs. I have found quality is the same even though its re-encoded.


That's basically what I'm trying to do, but using Hazel to help facilitate the folder actions. Mostly, I don't really know what I'm doing. I do know when I've tried to run the folder actions that include the script to do so, it's encoding them to the wrong file size. Still MP4s, but in most cases either the same file size as the source file or sometimes larger, which is defeating part of my purpose.

How would I do the thing you're talking about? And do dumb it down a shade or two.

Thanks!
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

Set up a Hazel rule as follows:

* Assumes you download/drop a new AVI into a folder called Folder A

Run Rule on Folder A

If all following rules met
Date added is after date last matched
Extension is AVI

Do the following:

Run Applescript - embedded script
(And put the following code)

Code: Select all
   tell application "Finder"
      try
         --Set to red label to indicate processing
         set label index of theFile to 2
         
         --Assemble original and new file paths
         set origFilepath to quoted form of POSIX path of (theFile as alias)
         set newFilepath to (characters 1 thru -5 of origFilepath as string) & "m4v'"
         
         --Start the conversion
         set shellCommand to "nice /Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " --preset=\"AppleTV 3\" ;"
         do shell script shellCommand
         
         --Set the label to orange
         set label index of theFile to 3
      end try
   end tell
   tell application "Finder"
      set movieName to name of item theFile
   end tell


It will convert in background and change colors when done. I am using the AppleTV 3 preset for handbrake but feel free to change it to which you want in the code.
dhy8386
 
Posts: 94
Joined: Tue Nov 09, 2010 12:19 pm

Sorry for the delay. I do appreciate you providing script code. I've got it compiled and saved, but before I start/test it, what's to stop it from looping, since the source AVI files will remain in the input folder (won't it?)? So it converts the file, then keeps doing so until I somehow manually stop it. I ask because it happened with the Hazel script, too.

I'm a code layman, but I didn't notice anything about moving converted files out or moving source AVI files to the trash or something. Is there a way to add that?

Thanks!
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

5x5 wrote:Sorry for the delay. I do appreciate you providing script code. I've got it compiled and saved, but before I start/test it, what's to stop it from looping, since the source AVI files will remain in the input folder (won't it?)? So it converts the file, then keeps doing so until I somehow manually stop it. I ask because it happened with the Hazel script, too.


I would change the date condition, or add a condition that says "if color label is X".

Since the applescript labels it red when it's processing, and yellow when it's done, the original won't be reprocessed after that unless you manually change the color back to none (X). It's either that, or use something like openmeta to tag the original when you start processing it, and after you're done.

I added another rule to remove the original after processing as well.
staze
 
Posts: 16
Joined: Sat Feb 28, 2015 5:52 pm

This is just terrific and exactly what I was looking for.

Trying the Rule as written with an .mov file but the script does not appear to run. What might I be doing wrong?

I am new to Hazel and was hoping someone could guide me in adding a final step in this process. Can Hazel look for the converted file and move it to a folder called "Converted" within this same rule? Or does it require a second rule?
Last edited by MacWorks on Wed Apr 15, 2015 5:45 pm, edited 1 time in total.
MacWorks
 
Posts: 6
Joined: Thu Sep 18, 2014 1:52 pm

MacWorks wrote:This is just terrific and exactly what I was looking for.

I am new to Hazel and was hoping someone could guide me in adding a final step in this process. Can Hazel look for the converted file and move it to a folder called "Converted" within this same rule? Or does it require a second rule?

Thanks


No clue. I still haven't been able to get it to work properly. Full disclosure, I haven't tried much because I don't know what I'm doing. But if you get a solidly working version put together, would you mind sharing it?
5x5
 
Posts: 11
Joined: Fri Jul 13, 2012 10:03 pm

Have you gotten the script to run at all? I can't seem to get HandBrakeCLI to kick in when a file is moved into the folder.
MacWorks
 
Posts: 6
Joined: Thu Sep 18, 2014 1:52 pm

Next

Return to Open Discussion