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 » Sun Jan 31, 2010 11:29 pm

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/h/handbrake/handbrake-cli_0.9.3-0.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 » Tue Feb 02, 2010 6:11 pm

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 » Mon Jun 21, 2010 11:17 am

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.


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

Re: Encoding video using Handbrake on x86 NAS

Post by maxdreamland » Sat Aug 14, 2010 7:41 pm

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
b0n3z
Starting out
Posts: 21
Joined: Fri Jan 08, 2010 11:58 pm
Location: Orange, CA, USA

Re: Encoding video using Handbrake on x86 NAS

Post by b0n3z » Fri Oct 29, 2010 11:34 pm

Thank you bseboy & spoon.uk for the info.

This noob is still a bit stuck :cry: . It would be awesome if this was available in a ipkg (optware) or better yet qpkg :wink: . I'm stuck on how to "install" the app or run it I guess. The following is what I did:

mkdir /share/Public/Encode
(I then copyied the file "handbrake-cli_0.9.3-0.1_i386.deb" from my PC to the NAS location above)
ar vx handbrake-cli_0.9.3-0.1_i386.deb
(this extracted 3 files: "control.tar.gz", "data.tar.gz" and "debian-binary")
tar -xzvf data.tar.gz
(this extracted the "usr" directory and files "copyright" and "changelog.Debian.gz" in the ./usr/share/doc/handbrake-cli/ directory)
(this also extracted "HandBrakeCLI" in the ./usr/bin/ directory)
tar -xzvf control.tar.gz
(this extracted "control" and "md5sums")

So after this step - I tried to run HandBrakeCLI so I did the following:

ch /share/Public/Encode/usr/bin/
chmod 777 HandBrakeCLI
./HandBrakeCLI
(this gave me the following:)
(./HandBrakeCLI: error while loading shared libraries: libmp3lame.so.0: cannot open shared object file: No such file or directory)

So I think I'm at the same spot maxdreamland is at... I REALLY want to figure this out and make it functional. I want to be able to stream movies I have on the QNAP back to my Android phone using QNAP Mobile.

thanks everyone,

-b0n3z
Model: TS-509 Pro with E7600 & 4GB Ram
HDD Model: (5) Seagate ST32000542AS CC32
HDD Capacity: 8TB
RAID Config: RAID 5 EXT4

User avatar
b0n3z
Starting out
Posts: 21
Joined: Fri Jan 08, 2010 11:58 pm
Location: Orange, CA, USA

Re: Encoding video using Handbrake on x86 NAS

Post by b0n3z » Fri Oct 29, 2010 11:55 pm

OK - I think I got a bit farther.. but I don't know how to make the "HandBrakeCLI" use the codec installed. The following is what I have done after the above post.

In the web interface of QNAP - Applications/QPKG Plugins, installed Optware. Opened telnet session to QNAP and did the following:
ipkg update
ipkg install lame
(This seemed to have installed the lame codec. I can do the following and see the files needed. ls /opt/lib/libmp3*.*)

(I even tried to link using the following)
ln -s /opt/lib/libmp3lame.la /share/Public/Encode/usr/bin
(But I still get the same error above.)

I feel sooooo close, yet still so far away. Heeeeelp

-b0n3z
Model: TS-509 Pro with E7600 & 4GB Ram
HDD Model: (5) Seagate ST32000542AS CC32
HDD Capacity: 8TB
RAID Config: RAID 5 EXT4

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 » Sat Oct 30, 2010 7:48 pm

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 » Tue Dec 28, 2010 10:00 am

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 » Tue Dec 28, 2010 4:30 pm

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 » Tue Dec 28, 2010 7:57 pm

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 » Wed Dec 29, 2010 1:42 pm

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.

User avatar
b0n3z
Starting out
Posts: 21
Joined: Fri Jan 08, 2010 11:58 pm
Location: Orange, CA, USA

Re: Encoding video using Handbrake on x86 NAS

Post by b0n3z » Thu Dec 30, 2010 12:19 pm

micster!!! that's awesome!
I can't wait to test this out. I'm away for the holidays so I can't wait to get back home and try all this. If there is any chance I could get the compiled file from you that would be a HUGE help (late Christmas present? - [email recieved] that's a zero and a three).

Now if only I could view the QNAP Administration web page on my Android Incredible - I would be one happy camper.
Last edited by b0n3z on Fri Dec 31, 2010 10:20 am, edited 1 time in total.
Model: TS-509 Pro with E7600 & 4GB Ram
HDD Model: (5) Seagate ST32000542AS CC32
HDD Capacity: 8TB
RAID Config: RAID 5 EXT4

micster
Starting out
Posts: 25
Joined: Thu Sep 03, 2009 12:43 pm

Re: Encoding video using Handbrake on x86 NAS

Post by micster » Thu Dec 30, 2010 3:54 pm

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.

User avatar
b0n3z
Starting out
Posts: 21
Joined: Fri Jan 08, 2010 11:58 pm
Location: Orange, CA, USA

Re: Encoding video using Handbrake on x86 NAS

Post by b0n3z » Fri Dec 31, 2010 10:39 am

Thank you micster! Ok - I just tried it after making it executable. However when I run it I get a "Segmentation fault". So I'm not sure what I did wrong...

-b0n3z
Model: TS-509 Pro with E7600 & 4GB Ram
HDD Model: (5) Seagate ST32000542AS CC32
HDD Capacity: 8TB
RAID Config: RAID 5 EXT4

Post Reply

Return to “Users' Corner”