dts2ac3 revisited

Following up from this thread, there’s currently some error passing the output from dcadec to aften via shell pipe.

error allocating read buffer
Invalid count passed to aften_encode_frame
Error encoding frame 0

So been looking at an alternative to that method. And for what it’s worth, ffmpeg can do that too, even in one step.

# ffmpeg -i tmp.dts -acodec ac3 -ac 6 -ab 448k tmp.ac3 

So below is version 0.2 of the script, now depending on ffmpeg instead of dcadec and aften.

#!/usr/bin/perl
# 0.1 - dcadec, aften for dts2ac3
# 0.2 - ffmpeg for dts2ac3
# usage: cd into your working directory, put all sub directories containing mkv's with dts track to encode to ac3 over there and run it
use warnings;
use strict;
use File::Basename;

my $FFMPEG="/usr/bin/ffmpeg";
my $MKVMERGE="/usr/bin/mkvmerge";
my $MKVEXTRACT="/usr/bin/mkvextract";

my $TMP_DTS="tmp.dts";
my $TMP_AC3="tmp.ac3";
my $PATTERN_DTS="A_DTS";
my $PATTERN_AC3="A_AC3";

sub dts2ac3 {
        my ($dts, $ac3) = @_;
        `$FFMPEG -i $dts -acodec ac3 -ac 6 -ab 448k $ac3`;
}
sub info {
        my ($mkv) = @_;
        return `$MKVMERGE -i $mkv`;
}
sub demux {
        my ($mkv, $id) = @_;
        `$MKVEXTRACT tracks $mkv $id:$TMP_DTS`;
}
sub mux {
        my ($mkv, $new, $ac3) = @_;
        #remove all tracks with -A, only add new
        `$MKVMERGE -A -o $new $mkv $ac3`;
}
sub clean {
        # delete 1.dts, 1.ac3, old mkv
        my ($dts, $ac3, $old) = @_;
        system("rm -f $dts");
        system("rm -f $ac3");
        system("rm -f $old");
}
my $pwd=`pwd`;
print "Processing all matches in $pwd...nn";
my @dirs=<*>;
my $dir;
my @files;
my $file;
my @buf;
my $line;
my $id;
my $name;
my $ext=".mkv";;
my $output;

foreach $dir (@dirs) {
        chdir $dir;
        @files=<*>;
        foreach $file (@files) {
                if($file=~m/mkv/i) {
                        $id=-1;
                        # 1. get dts track id from info
                        @buf=info($file);
                        foreach $line (@buf) {
                                if($line=~m/$PATTERN_DTS/i) {
                                        $line=~m/(d+)/;
                                        $id = $1;
                                        # only the first
                                        print "found first match for DTS.n";
                                        last;
                                }
                                if($line=~m/$PATTERN_AC3/i) {
                                        print "AC3 track found.n";
                                }
                        }
                        next if($id<0);
                        # 2. demux dts track
                        print "Demuxing DTS track from $file...n";
                        demux($file,$id);
                        # 3. encode dts to ac3
                        print "Encoding DTS to AC3...n";
                        dts2ac3($TMP_DTS,$TMP_AC3);
                        # 4. parse old name, create new
                        if($file=~m/dts/i){
                                $output=$file;
                                $output=~s/DTS/AC3/g;
                                $output=~s/dts/AC3/g;
                        } else {
                                ($name, undef, $ext) = fileparse($file,qr".mkv");
                                $output="$name.AC3$ext";
                        }
                        # 5. mux
                        print "Creating new output with AC3 in $output...n";
                        mux($file, $output, $TMP_AC3);
                        # 6. clean
                        print "Deleting temp files and old mkv...n";
                        clean($TMP_DTS, $TMP_AC3, $file);
                        # 7. info
                        print info($output);
                }
        }
        chdir "../";
}

customize ssh user shell on thecus n4200pro

I’m using a variety of custom modules for my thecus nas n4200pro. The best thing is that most modules are compatible with the n5500 series, so taking those and installing on the n4200pro works in most cases.

First, install SYSUSER and SSHD module on the nas, and change the “sys” password immediately.

The default settings by this module will be adding a new user “sys” with home “/root/” and shell used “/bin/sh”. This is basically not what we want in the first place, so open

# vi /app/etc/passwd

and change the line looking like this

sys:x:0:0::/raid/data:/bin/bash

Then exit and relogin.

Now it’s time to customize our profile using .bash*

