“DropFolders”: AIR 2.0 NativeProcess w/ HandBrake

DropFolders is an upcoming AIR 2.0 Windows-only (for now) application which allows a user to set up multiple presets consisting of watch folders, destination folders, and specific arguments for use in HandBrake. The app then polls the watch folders for new files, builds an internal processing queue, hands each file off to the embedded HandBrake CLI, and moves the new file into it’s proper home (while cleaning up after itself!) when finished.

The application uses some of the really cool APIs exposed through AIR 2.0, including SQLite databases and most importantly the NativeProcess APIs which allow AIR applications to talk with native processes.

Here is a video demonstrating the application in action running on both desktop and a remote server:

The main reason for building this application was to have it run on a server and allow users to transfer files to an exposed shared folder (the watch folder) and not have to worry about encoding and moving files around. It is obviously written to run on the desktop as well- but in case you’d like to set it up on a server, here is how I went about it:

I’m using a Windows Server, so we’ll be setting up our AIR application to run as a Service. That way, it will continue to run and monitor folders even while no one is logged in.

  1. Download Windows Server 2003 Resource Kit Tools
  2. Install WSRT on your server
  3. Open the command prompt and navigate to where you installed the toolkit
  4. Run instsrv DropFolders "C:\{pathToToolkit}\srvany.exe" to create a Service called “DropFolders “
  5. Add the following to your Registry: Run reg ADD HKLM\SYSTEM\CurrentControlSet\Services\DropFolders\Parameters /v Application /d “C:\Program Files\DropFolders\DropFolders.exe” to point the service to the AIR application
  6. I then went into the Service manager to have the thing run with my credentials. Also be sure that the Service will start automatically. You will have to modify based upon your specific environment.
  7. Create whatever system of watch and destination folders you need
  8. Create access to these watch folders through Network Shares or FTP or whatever
  9. Fire up DropFolders and set up your various presets
  10. Close DropFolders, start the Service, and logout
  11. All set!

Once again though; you don’t need to do any of this if running as a normal desktop application. Just install and use.

I’ll be releasing the application onto the AIR Marketplace as soon as AIR 2.0 final goes public.

Video: AIR 2.0 NativeProcess Example

I’ve been looking for an opportunity to take advantage of the new flash.desktop.NativeProcess class within AIR 2.0 and was fortunate enough to have a quick project fall into my lap early this week that would serve as the perfect testing ground.

If you aren’t familiar with NativeProcess, it basically gives you the ability to interact directly with just about any process running on the host operating system. You can pass in any number of arguments into the program being invoked, and can even intercept messages being transmitted in response to your invocation.

The project basically involves building a custom interface upon the excellent HandBrake CLI for enabling server side directory polling along with custom transcoding presets complete with individual output destinations.

The following video is simply an overview of what is capable with AIR 2.0 – I hope this will be the first of many as I built this project to completion, especially as this is such an exciting (and powerful!) addition to the Flash Platform.