Archive for the 'Code Samples' Category

I use MediaCoder for most of my encoding/transcoding of video for playback on my PC and other devices. The N800 has a peculiar set of parameters for it’s video - if it doesn’t match up then it either won’t play back or will be very choppy.

I ended up selling the N800 but I thought I would pass this profile along to anyone who might use it.

<?xml version="1.0" encoding="UTF-8"?>
<MediaCoderPrefs>
  <node key="overall">
    <node key="generic">
      <node key="autoRevert">
        <value>Never</value>
      </node>
    </node>
    <node key="ui">
      <node key="optionTab">
        <value>3</value>
      </node>
      <node key="param">
        <value>1069,767,47,50</value>
      </node>
      <node key="noWelcome">
        <value>4068</value>
      </node>
    </node>
    <node key="task"/>
    <node key="output"/>
    <node key="tagging"/>
    <node key="subtitle"/>
    <node key="decoding"/>
    <node key="audio"/>
    <node key="video">
      <node key="format">
        <value>XviD</value>
      </node>
    </node>
    <node key="container">
      <node key="format">
        <value>AVI</value>
      </node>
    </node>
    <node key="mplayer"/>
    <node key="preview"/>
    <node key="plugin"/>
    <node key="presets"/>
    <node key="httpd"/>
    <node key="server"/>
  </node>
  <node key="audiosrc">
    <node key="mplayer"/>
    <node key="winamp"/>
    <node key="lame"/>
    <node key="wavefile"/>
  </node>
  <node key="audioenc">
    <node key="lame"/>
    <node key="vorbis"/>
    <node key="faac"/>
    <node key="aacplus"/>
    <node key="nero"/>
    <node key="helix"/>
    <node key="helixmp3"/>
    <node key="fraunhofer"/>
    <node key="speex"/>
    <node key="musepack"/>
    <node key="ffmpeg"/>
    <node key="aac3gpp"/>
    <node key="amr"/>
    <node key="wavpack"/>
    <node key="flac"/>
    <node key="ape"/>
    <node key="tta"/>
    <node key="als"/>
    <node key="ofr"/>
    <node key="pcm"/>
    <node key="cli"/>
  </node>
  <node key="videosrc">
    <node key="mplayer"/>
    <node key="avisynth"/>
  </node>
  <node key="videoenc">
    <node key="xvid"/>
    <node key="x264"/>
    <node key="mencoder"/>
    <node key="ffmpeg"/>
    <node key="theora"/>
    <node key="dirac"/>
    <node key="amv"/>
    <node key="vfw"/>
    <node key="dumper"/>
    <node key="wm"/>
    <node key="remote"/>
  </node>
  <node key="container">
    <node key="mp4box"/>
    <node key="matroska"/>
    <node key="mencoder"/>
    <node key="mp4creator"/>
    <node key="atom"/>
    <node key="pmp"/>
    <node key="vcd"/>
  </node>
  <node key="audiofilter">
    <node key="resample"/>
    <node key="equalizer"/>
    <node key="channels"/>
    <node key="volume"/>
    <node key="surround"/>
    <node key="compressor"/>
    <node key="delay"/>
    <node key="extraStereo"/>
    <node key="extra"/>
    <node key="shibatch"/>
  </node>
  <node key="videofilter">
    <node key="scale">
      <node key="enabled">
        <value>true</value>
      </node>
      <node key="width">
        <value>352</value>
      </node>
      <node key="height">
        <value>288</value>
      </node>
    </node>
    <node key="crop"/>
    <node key="expand"/>
    <node key="frame"/>
    <node key="eq"/>
    <node key="postproc"/>
    <node key="rotate"/>
    <node key="itf"/>
    <node key="denoise"/>
    <node key="unsharp"/>
    <node key="delogo"/>
    <node key="screenshot"/>
    <node key="thumb"/>
    <node key="extra"/>
  </node>
</MediaCoderPrefs>

You can also download the file here: N800.xml

I created this Bash script as a project for the system administration course I’m taking for the summer. I’m sure there are bugs in it, so let me know if you find any.

It basically uses an XML configuration file, which includes the source, destination, and any excludes from the transfer. You then pass either -u or -d (upload or download) and the options -x (delete if not in source) and -f (force). Destination can be local or remote, but source must be local.

Here is the code:

#!/bin/bash
## Transfer Script
## By David Drager
## CSC586: Summer II 2008
## Requires: xml2, rsync

## Settings
tempdir="/tmp/"
rsynccommand="/usr/bin/rsync"

## Usage command
usage="usage: transfer.sh [options] <config-file>.xmlnoptions:n  -d or -u:t download or upload, resp. one and only one must be presentn  -f:ttforce transfer regardless of 'newness' of filen  -x:ttdelete items in target not present in source"

# Check to make sure temporary directory exists
[ -d $tempdir ] || { echo -e "Error: Could not locate a temporary directory. See file settings."; exit 1; }

# Usage Command
[ $# -eq 0 ] && { echo -e "ERROR: Needs at least the -d or -u flag plus a config file.nn$usage"; exit 1; }

## Get options passed to the program
while getopts "dufx" flag
do
  [ "$flag" = "?" ] && echo -e "ERROR: Flag(s) not valid.nn$usage" && exit 1;
  eval "opt_$flag=1"
done
shift $((OPTIND-1))
configfile="$1"

if [ "$opt_d" = 1 ] && [ "$opt_u" = 1 ]
then
  echo -e "Error: Use either -u Upload or -d Download, but not bothn$usage"; exit 1;
elif  [ "$opt_u" = "" ] && [ "$opt_d" = "" ]
then
    echo -e "Error: Use either -u Upload or -d Download, but not bothn$usage"; exit 1;
fi

if [ "$opt_f" = 1 ]; then
  force=1
fi

if [ "$opt_x" = 1 ]; then
  deltar=1
fi

## Make sure config file is located
if [ "$configfile" != "" ]
then
  [ -f "$configfile" ] || { echo -e "Error: Config file not found.n$usage"; exit 1; }
else
   echo -e "Error: Config file not specified.n$usage"; exit 1;
fi

## End of swich verification

# echo Action: "$action"
# echo Force: "$force"
# echo Delete Target Files: "$deltar"
# echo Config: "$configfile"

## Now read config file

## Set temp file for XML parsing
tempfile="$tempdir"transferscript_$$
tempexcludes="$tempdir"transferscriptexcludes_$$
# echo -e "Temp:$tempfile"

# Run config file through xml2
xml2 < "$configfile" > "$tempfile"

[ -f "$tempfile" ] || { echo -e "There was a problem processing the XML file."; exit 1; }

# Make sure that source and destination are found
excludelist=""
while read line; do
    key=$(echo $line | awk -F '=' '{print $1}')
    value=$(echo $line | awk -F '=' '{print $2}')
    if [ "$key" = "/sync/@src" ]; then
      source="$value";
    elif [ "$key" = "/sync/@dst" ]; then
      destination="$value"
      # Add any exclude options to array
    elif [ "$key" = "/sync/exclude" ]; then
      tempexcl=("$value")
      excludelist=("${excludelist[@]}" "${tempexcl[@]}")
    fi
done < "$tempfile"

[ "$source" ] || { echo "Error: Config file must include a source"; exit 1; }
[ "$destination" ] || { echo "Error: Config file must include a destination"; exit 1; }

source="$source/"
destination="$destination/"

[ -d "$source" ] || { echo "Error: Source must be a local directory"; exit 1; }

excludes=""
excludes=${excludelist[@]}

# echo Excludes: "(${#excludelist[@]}): $excludes"

## Clean up temp file from xml process
rm "$tempfile"

## Build up the command line

[ -f "$rsynccommand" ] || { echo -e "Error: Could not locate rsync command."; exit 1; }

fullcommand="$rsynccommand"
fulltestcommand="$rsynccommand"

if [ "$opt_f" == "1" ]
then
    fulltestcommand="$fulltestcommand -nva"
    fullcommand="$fullcommand -a"
else
    fulltestcommand="$fulltestcommand -nvau"
    fullcommand="$fullcommand -au"
fi

if [ "$opt_u" == "1" ]
then
  fileorder="$source $destination"
  echo "Evaluating transfer from $source ==> $destination"
elif [ "$opt_d" == "1" ]
then
  fileorder="$destination $source"
  echo "Evaluating transfer from $destination ==> $source"
fi

[ "$opt_x" == "1" ] && { fulltestcommand="$fulltestcommand --delete"; fullcommand="$fullcommand --delete"; }

## Move exclude list to a file.
## This duplicates as above but I originally thought we were passing it to rsync as a list and not as a file.

[ "${#excludelist[@]}" -gt 0 ] && {
    tempfile="$tempdir"transferscript_$$
    touch "$tempfile"
    echo "$excludes" | tr " " "n" > "$tempfile"
    fulltestcommand="$fulltestcommand"" --exclude-from=$tempfile"
    fullcommand="$fullcommand"" --exclude-from=$tempfile"
}

fulltestcommand="$fulltestcommand $fileorder"
fullcommand="$fullcommand $fileorder"

# We only want lines minus top line and bottom 3 lines
testresult=`$fulltestcommand | tail --lines=+2 | head --lines=-3`

# If this is empty, then notify that no files would be transferred.
 [ "$testresult" ] || { echo "This command would not transfer any files. Script exiting."; rm "$tempfile"; exit 1; }

# Display changes
echo -e "Changes to be made:n--------------------n$testresultn--------------------"

# Check to see if we really want to run the command.
echo "Do you wish to perform this command? $fullcommand (y/n)[y]"
read confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "" ]
then
    echo "Performing transfer..."
    # Without -v this will not output anything.
    $fullcommand
    echo "Transfer complete."
    rm "$tempfile"
