Mass Conversion of different video files with handbreak-CLI

Flattr this!

I am currently converting all my videos to a fixed format using handbrake. If you have a lot of videos to convert, the UI version of handbrake is not always the best solution. Handbrake offers a CLI, sometimes you it needs to be installed separately.

It has a lot of options ( ). So the best is to go with your preferred preset.
I want to encode all video files in a given folder to the preset “universal”.
So i wrote a short bash script, to to the work:

# Folder Setup

if [ ! -f $DONE_FOLDER  ] ; then mkdir -p $DONE_FOLDER; fi
if [ ! -f $OUT_FOLDER  ] ; then mkdir -p $OUT_FOLDER; fi

#All Extensions of the input files
EXTS=( mp4 flv )
#Find Handbrake CLI
HB=`which HandBrakeCLI`

for ext in ${EXTS[@]}; do
	echo "for $ext"
	for FILENAME in `ls $IN_FOLDER/*.$ext`; do
		#echo $FILENAME
		$HB -i $FILENAME  -o $OUT_FOLDER/`basename "$FILENAME" .$ext`.mp4  --preset="Universal"

Another use-case might the conversion of some videos to flv for a web playback (or the other way round flv->mp4 for playback on iOS Devices)

setup your public SSH key to another UNIX Host

Flattr this!

Normally you would prefer to use your public ssh key for login into a remote linux machine.
I created a script to perform the basic steps for inserting your public key into the hosts authorized_keys files.

The script looks like this:


echo ">> setup your ssh keys for $HOST"
echo ""
echo ">> creating ssh keys on $HOST if necessary"
echo "(you need to enter your password)"
echo ""
ssh $HOST 'if [ ! -d ~/.ssh  ] ; then ssh-keygen -t rsa; fi'
echo ""
PUBKEY=`cat ~/.ssh/`
echo "=========================================================="
echo "your"
echo "$PUBKEY"
echo "=========================================================="
echo ""
echo ">> transfering your public ssh key"
scp ~/.ssh/authorized_keys $HOST:~/.ssh/authorized_keys
ssh $HOST 'chmod 600 ~/.ssh/authorized_keys'
echo ""
echo ">> login with your public key"
echo "(should work without a password)"
ssh $HOST

A typical run might look like this:

imotep:~ philipp$ setupssh philipp@
>> setup your ssh keys for philipp@

>> creating ssh keys on philipp@ if necessary
(you need to enter your password)

