Jump to content
aaronjb

HowTo: Install HandBrakeCLI on your unRAID server (rather than in a VM)

115 posts in this topic Last Reply

Recommended Posts

So I did all this because VMWare only allows you to access two cores in any VM, even on a quad core box - and since I specifically spent the extra on a quad core processor for my unRAID box with transcoding my DVDs in mind, I wanted to make use of them :)  So without further ado:

 

 

 

If you want to compile HandBrake yourself then follow the instructions below - you'll be checking out a development tree of HandBrake and compiling that on your unRAID development box, then installing a package you build yourself.

 

If you'd rather just download the last one I built (which could be out of date and/or have bugs, just as any SVN build can) then skip to step 1a at the foot of this post.

 

 

1) Prepare your unRAID Development machine per here: http://lime-technology.com/forum/index.php?topic=2937.0

  N.B. The version of slackware your development machine uses will change the minimum version of libstdc you need later in these instructions - pay attention there!

 

2) Install yasm & jam:

wget http://repository.slacky.eu/slackware-12.1/development/yasm/0.7.2/yasm-0.7.2-i486-1sl.tgz
wget http://repository.slacky.eu/slackware-12.1/development/jam/2.5/jam-2.5-i486-2gal.tgz

installpkg yasm-0.7.2-i486-1sl.tgz
installpkg jam-2.5-i486-2gal.tgz

 

2) Check out a copy of the HandBrake source. I like to keep everything in a 'dev' directory in my home, so for me it's:

cd dev
svn co svn://svn.handbrake.fr/HandBrake/trunk HandBrake

 

After a couple of minutes the checkout should complete, and drop you back at the shell prompt, so pop into the checked-out directory and let's get started:

A    HandBrake/make/config.guess
Checked out revision 2353.
root@slacky:~/dev$ cd HandBrake

 

 

**N.B.** As of right now, HandBrake refuses to build on Slackware because they require a later version of libtool than is installed by default due to a patch to pass '-i' to libtoolize when building xvidcore.

 

A dirty hack to fix this is to remove the patch file - you should test a build first to see if it completes, since the SVN version is always in-flux, this could easily be fixed by the time you're reading this.  If it doesn't build, come back to this step and start from here again.

 

3) If you need to, remove the xvidcore patch:

cd contrib/xvidcore
rm -f A00-libtool.patch
cd ~/dev/HandBrake
rm -rf build

 

Otherwise, run configure and then we can build:

cd ~/dev/HandBrake
./configure
cd build
make

 

Now sit back and watch as the build process runs through, downloading the required libraries and compiling everything up.

 

The build should stop with an error relating to gtk, but that's OK - we don't actually care about the GTK GUI anyway:

../gtk/src/values.h:69: error: expected ')' before '*' token
make: *** [gtk/src/create_resources-native.o] Error 1

 

As long as the build directory now contains a binary called 'HandBrakeCLI', we're good to go.

 

 

4) If you want to save the HandBrake binary on your USB key then you can now simply copy it (via whatever method you prefer) to somewhere in /boot (I keep packages in /boot/packages, for example), otherwise if you'd rather store it in the RAMfs, you can make an installation package now:

 

mkdir -p /handBrakeREALTIME/usr/local/bin
cp HandBrakeCLI /handBrakeREALTIME/usr/local/bin
cd /handBrakeREALTIME
makepkg HandBrakeREALTIME.tgz

 

Then copy the package to somewhere on your unRAID /boot - I use /boot/packages personally.

 

5) From this point on, all steps are performed on your unRAID server directly

 

Edit /config/go to include a line which reads:

 

installpkg /boot/packages/HandBrakeREALTIME.tgz

 

(Naturally change the path if you store your packages elsewhere)

 

5) HandBrake also requires cxxlibs, and depending on the version of Slackware you built on will dictate the version of cxxlibs you need to install.  If your development box is 12.0, you'll need cxxlibs 6.0.8 or newer, 12.1 or newer will require 6.0.9 or newer.  Download them on your main unRAID box thusly if you don't already have them:

 

wget http://www.mirrorservice.org/sites/ftp.slackware.com/pub/slackware/slackware-12.1/slackware/a/cxxlibs-6.0.9-i486-1.tgz

 

And add a line to your 'go' script to load the pacakge:

installpkg /boot/packages/cxxlibs-6.0.9-i486-1.tgz

 

 

And now you're all done! Congratulations!

 

 

If you just want to use the package I've pre-built then start here:

 

1a) Telnet to your unRAID box and run the following commands - note I keep all my packages in /boot/packages, so that's where I'm assuming you do, too:

 

