Encoding video using Handbrake on x86 NAS

Introduce yourself to us and other members here, or share your own product reviews, suggestions, and tips and tricks of using QNAP products.
bseboy
New here
Posts: 6
Joined: Tue Jan 19, 2010 8:13 pm

Encoding video using Handbrake on x86 NAS

Post by bseboy »

I use HandBrake 0.93 CLI (command line) to encode various video files overnight on my TS-459.

The process should work on any x86 based model.

You will need to get HandBrakeCLI (0.93 version required, not 0.94) installed and on your path before the script will work.

I got it from a Debian package, and manually extracted it (link below).

http://debian-multimedia.org/pool/main/ ... 1_i386.deb

For it to work you create an 'Encode' folder (/share/Public/Encode in the script).

Inside this folder you create a folder for each set of encoding settings.

Each of these folders must contain a file called 'handbrake.profile'. There's an example below.

The script looks for any files with specific extensions, or VIDEO_TS folders within these 'profile' folders (and in any subfolders).

I use cron to run the script at midnight every day.

Code: Select all

# !/bin/sh

# encode files in Encode folder with handbrake

ENCDIR=/share/Public/Encode

# profile filename
PROFILE=handbrake.profile

# extension to use when we complete encoding a file
COMPEXT=complete

# flags that we are busy
WORKFILE=$ENCDIR/working

# 1. check work file not present .... quit if it is

if [ -a $WORKFILE ];
then
        echo "Encode already in progress ... exiting."
        exit 0
fi

echo "Looking for files to encode ..."
touch $WORKFILE

# get list of directories to look in for video files / profiles
PROFDIRS=`find $ENCDIR -type d -name "*"`

for DIR in $PROFDIRS
do
        if [ -a "$DIR/$PROFILE" ];
        then
                OPTIONS=`cat "$DIR/$PROFILE"`
                echo "$DIR has profile options : $OPTIONS"
                # look for any file with specified extensions
                VIDFILES1=`find $DIR -type f -name "*.ts"`
                VIDFILES2=`find $DIR -type f -name "*.avi"`
                VIDFILES3=`find $DIR -type f -name "*.mkv"`
                VIDFILES4=`find $DIR -type f -name "*.m2ts"`
                VIDFILES5=`find $DIR -type d -name "VIDEO_TS"`
                VIDFILES6=`find $DIR -type f -name "*.mpg"`
                VIDFILES7=`find $DIR -type f -name "*.wmv"`
                # .. and so on, finally put them all together
                VIDFILES="$VIDFILES1 $VIDFILES2 $VIDFILES3 $VIDFILES4 $VIDFILES5 $VIDFILES6 $VIDFILES7"

                for VID in $VIDFILES
                do
                        OUTFILE=$VID.mp4
                        echo "Encoding video file $VID to file $OUTFILE"
                        # use HandBrakeCLI to encode the file
                        COMMAND="HandBrakeCLI -i $VID -o $OUTFILE -f mp4 -m -O $OPTIONS"
                        `$COMMAND`
                        mv $VID $VID.$COMPEXT
                        echo "Completed and renamed to $VID.$COMPEXT."
                done
        fi
done

echo "Completed encoding."
rm $WORKFILE
Here's an example Handbrake profile

Code: Select all

-e x264 -b 1200 -2 -T -E faac -B 160 -6 dlp2 --decomb --deblock -w 640
Nerdy
Starting out
Posts: 24
Joined: Wed Jan 13, 2010 6:48 pm
Location: Brisbane, Australia

Re: Encoding video using Handbrake on x86 NAS

Post by Nerdy »

Thanks for the info.
Any reason for using 0.93 instead of 0.94?
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

Could you please give some more details on this process?

I don't understand how you did this:
I got it from a Debian package, and manually extracted it
As much information as you can give would be helpful.
User avatar
spoon.uk
Been there, done that
Posts: 992
Joined: Tue Jan 06, 2009 7:14 pm
Location: London, United Kingdom
Contact:

Re: Encoding video using Handbrake on x86 NAS

Post by spoon.uk »

maxdreamland
Starting out
Posts: 20
Joined: Fri Jul 16, 2010 4:40 pm

Re: Encoding video using Handbrake on x86 NAS

Post by maxdreamland »

Hi,

i'm curious how you resolved some of the missing dependencies. in particular i can't find a suitable ipkg that contains libxvidcore.so.4.

any advice?

regards
Mario
User avatar
spoon.uk
Been there, done that
Posts: 992
Joined: Tue Jan 06, 2009 7:14 pm
Location: London, United Kingdom
Contact:

Re: Encoding video using Handbrake on x86 NAS

Post by spoon.uk »

Do:

Code: Select all

cat HandBrakeCLI
and paste the output here.
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

I'm getting the same warning "error while loading shared libraries: libmp3lame.so.0: cannot open shared object file: No such file or directory"

When I do the command

Code: Select all

cat HandbrakeCLI
it just prints a bunch of gibberish to the screen, like when you try printing the contents of a binary file (which makes sense).
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

Okay, I installed the missing dependency like b0n3z did

Code: Select all

ipkg install lame
and it installed, but it puts it in a different location than what HanBrakeCLI is looking for. The libmp3lame.so.0 gets installed into /opt/lib and I think that it normally gets put into /usr/lib.

