Page 1 of 1
Convert video and rename

Posted:
Thu Aug 11, 2011 12:01 am
by ericwass
Hi,
I'm desperately trying to figure out how to do the following:
1. Have a folder where I drop videos for conversion.
2. Have Hazel wait a couple of minutes to make sure all the videos have finished copying over
3. Take a video file and convert it (usually from AVCHD) to m4v using Handbrake CLI
4. Have Hazel rename the file based on the original files name and Date Modified. So, for instance, if the original file was named 0002.MTS and modified on 9/15/10 the converted video file will be named 20100915_0002.m4v
5. Have Hazel move the new video file to a specified directory and delete the original MTS file.
I'm able to all of the steps above in bits and pieces, just not all together. For instance, one strategy I tried was having Hazel rename the original file first which made renaming the new file based on the old one a non-issue. Then I had it color label the old file so it wouldn't get converted again. But at that point I couldn't get Hazel to know which file I wanted to move to a specified directory (step 5). And what I really couldn't do was make this work with multiple files in sequence. Anyway, you get the point. I need help. Can anybody step me through this. Much appreciated.
Thanks.
Re: Convert video and rename

Posted:
Thu Aug 11, 2011 1:59 am
by justinkthornton
If you can set handbrake to save the converted video to a new folder it might be easier to manige the flow so you can have less complicated rules.
Re: Convert video and rename

Posted:
Fri Aug 12, 2011 4:02 pm
by Mr_Noodle
If the directory in #5 is a fixed directory, then I'm not sure how that wouldn't work. Maybe you need to be more specific about what you want there.
Otherwise, I don't see why the following workflow wouldn't work:
- Rename the file
- Run a shell script to run handbrake to do the conversion
- Remove the original
- Re-target the rule to act on the new file (see
here- Move the file to the new directory.
I believe that should work. If not, maybe more details on the workflow would help.
Re: Convert video and rename

Posted:
Sat Aug 13, 2011 12:53 am
by ericwass
Thanks guys. Mr. Noodle, the directory in #5 is fixed. But for some reason the workflow you suggested goes along nicely until I try to re-target Hazel at which point I get an unspecified error. I know very little about scripting but it seems to me the shell script you pointed to redirects Hazel to a parent directory. But is that what I want to do? The converted file that needs to be moved to the directory in step #5 resides in the same directory as the original file that just got deleted. How do I tell Hazel to stay in the same directory but just target the new file?
------
edit: I realize it was an applescript, not a shell script. I fixed that but it still didn't work. No errors, but the m4v that's created does not get moved, nor does the rule get applied again to files added subsequent to the first file.
Re: Convert video and rename

Posted:
Mon Aug 15, 2011 3:32 pm
by Mr_Noodle
Ah, you're not supposed to use that retarget script as-is. That's just an example of the functionality. You'd need to change it to switch from the original file to the converted version as Hazel can't know that otherwise. Google around for AppleScript to figure out how to tweak it if you aren't already familiar with AS.
Re: Convert video and rename

Posted:
Mon Aug 15, 2011 4:30 pm
by ericwass
Thanks. I'm only ok with Applescript. And I'm great with Google hunting. That being said, if you can, off the top of your head, give me a hint of the relevant commands, I'd be much obliged.
Re: Convert video and rename

Posted:
Mon Aug 15, 2011 8:22 pm
by ericwass
I've Googled the hell out of this and know there is an easy answer. I just can't find it. So, what I've done is taken justinkthornton's advice and had Handbrake CLI simply create the new file in the new directory instead of using Hazel to move it there after Handbrake is done with it. To do this I actually use Hazel to rename the original file first (based on Date Modified), Handbrake CLI then uses this modified filename when it makes the transcoded version. This solves my main problem. But it opens up others. Now that the files are disassociated from each other I can't do anything else with the file once it's done transcoding.
Ideally, I'd like to have Hazel sort the new .m4v files into subdirectories based on capture date of the original file. But since Hazel can't parse the date structure in the filename (20100915_0002.m4v for example), I was thinking I might be able to add Spotlight comments or something to the .m4v file that gave Hazel direction for organizing it by date. I don't know if I could've made that work in actuality, but I know that I'm totally stuck with my current configuration; the only info I can carry over through the transcode is the filename.
Anyway, I'm doing my damnedest to figure this out by myself. But I do have a career and a wife and a 2-year-old and there're only so many hours in the day. Any help would be much appreciated.
Re: Convert video and rename

Posted:
Wed Aug 17, 2011 2:13 pm
by Mr_Noodle
This is going beyond the support I can usually give but here's an untested script. It takes the file and tells Hazel to retarget to a file with the same name but with a .m4v extension instead.
- Code: Select all
set AppleScript's text item delimiters to ":"
set theParentDir to (text items 1 through -2 of (theFile as string)) as string
set theFileName to (text item -1 of (theFile as string)) as string
set AppleScript's text item delimiters to "."
set theExtension to the last text item of theFileName
set theBasename to (text items 1 through -2 of theFileName) as string
set theNewFile to theParentDir & theBasename & ".m4v"
set AppleScript's text item delimiters to ""
return {hazelSwitchFile:theNewFile}
You'll have to take it from here to do any fixes/tweaking to get it to work in your situation.