luni, 8 aprilie 2013

Serviio on DW My Book Live working with transcoding.

Sorry for my bad English is not my primary language !!!

I wanted to keep things simple and I did not want to use my PC or laptop for hosting the movies or downloading torrents because is a hassle to turn them on and off and then the power consumption, the biggest problem was the convenience of controlling everything from the TV remote.
After two days of searching I got nowhere so I decided to think and put them together.

My network config:
 - My book Live 1Tb (from eBay got it cheap) thinking that was the only solution that I can afford and has a decant processor to do transcoding. MyBookLive 02.41.05-034 : Core F/W
 - My rooter is a Linksys E3200 running DD-WRT v24-sp2 (02/11/13) mega - build 20675
 - KDL-40HX751 3D TV latest firmware.

Visio diagram:

I had to upgrade the my book live to latest firmware because of the Play Station 2.
 I'm using the Open PS2 Loader to load games from network and My book Live had an older version of Samba, that is the file sharing server for Linux and the shares cannot be accessed from the PS2.

Ok let's start configuring the my book live:

First be sure that you have the latest firmware MyBookLive 02.41.05-034 : Core F/W, is better to start clean I did a reset to defaults of the OS on My book live.
Follow this tutorial for this: RESTORE DEFAULTS ON MY BOOK LIVE

All console commands will be in RED.
1) Go to http://mybooklive/UI/ssh (case sensitive) replace “mybooklive” if you have renamed it to something else, or replace it with its IP address. It's a hidden UI menu to enable SSH.
Then select Settings→Media→ and turn of Twonky
Under Settings→System→Updates→ Turn off Automatic Updates.

2) Go to Putty and log in to your NAS via SSH (I assume that you know how to do this) optware and nano are already installed on this firmware.
Test it by typing:
code:

nano --help




3) Add necessary repositories
  Code:

nano /etc/apt/sources.list


Add lines and put # in front of all that is already in the file.
  Code:

deb http://www.debian-multimedia.org stable main deb http://ftp.us.debian.org/debian/ sid main



4) Setup apt pinning so that stable versions are installed prior to testing and unstable versions.
  Code:

nano /etc/apt/preferences


Copy the following code
  Code:

Package: * Pin: release a=stable Pin-Priority: 1001 Package: * Pin: release a=testing Pin-Priority: 650 Package: * Pin: release a=unstable Pin-Priority: 600 Package: libxvidcore4 Pin: version 2:1.3.2* Pin-Priority: 1001



5) Update repository and install Keyring
  Code:

apt-get update apt-get install --allow-unauthenticated debian-multimedia-keyring



6) Install ffmpeg
  Code:

apt-get remove ffmpeg x264 libx264-dev libvpx-dev librtmp0 librtmp-dev apt-get update apt-get install ffmpeg ffmpeg - version


after last command you will get this screen: (ignore last line)



7) Install Java
code:


apt-get update
apt-get install --allow-unauthenticated debian-keyring
apt-get install --allow-unauthenticated debian-archive-keyring
apt-get install openjdk-6-jdk
java -version
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-powerpc/jre
export PATH=$PATH:/usr/lib/jvm/java-6-openjdk-powerpc/jre





8) Install Serviio and setup user account to run the program.
code:
useradd serviio
passwd serviio
usermod -a -G root serviio

mkdir /usr/local/serviio/
cd /usr/local/serviio/
wget http://download.serviio.org/releases/serviio-0.6.2-linux.tar.gz
tar -xf serviio-0.6.2-linux.tar.gz
9) Launch Serviio as a test
cd serviio-0.6.2/bin
serviio.sh
You will be at a blank line, it appears like nothing is happening, yet the server is starting. One way to confirm is to open another ssh window, log in and run
tail -f /usr/local/serviio/serviio-0.6.2/log/serviio.log
This will show a live output of the serviio log file. When you are satisfied that it's launching, hit ctrl-c in both ssh windows.
10) Setup Daemon to launch serviio upon bootup of your MyBook Live.
10a) create serviiod
nano /etc/default/serviiod
Copy following code, the service account is the name of the account we created in step 6. Also, the Daemon is the path to the serviio.sh file, update if you use a different version/location.
#########################################################
#- Daemon Script Configuration for Serviio Media Server
#- By Ian Laird
#- /etc/default/serviiod
#########################################################