I think your symbolic link was wrong. I was able to get past the first missing dependency by creating the following

Code: Select all

ln -s /opt/lib/libmp3lame.so.0  /usr/lib/libmp3lame.so.0
Though another missing dependency shows up after that one. I continued to *fix the missing dependencies by repeating this process for another 3-4 files. I wasn't able to get them all however, after I restarted the NAS all of my symbolic links were gone.

Maybe if we somehow permanently added /opt/lib to the $PATH variable it would work. Has anyone seriously been able to get HandBrakeCLI running on a QNAP? We could use some more help...
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

I found an *almost helpful thread on the HandBrake Forum that describes an alternative way of trying to get HandBrake installed on the QNAP by building it from source. I am currently exploring that method as well and have linked to the thread here in case it eventually works...
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

Okay I made some progress. I was having a separate problem and another user named "micke" told me he never builds on the NAS, he has a separate Linux system that he uses and builds on that. The key it seems is using the Debian distribution Etch which is comparable to what is installed on the Qnap NAS (it uses the same libraries and such).

Step 1.
Do a google search for debian-40r7-i386-DVD-1.iso I found it here and here. There seems to be three DVDs in total, but I only needed the first.

Step 2.
Install Debian Etch on an alternate system. I found it was easiest to use VirtualBox and just install it onto my main Windows machine. The setup is pretty straight forward, with one tricky part... When asked if you want to use a Fixed Size disk or a Flexible Size disk, choose Fixed. I tried flexible and it got stuck, so just set aside a few GB for the Debian installation and use the fixed size.

Step 3.
Install the missing dependencies. I followed the instructions found on the HandBrake website about compiling for Linux. At the moment that website seems to be down, but if you use google you can view the cached version. I recommend only trying to install what is needed for the Command-Line version of Handbrake because it has less dependencies.

Code: Select all

su root
apt-get install subversion build-essential autoconf automake make libtool zlib1g-dev libbz2-dev
You also need YASM which I couldn't find via apt-get, you might have better luck though. I got it working by installing it from source.

Step 4.
Create a folder on your newly acquired Debian box to work out of, I called mine Handbrake. Then download and build HandBrake from the svn repository:

Code: Select all

mkdir HandBrake
cd HandBrake
svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk
cd hb-trunk
./configure --launch --disable-gtk
This step took a while, but once finished navigate into the folder called "build" and there should be a HandBrakeCLI executable in there. When running the above step make sure you are not getting any more errors. I was missing "make" the first time I tried.

Step 5.
The final thing to do is copy the HandBrakeCLI that we just built onto your Qnap NAS. I accomplished this by emailing the file to myself using GMail from within the Debian Box. Maybe you know a better way to transfer files across Operating Systems?

I still have some more testing to do, but after copying the HandBrakeCLI file to my NAS I was able to run it without getting warnings:

Code: Select all

[/share/Public/handbrake/hb-trunk/build] # ./HandBrakeCLI -u
[21:36:11] hb_init: checking for updates
[21:36:11] Using http://handbrake.fr/appcast_unstable.xml
[21:36:11] latest: 0.9.4, build 2009112300
[21:36:11] hb_init: checking cpu count
[21:36:11] hb_init: starting libhb thread
HandBrake svn3717 (2010122801) - Linux i686 - http://handbrake.fr
Your version of HandBrake is up to date.
I haven't tried to actually transcode anything yet, but I will update this post with the results soon.
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

Okay B0n3z, I sent you an email. Does anyone know where I could upload a binary file to share?

Just tried to attach it to this post and the forum says that extension is not allowed.
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

It might have gotten corrupted from me copying it so many times within Windows... and I renamed it. Installing the VMware and Debian Etch wasn't too hard, I would try building it yourself and see what happens.
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

well I have some time now and I don't seem to have apt-get or svn on my Qnap TS-509 Pro. So I'm wondering if I can use ipkg to get the same requirements?
No, don't try doing it on the QNAP. You only have IPKG to work with and I tried, but was unable to get everything required to "make" installed properly. So I tried installing as much as I could on the Qnap, which may or may not be needed, but ended up using a separate system to do the heavy lifting.

If you want to try installing some of these dependencies anyways on your QNAP use the command

Code: Select all

ipkg install <whatever>
For example to get SVN you would issue this command

Code: Select all

ipkg install svn
Remember that your QNAP has limited resources so installing too much of this stuff is a bad idea anyways, hence why you should install the distro I linked too and install the requirements on a separate computer. When you successfully "make" the HandBrakCLI you end up with something that is similiar to a compiled, self-contained, executable that you should then be able to relocate and copy elsewhere (like to your QNAP).
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

You don't necessarily need "wget" working. It just goes and downloads a file from the URL you give it. You could browse to that resource with your normal computer and web browser and download the file to something like a thumbdrive and then copy it to the Linux machine. Of course, getting your linux machine to read the thumbdrive might be just as hard ;)
micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster »

I just tried it again and it worked for me. I typed the command and this is what I got

Code: Select all

svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk
Checked out revision 3737.
Maybe something is blocking your Internet or the "SVN" protocol? Like a firewall? Worst case would be to try and find a tarball of the source just like you did for YASM.
Post Reply

Return to “Users' Corner”