# echo "source ~/.bashrc" >> /raid/data/.bash_profile
# vi /raid/data/.bash_logout

# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi
# vi /raid/data/.bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# don't overwrite GNU Midnight Commander's setting of `ignorespace'.
HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$ '
else
    PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="[e]0;${debian_chroot:+($debian_chroot)}u@h: wa]$PS1"
        ;;
    *)
        ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    #alias grep='grep --color=auto'
    #alias fgrep='fgrep --color=auto'
    #alias egrep='egrep --color=auto'
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

# COLOR PROMPTS FOR FOUI - FAST OPTICAL USER IDENTIFICATION
# =========================================================
if [ `/usr/bin/whoami` = 'root' ]
then
export XFOUND_ROOT_USER='YES'
    # Do not set PS1 for dumb terminals
    if [ "$TERM" != 'dumb'  ] && [ -n "$BASH" ]
    then
         export PS1='[33[01;31m]h [33[01;34m]w $ [33[00m]'
    fi
else
export XFOUND_NORMAL_USER='YES'
    # Do not set PS1 for dumb terminals
    if [ "$TERM" != 'dumb'  ] && [ -n "$BASH" ]
    then
         export PS1='[33[01;32m]u@h [33[01;34m]w $ [33[00m]'
    fi
fi

To verify that your settings are not overwritten you should reboot the nas once.

visualize icinga git with gource

install the following pre-requisites:

add debian multimedia repo – http://debian-multimedia.org

$ sudo apt-get install x264 ffmpeg gource

make sure you’ll get the latest on all projects:

$ cd ~/icinga/gource
$ git clone git://git.icinga.org/icinga-core.git
$ git clone git://git.icinga.org/icinga-doc.git
$ git clone git://git.icinga.org/icinga-api.git
$ git clone git://git.icinga.org/icinga-web.git
$ cd icinga-core

optional: if you want to use gravatars, fetch that perl script and run it. it will place fetched avatars in .git/avatar which can be used in below’s example. if you are omitting this, remove the param in the commands below.

$ perl grab_avatars.pl

for each project, we need to get the git log from the past year (or similar period)

 $ git log --pretty=format:user:%aN%n%at --reverse --raw --encoding=UTF-8 --no-renames --since="1 year ago" > git.log

1 second per day should be enough speed (-s 1). 720p for youtube is also good 🙂

$ gource --path git.log --user-image-dir .git/avatar/ -s 1 --auto-skip-seconds 0.1 --file-idle-time 50 --max-files 500 --multi-sampling -1280x720 --stop-at-end --elasticity 0.1 -b 000000 --disable-progress --user-friction .2 --disable-bloom --output-ppm-stream - | ffmpeg -an -threads 4 -y -vb 4000000 -aspect 16:9 -r 60  -f image2pipe -vcodec ppm -i - -vcodec libx264 -vpre slow gource.mp4

take the gource.mp4 and upload to wherever you want.

Encode DTS tracks in mkv's to AC3 with dts2ac3

Following up to this thread I got lazy pasting those commands by hand.

So I finally wrote another Perl script doing all the demux-encode-mux stuff alone, also taking all sub directories, parsing for DTS encoded tracks within the mkv’s. It also creates a new output file with a fine AC3 track, and removes the old file with the DTS track. Note: This currently works only with single audio tracks, and ignores non-DTS files. And it is being written for directory usage, meaning one working dir and sub dirs with mkvs.

The script has several dependencies on used software, as there are

  • mkvmerge
  • mkvextract
  • dcadec
  • aften

Resolve them like this:

# apt-get install mkvtoolnix mkvtoolnix-gui libdca0 libdca-utils cmake
# cd /usr/src; wget wget http://downloads.sourceforge.net/project/aften/aften/0.0.8/aften-0.0.8.tar.bz2; tar xvjf aften-0.0.8.tar.bz2
# cd aften-0.0.8; mkdir default; cd default
# cmake .. -DCMAKE_INSTALL_PREFIX:STRING="/usr"; make && make install

Current script can be found here at pastebin 🙂

dnla portforwarding with wrt320n

In order to get DLNA back to work through a client bridged setup, simply add 1900 and 8200 to “NAT/QoS” -> “Portforwarding” and add your client IP address, mapping 1900 -> IP:1900 and 8200 -> IP:8200

So the DLNA client in the other subnet believes that the router is hosting the DNLA server and everything is fine again 🙂