NAME="Serviio Media Server"
DAEMON="/usr/local/serviio/serviio-0.6.2/bin/serviio.sh"    ## Update this to point at serviio_root/bin/serviio.sh
SERVICE_ACCOUNT="serviio" ## DON'T RUN UNDER ROOT!
10b) create serviio script
nano /etc/init.d/serviio
Paste the following code.
    #!/bin/sh
    #
    #########################################################
    #- Daemon script for Serviio media server
    #- By Ian Laird; converted for Debian by Jacob Lundberg
    #- /etc/init.d/serviio
    #########################################################
    #
    ### BEGIN INIT INFO
    # Provides:          serviio
    # Required-Start:    $local_fs $remote_fs $network $syslog
    # Required-Stop:     $local_fs $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # X-Interactive:     true
    # Short-Description: Start/stop serviio media server
    # Description:       The Serviio media server makes your media available to
    #                    all kinds of networked devices.
    ### END INIT INFO


    . /lib/lsb/init-functions

    if [ -f /etc/default/rcS ]; then
            . /etc/default/rcS
    fi


    DAEMON_STOP=" -stop"
    NAME="$(basename $0)"
    PIDFILE="/var/run/serviiod.pid"
    TIMEOUT=10

    if [ -f /etc/default/serviiod ]; then
            . /etc/default/serviiod
    fi

    [ -x "$DAEMON" ] || exit 0


    running() {
            if [ "x$1" == "x" ]; then
                    echo 0
                    return 1
            fi

            PS=$(ps h -p $(echo $1 | sed -r 's/[\t \n]+/ -p /') | wc -l)
            echo $PS

            if [ $PS -gt 0 ]; then
                    return 0
            else
                    return 1
            fi
    }


    start() {
       # Set up correct LANG
          if [ -r /etc/default/locale ]; then
             . /etc/default/locale
             export LANG LANGUAGE LC_MESSAGES LC_ALL LC_CTYPE
          fi

            log_daemon_msg "Starting Serviio media server daemon" "$NAME"
            start-stop-daemon --start -q -b -p "$PIDFILE" -m -c "${SERVICE_ACCOUNT}" -x "${DAEMON}"
            log_end_msg $?
    }

    stop() {
            log_daemon_msg "Stopping Serviio media server daemon" "$NAME"
            if [ -r "$PIDFILE" ]; then
                    PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
                    if running "$PIDS" > /dev/null; then
                            "${DAEMON}" "${DAEMON_STOP}"
                            for PID in $PIDS; do
                                    if running $PID > /dev/null; then
                                            kill -TERM $PID
                                    fi
                            done
                    fi
                    COUNTDOWN=$TIMEOUT
                    while let COUNTDOWN--; do
                            if ! running "$PIDS" > /dev/null; then
                                    break
                            fi
                            if [ $COUNTDOWN -eq 0 ]; then
                                    for PID in $PIDS; do
                                            if running $PID > /dev/null; then
                                                    kill -KILL $PID
                                            fi
                                    done
                            else
                                    echo -n .
                                    sleep 1
                            fi
                    done
            fi

            if running "$PIDS" > /dev/null; then
                    log_end_msg 1
            else
                    rm -f "$PIDFILE"
                    log_end_msg $?
            fi
    }

    status() {
            echo -n "$NAME should be"
            if [ -r "$PIDFILE" ]; then
                    echo -n " up with primary PID $(<"$PIDFILE")"
                    PIDS=$(pstree -p $(<"$PIDFILE") | awk -F'[\(\)]' '/^[A-Za-z0-9]/ { print $2" "$4; }')
                    RUNNING=$(running "$PIDS")
                    if [[ $RUNNING && $RUNNING -gt 0 ]]; then
                            echo -n " and $RUNNING processes are running."
                    else
                            echo -n " but it is not running."
                    fi
            else
                    echo -n " stopped."
            fi
            echo
    }


    case "${1:-}" in
            start)
                    start
            ;;
            stop)
                    stop
            ;;
            restart)
                    stop
                    start
            ;;
            status)
                    status
            ;;
            *)
                    log_success_msg "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
                    exit 1
            ;;
    esac

    exit 0
10c) Set files to launch on startup.
chown serviio -R /usr/local/serviio
chmod 755 /etc/init.d/serviio
update-rc.d serviio defaults

11) Install web interface of servioio

nano /etc/network/interfaces

Add after line with "iface eth0 inet dhcp", this text -> up route add -net 240.0.0.0 netmask 240.0.0.0 dev eth0

cd /root
wget https://github.com/downloads/mpemberton5/Web-UI-for-Serviio/WebUI%20v1.0.2.zip
cd /var/www
unzip /root/WebUI\ v1.0.2.zip
chmod -R 0755 serviioweb
mv /etc/init.d/twonky /etc/init.d/twonky.norun
reboot



12) After reboot, wait minimum 5 min and check status when back up by using this command.
/etc/init.d/serviio status


You will get somthing like this:

NAS:~# /etc/init.d/serviio status
Serviio Media Server should be up with primary PID 4232 and 2 processes are running.

Your done Serviio is working on My book Live !!!


Go to http://mybooklive/serviioweb (case sensitive) replace “mybooklive” if you have renamed it to something else, or replace it with its IP address, and access serviio web interface, there you can manage the server.
If you want trans-coding create a Temp directory in your Public folder and change the Temp directory in serviio to that one because /temp directory will not work as is limited in size.





I use torrent on the NAS to so you need to install Install Mybook Live Feature Pack Manager and use Transmission as a client.

Useful utilities:
Android: ServiioDroid, Remote Transmission, WD 2GO
To check cpu, ram usage on  NAS from windows use gkrellm, you need to install the windows client as well.

sudo aptitude install gkrellm


This configuration is working for me for two days now  with no problems, MKV, FLV is working on my Sony TV

TESTS
MKV - 1080p movies working with trans-coding.
FLV - working


NOT WORKING
 - FF, Pause, REW when on a MKV or FLV file will fail (this I think is related with version of serviio)
 - After stopping a file playing, the ffmpeg process is still running until that file is all trans-coded.Example: If you have a 8Gb MKV and you start playing it, and after 5 seconds you stop it the hole file will be trans-coded and then the ffmpeg process will stop. (... it will take CPU clocks and you cannot stop it, so I open and stop a small file like a flv to fix this, most persons will not observe this but I got curios why my green led on the My Book Live having so much activity after stopping a movie)

WARNING !!!
Because of the CPU speed of the NAS when downloading with Transmission, you cannot start a movie on the TV because will work for 15 seconds after then the ffmpeg process will get less cpu clocks and will fail to trans-code real-time, this can be fixed by prioritizing the ffmpeg process problem is that I don't know how :)


Credits are all to the WEB !!!


2 comentarii: