20 December, 2012

Applying Watermark With FFMpeg

Assuming you have a watermark png file 'watermarklogo.png' and a input file 'screenCap.mpg', you can apply a watermark in the upper right hand corner by running the following command:

$ ffmpeg -i screenCap.mpg -vf "movie=watermarklogo.png [watermark]; [in] [watermark] overlay=main_w-overlay_w-10:10 [out]" /var/tmp/foo.mpg
Cheers.

13 December, 2012

Getting UTC Time From Web

At work we suspect our embedded devices are susceptible to clock drift. To accurately assess, a 'true' clock is required. An alternative would be to use NTP on a local laptop, using the laptop time as 'true' time. The alternative is to access an atomic clock via web interface periodically and use it's value as the reference time. Done by repeating the URL navigation using curl, repeated by using the watch command.

$ watch -n 1 'curl http://tycho.usno.navy.mil/cgi-bin/timer.pl'
Grabbing the time and embedded time via Ethereal should achieve what we want. Cheers.

16 November, 2012

Screen Capture with FFMpeg with Audio

Found it useful to capture the Linux desktop using FFMpeg, most useful with audio. Accomplished it using the following command:

$ ffmpeg -y -f alsa -i pulse -f x11grab -r 25 -s 1366x768 -i :0.0 -qscale 1 -s 1024x768  screenCap.mpg
First dimension specified is the resolution of the desktop, the second dimension is the desired resized video dimension. Cheers.

09 November, 2012

Viewing WebCam Video with Mplayer

On a number of occasions I find it useful to view my laptop's camera in real-time using Mplayer. Seems this is accomplishable using the following command:

$ mplayer -fps 15 tv:// -tv  driver=v4l2:device=/dev/video0
Cheers.

08 September, 2012

Stress Testing Android Application Activity Start/Stop

One of the things I find before delivering Android applications is the impact of starting and stopping the application in a rapid manner. It's common that key stroke and touch handlers get invoked before all the necessary resources have been created, or after they have been released. Starting an application, followed by hitting the back button or home button can often result in calls to your application handlers or scheduled behavior after onStop() has been invoked. I find the following script assists in stress testing this form of behavior:

#!/bin/bash


for t in {0..5}; do
  for i in {0..10}; do
    adb -s emulator-5554 shell am start -a android.intent.action.MYAPPNAME -n com.abc.myappname/com.abc.myappname.MyAppName
    sleep $t
    adb shell input keyevent 3
    sleep 5
  done
done

The above script will repeatedly start the application, wait X seconds, then post the 'home' keyevent. If my app passes this test, and a series of monkey tests I'm pretty confident the users won't experience unexpected crashes. Cheers.

06 September, 2012

Customizing Views with Android

My wife, a software engineer as well, pointed out today that I've been making customizing views more difficult than they have to be.  While I've been customizing views, buttons, and the like for some time I've felt that I needed to dynamically create the objects because I didn't think you could specify them in the XML layout.  Fortunately, I was incorrect.

Consider extending the ImageView class, demonstrated in the following example;


package com.abc.customview;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.content.Context;
import android.util.AttributeSet;

class MyCanvasView extends ImageView {
        public MyCanvasView(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
        }

        public MyCanvasView(Context context, AttributeSet attrs) {
                super(context, attrs);
        }

        public MyCanvasView(Context context) {
                super(context);
        }
};

public class CustomView extends Activity
{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}
Normal XML layout would take the form;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello World, CustomView"
    />
  <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:tint="#00000000"
    android:layout_gravity="center"
    android:src="@drawable/background"
    android:layout_weight="85"/>
</LinearLayout>
Using the extended class requires replacing the "ImageView" class specifier to our extended sub-class using full package namespace;

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Hello World, CustomView"
    />
  <com.abc.customview.MyCanvasView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:tint="#00000000"
    android:layout_gravity="center"
    android:src="@drawable/background"
    android:layout_weight="85"/>
</LinearLayout>
Cheers.

28 July, 2012

Android Version Distributions

Came across this site, gives statistics of Android versions currently used:


30 April, 2012

Android Library Reuse

Well, it took me some time, but I finally uncover my original findings concerning creating an Android reuse library. Examples seem tough to come-by, so I'll post what I discovered. The overall objective is to define a reuse package that contains common source and resources. For the sake of this discussion, our reuse package will be defined as com.abc.lib, our sample project utilizing the library packaged as com.abc.sample01; First, let's create our reuse library project:

$ android create lib-project --name Lib --target 4 --path Lib --package com.abc.lib