wget http://zion.mind-design.co.uk/unRAID/HandBrakeCLI-svn2354-i686-1ajb.tgz
wget http://www.mirrorservice.org/sites/ftp.slackware.com/pub/slackware/slackware-12.1/slackware/a/cxxlibs-6.0.9-i486-1.tgz

 

2a) Add the following lines to your /boot/config/go script:

 

installpkg /boot/packages/cxxlibs-6.0.9-i486-1.tgz
installpkg /boot/packages/HandBrakeCLI-svn2354-i686-1ajb.tgz

 

Note that my package installs to /usr/local/bin

 

 

Enjoy!

 

 

Any corrections or problems then post up and I'll adjust the instructions accordingly :)

 

Aaron

Share this post


Link to post

I am certain this will be of help to alot of users.

 

If you can find the time could you add a wiki page for this and edit it there. In the long term thats a far better place for these things.

 

Kudos

 

p.s. if you get stuck with formatting etc just PM me and I will do it for you

Share this post


Link to post

Where is a good place to read about how to actually use this?  I have the windows version, and I'm wondering if I can have the gui generate a script that would be portable...  Thanks for any tips, this is a great tool.

 

Chris

Share this post


Link to post

The best resource is really the HandBrake website - http://handbrake.fr - the forums and the Wiki. Start with the Wiki, though, as they don't suffer fools gladly on the forums :)

 

It's fairly easy to figure out what CLI options you need based on what GUI options you're picking - the main thing is to remember to look at what x264 options are being set in the GUI (the long text string) and use those at the CLI with the '-x' parameter, but the GUI can't generate a script unfortunately (would be nice if it could, actually).

 

Aaron (who really should get around to writing that Wiki page  :-[

Share this post


Link to post

The Windows version of HandBrake GUI does have a Query Editor that can generate the base script. Just then call the CLI executable with this script at the end.

Share this post


Link to post

Aha - thanks :) I've not used the Windows version - only the Mac GUI & CLI versions, so I wasn't aware of that (maybe that feature exists in the Mac GUI too - I'll have to go hunting)

Share this post


Link to post

Using the GUI to create a script is pretty easy, it turns out.  After you choose your settings, go to the 'Query Editor' tab and click the button to generate the query.  This represents the command line arguments to the CLI.  Here is a link to the Handbrake page with the parameters: http://trac.handbrake.fr/wiki/CLIGuide  One thing to look out for is that the gui will generate a file with the chapter increments.  The flags for this will be on the generated query unless you go out of your way to turn them off.  I wasted a lot of time trying to figure out if there was a problem with my encoding when it turned out that somehow I had the 'c' setting in there limiting me to the first 17 chapters of a movie.

 

In case it might help someone out, here is the script that I put together for encoding movies for my iPhone (based on the iPhone settings of Handbrake).  Note, you may not have your movies in the same place I have mine :)

 

HandBrakeCLI -i /mnt/disk1/Movies/$1 -t 1 -o /mnt/disk1/Movies/movie_stuff/$1.m4v -f m4v -X 480 -e x264 -q 0.59 -a 1 -E faac -B 128 -R 48 -6 dpl2 -D 1 -x level=30:cabac=0:ref=2:mixed-refs=1:analyse=all:me=umh:no-fast-pskip=1 -v

 

Thanks again for building this.  This is such a great addition to my server and stuff like this is the reason I bought a core2duo with 4G of ram...

 

Chris

Share this post


Link to post

Thanks again for building this.  This is such a great addition to my server and stuff like this is the reason I bought a core2duo with 4G of ram...

 

No problem at all, and thanks for the extra information :)

 

I'll build a new SVN version soon, as the more recent versions support DTS-passthrough as well as AC3, which makes for easier transcoding of anything where you want to preserve a DTS track - I'll update here when I've done it :)

Share this post


Link to post

Thanks for the how-to aaronjb! I managed to compile the newest HandBrake snapshot, which is going down the path towards 0.9.4. I've been using it on my Macs for a few weeks now and it's been solid for my needs.

 

If you want to use it, just use aaronjb's instructions, and substitute my package for his, and adjust your go script accordingly.

 

http://www.mediafire.com/download.php?m50mncmnj3t

 

Share this post


Link to post

OH! I missed this. I've been using DVD Decrypter+MeGui (older version for years) to archive my DVD's (-x264 crf18). I recently just found out about Handbreak and have been testing its results on my WinXP. I was going to build a small windows box thinking this would be too difficult to get encoding working (me=linux n00b). I only have a lonely single core, but if this works I may just add a dual-core to my unRaid and save some money.

Share this post


Link to post

OH! I missed this. I've been using DVD Decrypter+MeGui (older version for years) to archive my DVD's (-x264 crf18). I recently just found out about Handbreak and have been testing its results on my WinXP. I was going to build a small windows box thinking this would be too difficult to get encoding working (me=linux n00b). I only have a lonely single core, but if this works I may just add a dual-core to my unRaid and save some money.

You don't need a dual core to use HandbreakCLI on the unRAID server, about a month ago, after instaling it as described in this thread, I used a  shellscript to invoke it on each of  a subset of my ISO images in turn to create a .avi compressed version on a local disk for installation in one of my MG-35 media players I was going to use when traveling.  I managed over the course of a week or so to transcode about 500 movies from the ISO version to the .avi.  I did not care how long it took, I just set the script in motion and watched it over time.  I only have an old 2.6Ghz celeron...

 

Joe L.

Share this post


Link to post

I'm a patient person, so how long encoding takes is not such a big deal. Would you mind posting your script Joe? I seem to average 15 fps on my unraid.

Share this post


Link to post

I'm a patient person, so how long encoding takes is not such a big deal. Would you mind posting your script Joe? I seem to average 15 fps on my unraid.

 

Here it is:

for i in /mnt/user/Movies/*.ISO

do

  f=`basename $i .ISO`

  HandBrakeCLI -i $i -t 1 -o /mnt/disk/hdi1/$f.avi -f avi -p -e ffmpeg -S 700 -a 1 -E lame -B 160 -R 0 -6 dp12 -D 1 -v

  echo $i

done

 

Note: I had a disk outside of the array mounted on /mnt/disk/hdi1.  I was writing the output files to it.  You could change the script to write the output anywhere you like.

All of my ISO images were of the movie only. (no menus, extras)

You can adjust the options on HandBrakeCLI to suit your needs.

 

I only got about 4 or 5 fps on my unRAID server.  It will get the job done, but as you said, be patient.

 

Joe L.

Share this post


Link to post

My workflow is a bit more complicated to set up, but overall I'm pleased with how easy it is to use once I got it running. I rip a lot of movies and TV DVDs, so I needed a solution that would be somewhat flexible for both.

 

• In my go script I install HandBrakeCLI 0.9.4, perl 5.10.0, screen 4.0.3, and copy two scripts to /usr/bin (optional - it's just so I don't have to type their path out each time).

• I rip my DVDs to VIDEO_TS folders on my local computer, then transfer to my unRAID server. I separate TV and movie rips, as they get treated slightly differently. For my own organization, movies go in to /mnt/user/HandBrake/Movies/Ripped and TV goes in to TV/Ripped. Any folder structure works.

• I then set up a quick screen session, then execute the relevant script (TV or movies). It runs continuously until it's done encoding every VIDEO_TS rip in the folder its been pointed to.

 

The scripts are just very slightly modified versions of handbraker.pl. Long story short, this script traverses the folder you point it at, finds all the VIDEO_TS folders, HandBrake encodes every title in each VIDEO_TS folder that's more than 10 minutes long, using your settings. I like it over HandBrake's default setting of looking for the single longest title as it's more useful for getting extras, documentaries, and other bonus content from movie DVDs, and with a simple tweak, it's great for TV DVD encoding.

 

I use the stock script, though I replaced all the quality settings with my own set of settings, and I made the time limit so it only encodes 20 minute+ titles, for movie encodes. For TV encodes, I added a little bit of logic that checks to see if the title is more than 20 minutes long, but less than 55 minutes long (so it grabs all titles that are TV episode length), then encodes them.

 

As for quality settings - x264 all the way, but that's a discussion for another day, and another forum. My unRAID server is on a 2.5GHz Core 2 Duo, so encoding speeds are pretty rapid. With my fairly high quality settings, I see 25 to 30fps regularly, and even 40fps on some content. It's hard to compare apples to apples though, unless you're using identical settings with identical sources, as encoding speeds can vary with HandBrake a ton.

 

I'll attach my modified versions of the handbraker.pl scripts in case anyone wants to see them. Let me know if you'd like help setting them up.

Share this post


Link to post

I wanted to just be able to drop .ISO files in a directory and queue up encoding. There is no queue in the CLI, but with my limited scripting knowledge I was able to piece together some scripts that almost work. I have a few small questions.

 

handbrake_queue.sh; ln 59

I would like the output file name to be the same as the ISO. My script is using the "basename" command and appending ".mp4". This produces "movie title.ISO.mp4". How can I remove the ".ISO"

 

handbrake_queue.sh; ln 16 - I'm trying to determine if any ISO files are in the directory. I can't seem to get this to work correctly.

if [ $(ls -l $ISO/*.ISO | wc -l) -gt 0 ]

 

I start "handbrake_queue.sh &" so it can just run in the background. Its a never ending loop with a 1min (will up this to 10min) delay between checks for new .ISO files. On line 74, I start /queuelist.sh & the same way to prevent the process outputting to the screen. Is this a good way to go about this?

 

Thanks

Share this post


Link to post

I wanted to just be able to drop .ISO files in a directory and queue up encoding. There is no queue in the CLI, but with my limited scripting knowledge I was able to piece together some scripts that almost work. I have a few small questions.

 

handbrake_queue.sh; ln 59

I would like the output file name to be the same as the ISO. My script is using the "basename" command and appending ".mp4". This produces "movie title.ISO.mp4". How can I remove the ".ISO"

 

To get the name without the .ISO you need to supply an argument to the basename command, as I did in the short script I posted a few back in this thread.

 

The specific line in the script is

f=`basename $i .ISO`

 

Assuming "$i" has the full pathname to the .ISO file, "$f" will then have just the file name, without the .ISO suffix.

 

Joe L.

 

Share this post


Link to post

So I did all this because VMWare only allows you to access two cores in any VM, even on a quad core box - and since I specifically spent the extra on a quad core processor for my unRAID box with transcoding my DVDs in mind, I wanted to make use of them :)

 

aaronjb,

What CPU are you using? What encoding speeds to you see? I get ~10fps and ~3hrs (give or take) to encode a movie (basically tweaked setting of the 'classic' preset with a --quality 20). I find HandbrakeCLI runs better on unraid with my single 2.7Ghz, than on my windows Dual 2.0Ghz.

 

I attached my Handbrake queue script. Its not user friendly with arguments and all, but neatly written. I run a tweaked S3 Sleep script. I wanted to be able to drop ISO's into a directory and have the script pick them up as long as there is time before I want my box to sleep at night. The sleep script won't shut down while the drives are spinning. So, as it loop though the files and adds 3hrs for ISO and 2hrs for mp4 (using the _small.sh settings) files until 7pm is exceeded. Just wanted to share what I worked on this weekend.

 

P.S. I'm so happy this works on unRaid. Thank you for the latest compiled version ClunkClunk  :)

Share this post


Link to post

ClunkClunk,

 

Thanks so much for compiling a newer version of Handbrake.

 

I’ve encountered a similar problem as reported here which sometimes produces garbled audio when encoding a MP4/ACC file. I do this to reduce the file size of a mp4 file for playback on a portable device. Some movies encode fine while others have audio that sounds like a record player spinning slowly. The same problem happens weather I encode on windows or unRaid (I'm playing the files in VLC).

 

Handbrake-svn3154 still has the issue.

 

I tried to compile my CLI and get the following error when trying to retrieve the svn:

 

svn: error while loading shared libraries: libaprutil-1.so.0: cannot open shared object file: No such file or directory

 

Would you compile Handbrake-svn3205 (or above) package for us novices?

 

 

Share this post


Link to post

Thanks ClunkClunk!

 

I was able to encode the same MP4/AAC to a smaller mp4 file and the audio was correct this time. I have not tested this version will an ISO yet. One thing I noticed was the version seems to old when checking for a newer version...

root@unraid:~# HandBrakeCLI -u
[10:01:01] hb_init: checking for updates
[10:01:01] Using http://handbrake.fr/appcast_unstable.xml
[10:01:02] latest: 0.9.4, build 2009112300
[10:01:02] hb_init: checking cpu count
[10:01:02] hb_init: starting libhb thread
HandBrake svn3282 (2009110401) - Linux i686 - http://handbrake.fr
You are using an old version of HandBrake.
Latest is 0.9.4 (build 2009112300).

Share this post


Link to post

It probably seems old due to the Virtual Machine I was using had its date/time set incorrectly. On my next day off (Friday), I'll try to recompile it with an updated date/time and see if the issue is resolved.

Share this post


Link to post

ClunkClunk,

 

The version out-of-date is fixed now. I'm still able to re-encode an mp4 and the audio works. My normal encodes are ~1.5gig (full resolution). I really wanted the audio bug fixed when re-encoding for portable viewing like my on my Droid. Converting an ISO, I had to change the "--Longest" switch in my script, but seems to work. Thanks again.

 

A few changes that I feel are worth mentioning:

 

Changeset 3268: add --main-feature title selection option (replaces -L longest title selection option)

Changeset 3265: Fix an issue with the CLI version check logic.

Changeset 3205: fix audio clipping when downmixing and output codec is lame

 

On a side note, I upgraded the AMD Sempron 140 with a quad core Athlon II X4 635 in my unRaid. The single core preformed impressively well, but I wanted some more power for Handbrake. My encodes went from 10 fps (~4hrs) to 36 fps (~1hr) per movie. It's overkill for Slackware, but I might run a vm server in the future and this will definitely help.

 

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.