The authenticity of host ' (' can't be established.
RSA key fingerprint is ...
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '' (RSA) to the list of known hosts.
philipp@'s password:
Enter file in which to save the key (/home/philipp/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Generating public/private rsa key pair.
Created directory '/home/philipp/.ssh'.
Your identification has been saved in /home/philipp/.ssh/id_rsa.
Your public key has been saved in /home/philipp/.ssh/
The key fingerprint is:
... philipp@debian
The key's randomart image is:
+--[ RSA 2048]----+
|...              |


>> transfering your public ssh key
philipp@'s password:
authorized_keys                                                                         100%  610     0.6KB/s   00:00    

>> login with your public key
(should work without a password)
Linux debian 2.6.26-2-amd64 #1 SMP Thu Nov 25 04:30:55 UTC 2010 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Jan 23 17:31:16 2011 from

Show Build-Information in your iOS App About Panel

Flattr this!

Sometimes it might be useful to have an exact piece of information about what version of an app you have currently running. Especially if you have a decent Testing-Group, it is important to track the versions in which a bug appears. The goal of this post is to achieve a info panel like this in your application.
You get the Application version (from the Application Bundle), the Repository Revision and the Date of the last Commit.

Picture 1: Example Application About Dialog


We are using here the build-in functions of subversion to update given keywords with the repository information. More about this topic here. There is also a way to use this method with git, but i did not test it yet. You may find out more about this here
The first step is to create a File-Template you can import in your code, with which you can access all the necessary details:

#define APP_VERSION   
[[[NSBundle mainBundle] infoDictionary]   
[[[NSBundle mainBundle] infoDictionary]   
#define APP_NAME   
[[[NSBundle mainBundle] infoDictionary]   
#define APP_BUILD_REVISION @"$Rev$"
#define APP_BUILD_DATE @"$Date$"
#define APP_LAST_AUTHOR @"$Author$"

Code 1: version.h template
The next step is to tell Subversion to replace the placeholder with the subversion values.
You can do this with setting the subversion keyword for that file.
After that, with every commit of the file “version.h” the values will be updated.

svn propset svn:keywords 'Revision Author Date' version.h

Code 2: version.h template
The very last step is to make sure, that “version.h” will be updated each time you make a change to your application. Assuming you build your app every time you made a change, you can use the functions, build into Xcode to force an update on “version.h”. We use the trick, that every change on the propsets of “version.h” is equal to a file modification itself.
So we create a small bash script, setting the propset “build” to a new value. After that, “version.h” needs to be commited as a new version.

svn propset build "$HOST $DATE" Version.h

Code 3:
Now we need to add the run of “” to our Build-Cycle. (Picture 2 & Picture 3).

Picture 2: Project Target Settings


Picture 3: Insert Script Call

After a successful commit, the file “version.h” will look something like this:

#define APP_VERSION   
[[[NSBundle mainBundle] infoDictionary]   
[[[NSBundle mainBundle] infoDictionary]   
#define APP_NAME   
[[[NSBundle mainBundle] infoDictionary]   
#define APP_BUILD_REVISION @"$Rev: 1047 $"
#define APP_BUILD_DATE @"$Date: 2011-01-21 18:53:38 +0100 (Fri, 21 Jan 2011) $"
#define APP_LAST_AUTHOR @"$Author: phaus $"

Code 4: updated version.h
You might modify the output (e.g. filter out the $s or reformat the date) to get a more stylish output.

Using UIAutomation for Multilanguage iOS Applications

Flattr this!

With the appearance of iOS 4.0 Apple introduced a new Test-Framework for automatically UI Testing: UI Automation. Based on Javascript and build-in into Instruments, UI Automation is a very useful tool during the Developing of iOS Application.
A very good introduction in UIAutomation is here and here.
During the development of a iOS Application, we decided to port it to iOS 4.0 and therefor use also UIAutomation for regression testing (before that we used GHUnit Tests for Component Testing – but thats another story).
As we are primarily a company dealing with web-based application, we had almost zero afford to deal with the Javascript syntax of UI Automation. But we had to deal with the fact, that we developing a dual language Application (de and en), and therefore need a possibility to test the whole UI in both languages.
If you are familiar with UI Automation, you probably know that the Framework uses the accessibility labels of your UI and also often Button Labels. So you have to deal with the actual language of the current UI Setting. But wait. There is already a valid mapping of different language to a given key. If you internationalize your application you will use so called Localizable.strings to do your language Mapping (more here).
So we just need a way to move our already existing Mapping into our UI Automation world. UI Automation supports the import of separate JavaScript Files to use your own Libraries and Settings. So i build a conversation script to translate your different Localizable.strings to JavaScript and moving all languages into one big collection.
So for example a String like this:

    "Library" = "Bibliothek";
    "Shop" = "Kiosk";

Will be converted to:

UIA.Localizables = {
        "Library" : "Bibliothek",
        "Shop" : "Kiosk",

The next step is to determine during your UIAutomation Test which language Setting you need to Load from your Localization File.
It is possible to readout some System Settings during an UIAutomation Test. The basic functions to find your current language and to read the correct language Array look like this:

UIA.getCurrentLang = function(){
    if(application.preferencesValueForKey("AppleLanguages")[0]  == "en")
        return "English";
        return application.preferencesValueForKey("AppleLanguages")[0];
UIA.getCurrentLocalizables = function(){
    return UIA.Localizables[UIA.getCurrentLang()];
var Localizable = UIA.getCurrentLocalizables();

The first function is necessary to capture a quirk of the recent Xcode Versions (some people calling it a bug 🙂 ).
So now we can just use our String within our Test-Cases.

#import "lib/Localizables.js"
function delay(seconds){
function tapTab(name){
    var window = UIATarget.localTarget().frontMostApp().mainWindow();
var window = UIATarget.localTarget().frontMostApp().mainWindow();

I attached the conversion script to this post.
You just need to alter the source and destination folders of your i18n files and the UIAutomation-Tests directory.
Download file