Next, populate the source with library package contents:

$ mkdir -p Lib/src/com/abc/lib
$ cat LogUtils.java 
package com.abc.lib;

public class LogUtils {
  static public void Log (String msg) {
  }
}
$ cp ./LogUtils.java Lib/src/com/abc/lib

Building the library results in a JAR file located in bin.

/var/tmp/temp/Lib$ ant debug
Buildfile: /var/tmp/temp/Lib/build.xml

-set-mode-check:

-set-debug-files:

-set-debug-mode:

-debug-obfuscation-check:

-setup:
     [echo] Gathering info for Lib...
    [setup] Android SDK Tools Revision 16
    [setup] Project Target: Android 3.0
    [setup] API level: 11
    [setup] Project Type: Android Library
    [setup] 
    [setup] ------------------
    [setup] Resolving library dependencies:
    [setup] No library dependencies.
    [setup] 
    [setup] ------------------
    [setup] 
    [setup] WARNING: No minSdkVersion value set. Application will install on all Android versions.

-build-setup:
     [echo] Creating output directories if needed...
    [mkdir] Created dir: /var/tmp/temp/Lib/bin
    [mkdir] Created dir: /var/tmp/temp/Lib/bin/res
    [mkdir] Created dir: /var/tmp/temp/Lib/gen
    [mkdir] Created dir: /var/tmp/temp/Lib/bin/classes

-pre-build:

-code-gen:
     [echo] ----------
     [echo] Handling aidl files...
     [aidl] No AIDL files to compile.
     [echo] ----------
     [echo] Handling RenderScript files...
[renderscript] No RenderScript files to compile.
     [echo] ----------
     [echo] Handling Resources...
     [aapt] Generating resource IDs...

-pre-compile:

-compile:
    [javac] Compiling 2 source files to /var/tmp/temp/Lib/bin/classes
     [echo] Creating library output jar file...
      [jar] Building jar: /var/tmp/temp/Lib/bin/classes.jar

-post-compile:

-obfuscate:

-dex:
     [echo] Library project: do not convert bytecode...

-crunch:
   [crunch] Crunching PNG Files in source dir: /var/tmp/temp/Lib/res
   [crunch] To destination dir: /var/tmp/temp/Lib/bin/res
   [crunch] Crunched 0 PNG files to u
   [crunch] pdate cache

-package-resources:
     [echo] Library project: do not package resources...

-package:
     [echo] Library project: do not package apk...

-do-debug:
     [echo] Library project: do not create apk...

debug:
[propertyfile] Creating new property file: /var/tmp/temp/Lib/bin/build.prop
[propertyfile] Updating property file: /var/tmp/temp/Lib/bin/build.prop
[propertyfile] Updating property file: /var/tmp/temp/Lib/bin/build.prop
[propertyfile] Updating property file: /var/tmp/temp/Lib/bin/build.prop

BUILD SUCCESSFUL
Total time: 2 seconds
/var/tmp/temp/Lib$ 

The contents of the JAR file can confirm the existence of the LogUtils class.
/var/tmp/temp/Lib$ jar -tf ./bin/classes.jar 
META-INF/
META-INF/MANIFEST.MF
com/
com/abc/
com/abc/lib/
com/abc/lib/LogUtils.class
Next, let's create a project that will utilize the common reuse library.

$ android create project --package com.abc.sample01 --activity Sample01 --target 2 --path Sample01
We add the library dependency by specifying the relative path to the library.
$ android update project --target 4 --path Sample01 --library ../Lib
Finally, update the project to ensure it all takes affect.
$ android update project --path Sample01
Our sample activity can reference our common library components as follows;

/var/tmp/temp/Sample01$ cat src/com/abc/sample01/Sample01.java 
package com.abc.sample01;

import android.app.Activity;
import android.os.Bundle;
import com.abc.lib.LogUtils;

public class Sample01 extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        LogUtils.Log("hello");
    }
}

Building the sample project via 'ant debug' somewhat duplicates the resources and source in the referencing project.

Kinda rough post, but it hits most of the generals.

13 January, 2012

Unity -- Mouse Under Keyboard Focus

I've always preferred my focus to follow my mouse in my desktop preferences.

The recent push for the Unity desktop manager for Ubuntu, Debian...has prodded me to try it out.

One of my first challenges was enabling the focus to follow the mouse location. No simple way to do it via preferences, however:


$ gconftool-2 --type string --set /apps/metacity/general/focus_mode mouse
$ gconftool-2 --set /apps/metacity/general/auto_raise -t boolean false


That'll do it.