else
    echo "Cancelling transfer..."
    rm "$tempfile"
fi

exit 0

Here is the sample config file:

<sync src="/home/dir/bash-prog/dir1/" dst="login@some.machine:/home/dir/dir2">
        <exclude>
          .test3
          another.*
        </exclude>
</sync>

The AskApache blog has a great comprehensive guide to .htaccess. A must read for anyone who does a lot of work with Apache.

http://www.askapache.com/htaccess/apache-htaccess.html

Updated on 8/26/2008 with corrected information!

Window’s simple shutdown command works well, but has some major drawbacks. The major one is that it will only schedule a reboot up to 10 minutes into the future (600 seconds). Linux’s shutdown command makes this easy, just issue the command ’shutdown -r +60′ for example to reboot an hour in the future.

No such luck in Windows, you need to download a separate program to do this. It is a sysinternals program, you might remember sysinternals from such utilies like FileMon and ProcessMonitor.

The program we use for this is called PsTools and more specifically the file psshutdown.exe.

[Download PsTools here]

Place psshutdown.exe into a directory for future use, for this example we will use c:\tools\.

Easiest Method:

Type the following command into the command prompt:
c:\tools\psshutdown.exe -r -f -c -t 02:00 /accepteula

PSshutdown will respond with:

PsShutdown v2.52 - Shutdown, logoff and power manage local and remote systems
Copyright (C) 1999-2006 Mark Russinovich
Sysinternals - www.sysinternals.com

Local system is scheduled to reboot in 15:08:00.

If all goes will, Windows will reboot at 2:00am, or your specified time. This command will start a system service with the psstools scheduling program, PSSDNSVC.EXE.

Alternate Method:

Then open a command prompt and type the following command:

at 2:00am c:\tools\psshutdown.exe -r -f -c -t 10 /accepteula

This will result in:

Added a new job with ID = 1

You can verify this task has been added by looking at the Scheduled Tasks - the job name will be At1 if you haven’t scheduled any other tasks via the command line.

For some reason, Firefox started to display a blinking cursor, like web pages I have been viewing were editable. Thinking that some errant plugin was causing this behavior, I manically disabled a few I had recently installed. However that didn’t fix the problem.

Good ole Google to the rescue.

Firefox has a ‘feature’ that lets you select text with more visual feedback. I guess the little one must have been hitting keys and turned this on.

Turning it off is easy! Press F7 to turn off caret browsing.

Alternatively, type “about:config” in the URL area, then filter for “caret“. Change accessibility.browsewithcaret to “false”.

  • Welcome to systemBash, a technology and system administration blog by David Drager. If you enjoy this sort of content, can can subscribe to the RSS using the link to the right.