Extra Pepperoni

To content | To menu | To search

Tuesday, June 29 2010

The NYC Taxi & Limousine Commision is selling us to advertisers

Last week and this week I took taxis. For a few years now, NYC taxis have had screens aimed at the back seats. After an annoying advertisement for the TLC, the OFF button shows up.

But now after tapping OFF, rather than just showing a relatively static ad for the people who make the screens, they instead flips back 'ON' to show TV-style advertising. This week I got to watch a stabbing and an ad for a fight channel. This means I cannot even sit normally in the cab without seeing advertising. Even if I sit at an uncomfortable angle to avoid staring at the screen, the sound is still on.

This makes me want to keep our daughter out of taxis -- and myself too!

Here's the complaint I sent the TLC Commissioner (they direct all complaints to the 311 switchboard, which doesn't have access to accept complaints about the TLC itself).

The seat-back monitors did not shut off before, and now they turn themselves back on after OFF is touched.

It's incredibly aggravating to be a captive audience for advertising. This is worse because the sound turns on. Today I had to watch one black man stab another, and see ads for a fighting channel. Last week, despite looking away from the screen, I was still stuck listening to ads.

This is awful.

Monday, December 22 2008

boxee

After a mention by Kevin van Haaren, I decided to try boxee, a multiplatform open source media sharing project. Specifically, I was interested in running boxee on our Apple TV, and pointing it at a share on a Linux server, since the Apple TV's 160gb hard drive is perpetually full, and I spend a significant amount of time moving video on and off via iTunes. Additionally, boxee adds support for additional video formats, and facilitates access to Internet content such as hulu and RSS video feeds (ONN FTW, although I was already getting that through iTunes).

atvusb-creator

My first problem was some confusion in the atvusb-creator, which builds a "patchstick" by copying the appropriate files onto a flash drive. Booting an Apple TV from the patchstick adds boxee to the existing Apple TV software, and provides additional menu items and ssh access.

I was distracted by the bright blue Choose a DMG button. In Mac OS X, blue buttons are supposed to identify the default action, so I kept trying to find a suitable .dmg file to feed it, with no luck. I saw a few warnings that the creator only works with some flash drives, so thought mine were incompatible. After I watched a video on creating the patchstick, I realized this button was a herring -- it is apparently unneeded. Once I skipped straight to Create Using ->, I got a patchstick. Hooray!


Today, I got Boxee installed. It was pretty simple:

  1. Pull the plug.
  2. Plug the patchstick into the back.
  3. Turn on the Apple TV.

I watched Linux boot messages, then saw a message telling me no errors were detected, and to reboot the Apple TV. When it came back, I had 2 extra menu items: XBMC/Boxee & Software Menu. The former includes a (highly recommended) Update command (but after updating I am still offered the same set of updates), a Boxee command which gives me an inescapable black screen, and an XBMC command that lets me configure and use up the Xbox Media Center (which Boxee is built upon). Unfortunately, XBMC doesn't see the videos, music, & photos iTunes synched over, so there's no content yet.

Ah, well. That's progress, at least.

Thursday, December 11 2008

hb.sh (HandBrake Wrapper) Updated for v0.9.3

As threatened, I have an update for my HandBrake wrapper script. On a Mac or Linux system, the script examines one or more DVD folders (I rip mine with MacTheRipper), and converts the DVD MPEG2 content to MP4 files suitable for Apple TV (by default) or iPhone (with an iphone argument, e.g., hb.sh iphone). It's easy to hack up for different preferences, and will require changing some variables to match your preferred media folder layout. Thanks to Brian Beardmore for the original GPL script.

The required customizations are these two lines:

inputSearchDir="$HOME/tivo-inspector/input/$mySuffix"
outputDir="$HOME/tivo-inspector/output"

The main difference in v1.0.7 of the script is that it uses HandBrake 0.9.3's new improved presets, rather than hard-coding my custom settings. I've found the new presets give excellent quality in considerably less time.

If you have trouble compiling the Linux CLI, see my earlier post about v0.9.3 (I didn't try the GUI).

You can download hb.sh v1.0.7 (recommended), or copy & paste, but might have to fix line wrapping & remove blog cruft if you do.


#!/bin/bash

# hb.sh uses HandBrakeCLI to convert whole DVDs automatically.
# Copyright (C) 2007  Brian Beardmore
# Copyright (C) 2008  Chris Pepper

#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# This script requires HandBrakeCLI <http://handbrake.fr/>.

# This script searches the entire input directory directory tree looking
# for TS_VIDEO directories looking for DVDs to encode.  The output mp4
# filename is the DVD volume name.  When multiple tracks are to encoded 
# from a DVD, the output filename is appended with the track number.
# For example, 'Monsters, Inc.' DVD has both standard and wide screen tracks
# so there are 'Monsters, Inc.1.mp4' & 'Monsters, Inc.10.mp4' files created.
# For addition information on this script contact the script's original author,
# Brian Beardmore at medfk(at)realisticsoftware(dot)com or
# http://www.realisticsoftware.com
# Or contact Chris Pepper <http://www.extrapepperoni.com/category/television/>.

# Examples
# $ ./appletv.sh
#   [ encodes all DVDs mounted and encodes any tracks longer than 60min ]
#   [ to the mp4 folder in the users Movies folder ]
# $ appletv.sh -i ~/Movies -o toPod -b 1000 -w 576 --minGetTime 50
#   [ encodes all DVDs found in the users Movies folder and encodes any ]
#   [ tracks longer than 50min, with a 1000kb/s bitrate and scales the output ]
#   [ movie to a width of 576 pixels and puts the resulting mp4 files in the ]
#   [ toPod folder in the current directory that the command was executed from ]

# Syntax: HandBrakeCLI [options] -i <device> -o <file>
# 
# ### General Handbrake Options------------------------------------------------
# 
#     -h, --help              Print help
#     -u, --update            Check for updates and exit
#     -v, --verbose <#>       Be verbose (optional argument: logging level)
#     -C, --cpu               Set CPU count (default: autodetected)
#     -Z. --preset <string>   Use a built-in preset. Capitalization matters, and
#                             if the preset name has spaces, surround it with
#                             double quotation marks
#     -z, --preset-list       See a list of available built-in presets
# 
# ### Source Options-----------------------------------------------------------
# 
#     -i, --input <string>    Set input device
#     -t, --title <number>    Select a title to encode (0 to scan only,
#                             default: 1)
#     -L, --longest           Select the longest title
#     -c, --chapters <string> Select chapters (e.g. "1-3" for chapters
#                             1 to 3, or "3" for chapter 3 only,
#                             default: all chapters)
# 
# ### Destination Options------------------------------------------------------
# 
#     -o, --output <string>   Set output file name
#     -f, --format <string>   Set output format (avi/mp4/ogm/mkv, default:
#                             autodetected from file name)
#     -m, --markers           Add chapter markers (mp4 and mkv output formats only)
#     -4, --large-file        Use 64-bit mp4 files that can hold more than
#                             4 GB. Note: Breaks iPod, PS3 compatibility.
#     -O, --optimize          Optimize mp4 files for HTTP streaming
#     -I, --ipod-atom         Mark mp4 files so 5.5G iPods will accept them
# 
# ### Video Options------------------------------------------------------------
# 
#     -e, --encoder <string>  Set video library encoder (ffmpeg,xvid,
#                             x264,theora default: ffmpeg)
#     -x, --x264opts <string> Specify advanced x264 options in the
#                             same style as mencoder:
#                             option1=value1:option2=value2
#     -q, --quality <float>   Set video quality (0.0..1.0)
#     -Q, --cqp               Use with -q for CQP instead of CRF
#     -S, --size <MB>         Set target size
#     -b, --vb <kb/s>         Set video bitrate (default: 1000)
#     -2, --two-pass          Use two-pass mode
#     -T, --turbo             When using 2-pass use the turbo options
#                             on the first pass to improve speed
#                             (only works with x264, affects PSNR by about 0.05dB,
#                             and increases first pass speed two to four times)
#     -r, --rate              Set video framerate (5/10/12/15/23.976/24/25/29.97)
#                             Be aware that not specifying a framerate lets
#                             HandBrake preserve a source's time stamps,
#                             potentially creating variable framerate video
# 
# ### Audio Options-----------------------------------------------------------
# 
#     -a, --audio <string>    Select audio track(s), separated by commas
#                             More than one output track can be used for one
#                             input.
#                             ("none" for no audio, "1,2,3" for multiple
#                              tracks, default: first one)
#     -E, --aencoder <string> Audio encoder(s) (faac/lame/vorbis/ac3) 
#                             ac3 meaning passthrough
#                             Separated by commas for more than one audio track.
#                             (default: guessed)
#     -B, --ab <kb/s>         Set audio bitrate(s)  (default: 160)
#                             Separated by commas for more than one audio track.
#     -6, --mixdown <string>  Format(s) for surround sound downmixing
#                             Separated by commas for more than one audio track.
#                             (mono/stereo/dpl1/dpl2/6ch, default: dpl2)
#     -R, --arate             Set audio samplerate(s) (22.05/24/32/44.1/48 kHz)
#                             Separated by commas for more than one audio track.
#     -D, --drc <float>       Apply extra dynamic range compression to the audio,
#                             making soft sounds louder. Range is 1.0 to 4.0
#                             (too loud), with 1.5 - 2.5 being a useful range.
#                             Separated by commas for more than one audio track.
#     -A, --aname <string>    Audio track name(s),
#                             Separated by commas for more than one audio track.
# 
# ### Picture Settings---------------------------------------------------------
# 
#     -w, --width <number>    Set picture width
#     -l, --height <number>   Set picture height
#         --crop <T:B:L:R>    Set cropping values (default: autocrop)
#     -Y, --maxHeight <#>     Set maximum height
#     -X, --maxWidth <#>      Set maximum width
#     -p, --pixelratio        Store pixel aspect ratio in video stream
#     -P, --loosePixelratio   Store pixel aspect ratio with specified width
#           <MOD:PARX:PARY>   Takes as optional arguments what number you want
#                             the dimensions to divide cleanly by (default 16)
#                             and the pixel ratio to use (default autodetected)
#     -M  --color-matrix      Set the color space signaled by the output
#           <601 or 709>      (Bt.601 is mostly for SD content, Bt.709 for HD,
#                              default: set by resolution)
# 
# ### Filters---------------------------------------------------------
# 
#     -d, --deinterlace       Deinterlace video with yadif/mcdeint filter
#           <YM:FD:MM:QP>     (default 0:-1:-1:1)
#            or
#           <fast/slow/slower>
#     -5, --decomb            Selectively deinterlaces when it detects combing
#           <MO:ME:MT:ST:BT:BX:BY>     (default: 1:2:6:9:80:16:16)
#     -9, --detelecine        Detelecine (ivtc) video with pullup filter
#                             Note: this filter drops duplicate frames to
#                             restore the pre-telecine framerate, unless you
#                             specify a constant framerate (--rate 29.97)
#           <L:R:T:B:SB:MP>   (default 1:1:4:4:0:0)
#     -8, --denoise           Denoise video with hqdn3d filter
#           <SL:SC:TL:TC>     (default 4:3:6:4.5)
#            or
#           <weak/medium/strong>
#     -7, --deblock           Deblock video with pp7 filter
#           <QP:M>            (default 5:2)
#     -g, --grayscale         Grayscale encoding
# 
# ### Subtitle Options------------------------------------------------------------
# 
#     -s, --subtitle <number> Select subtitle (default: none)
#     -U, --subtitle-scan     Scan for subtitles in an extra 1st pass, and choose
#                             the one that's only used 10 percent of the time
#                             or less. This should locate subtitles for short
#                             foreign language segments. Best used in conjunction
#                             with --subtitle-forced.
#     -F, --subtitle-forced   Only display subtitles from the selected stream if
#                             the subtitle has the forced flag set. May be used in
#                             conjunction with --subtitle-scan to auto-select
#                             a stream if it contains forced subtitles.
#     -N, --native-language   Select subtitles with this language if it does not
#           <string>          match the Audio language. Provide the language's
#                             iso639-2 code (fre, eng, spa, dut, et cetera)

# Revision history:
# 1.0.7, 2008/12 -- Update for HandBrake 0.9.3, and use presets.
# 1.0.6 -- never released.
# 1.0.5, 2008/08 -- Require bash, per ebb.
# 1.0.4, 2008/06 -- Use different suffices so different flavors can coexist.
# 1.0.3, 2008/05 -- Add basic argument processing, so "appletv" and "iphone" as argument #1 produce different output.
# 1.0.2, 2008/05 -- hacks by Pepper to use HandBrakeCLI and optimize for AppleTV.
# 1.0.1, 2008/02/24 -- hacks by Pepper to use HandBrakeCLI and optimize for iPhone.
# 0.20070329.0 - initial release


#############################################################################
# globals

# const global variables
scriptName=`basename "$0"`
scriptVers="1.0.7"
scriptPID=$$
saveDVDinfo=1       # the DVD track info is also saved as .txt file when set
skipDuplicates=1    # if this option is off, overwrite existing files
E_BADARGS=65

if [[ $# = 0 ]]
 then
  myArgs='$HANDBRAKE_ARGS -Z AppleTV'
elif [[ $1 = "appletv" ]]
 then
  myArgs='$HANDBRAKE_ARGS -Z AppleTV'
  mySuffix=AppleTV
elif [[ $1 = "AppleTV" ]]
 then
  myArgs='$HANDBRAKE_ARGS -Z AppleTV'
  mySuffix=AppleTV
elif [[ $1 = "iphone" ]]
 then
  myArgs='$HANDBRAKE_ARGS -Z "iPhone & iPod Touch"'
  mySuffix=iPhone
elif [[ $1 = "iPhone" ]]
 then
  myArgs='$HANDBRAKE_ARGS -Z "iPhone & iPod Touch"'
  mySuffix=iPhone
else
 echo "Unknown format -- aborting!"
 exit 1
fi

# set the global variables to defaults
toolName="HandBrakeCLI"
toolPath="$HOME/bin/$toolName"
toolTrackArgs="-t 0"
toolArgs="-v"
inputSearchDir="$HOME/tivo-inspector/input/$mySuffix"
outputDir="$HOME/tivo-inspector/output"
minTrackTime="3"    # in minutes


# Pepper's sometime options:
# -s 1 # first subtitle
# -a 2 # second audio track ??
# For example (best within screen): HANDBRAKE_ARGS="-s1 -t11" iphone.sh


#############################################################################
# functions

parseProcessInArgs()
{
    if [ -z "$1" ]; then
        return
    fi

    toolArgs=""

    while [ ! -z "$1" ]
    do
        case "$1" in
            -h) displayUsageExit ;;
            --help) displayUsageExit ;;
            -i) inputSearchDir=$2
                shift ;;
            --input) inputSearchDir=$2
                shift ;;
            -o) outputDir=$2
                shift ;;
            --output) outputDir=$2
                shift ;;
            --minGetTime) minTrackTime=$2
                shift ;;
            *) toolArgs="$toolArgs $1" ;;
        esac

        shift
    done
}

verifyFindCLTool()
{
    # attempt to find the HandBrakeCLI if the script toolPath is not good
    if [ ! -x "$toolPath" ];
    then
        toolPathTMP=`PATH=.:/Applications:/:/usr/bin:/usr/local/bin:$HOME:$PATH which $toolName | sed '/^[^\/]/d' | sed 's/\S//g'`

        if [ ! -z $toolPathTMP ]; then 
            toolPath=$toolPathTMP
        fi
    fi  
}

displayUsageExit()
{
    echo "Usage: $scriptName [options]"
    echo ""
    echo "    -h, --help              Print help"
    echo "    -i, --input <string>    Set input directory to process all DVDs in it (default: /Volumes/)"
    echo "    -o, --output <string>   Set output directory for all output files (default: ~/Movies/mp4/)"
    echo "    --minGetTime <number>   Set the minimum time (mins) of the track/s to encode (default: 60)"

    if [ -x "$toolPath" ];
    then
        echo "   $toolName possible options"
        hBrakeHelp=`$toolPath --help 2>&1`
        hBrakeHelpPt=`printf "$hBrakeHelp" | egrep -v '( --input| --output| --help|Syntax: |^$)'`
        printf "$hBrakeHelpPt\n"
    else
        echo "    The options available to HandBrakeCLI except -o  and -i"
        if [ -e "$toolPath" ];
        then
            echo "    ERROR: $toolName command tool is not set up to execute"
            echo "    ERROR: attempting to use tool at $toolPath"
        else
            echo "    ERROR: $toolName command tool could not be found"
            echo "    ERROR: $toolName can be installed in ./ /usr/local/bin/ /usr/bin/ ~/ or /Applications/"
        fi
    fi

    echo ""

    exit $E_BADARGS
}

getTrackListLongerThan()
{
    # Two input arguments are are need. 
    #   arg1 is the time in minutes selector
    #   arg2 is the raw text stream from the track 0 call to HandBrake
    #   returns: a list of track numbers of tracks longer than the selector

    if [ $# -lt 2 ]; then
        return ""
    fi

    minTime="$1"
    shift
    allTrackText="$*"
    aReturn=""

    trackList=`eval "echo \"$allTrackText\" | egrep '(^\+ title |\+ duration\:)' | sed -e 's/^[^+]*+ //'g -e 's/title \([0-9]*\):/\1-/'g -e 's/duration: //'g"`

    trackNumber=""
    for aline in $trackList
    do
        trackLineFlag=`echo $aline | sed 's/[0-9]*-$/-/'`
        if [ $trackLineFlag = "-" ];
        then
            trackNumber=`echo $aline | sed 's/\([0-9]*\)-/\1/'`
        else
            set -- `echo $aline | sed -e 's/(^[:0-9])//g' -e 's/:/ /g'`
            if [ $3 -gt 29 ];
            then let trackTime=($1*60)+$2+1
            else let trackTime=($1*60)+$2
            fi

            if [ $trackTime -gt $minTime ];
            then aReturn="$aReturn $trackNumber"
            fi
        fi
    done

    echo "$aReturn"
}

makeFullPath()
{
    aReturn=""
    currentPath=`pwd`

    if [ $# -gt 0 ]; then
        inPath="$*"

        # put full path in front of path if needed
        aReturn=`echo "$inPath" | sed -e "s!~!$currentPath/!" -e "s!^./!$currentPath/!" -e "s!^\([^/]\)!$currentPath/\1!" -e "s!^../!$currentPath/../!"`

        # remove ../ from path - only goes 4 deep
        aReturn=`echo "$aReturn" | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g' | sed -e 's!/[^\.^/]*/\.\./!/!g'`

        # cleanup by removing //
        aReturn=`echo "$aReturn" | sed -e 's!//!/!g'`
    fi

    echo "$aReturn"
}

isPIDRunning()
{
    aResult=0

    if [ $# -gt 0 ]; then
        txtResult="`ps ax | egrep \"^[ \t]*$1\" | sed -e 's/.*/1/'`"
        if [ -z "$txtResult" ];
        then aResult=0
        else aResult=1
        fi
    fi

    echo $aResult
}

#############################################################################
# MAIN SCRIPT

# initialization functions
verifyFindCLTool
parseProcessInArgs $*
# see if the output directory needs to be created
if [ ! -e $outputDir ]; then
    mkdir -p "$outputDir"
fi

# sanity checks
if [[ ! -x $toolPath || ! -d $inputSearchDir || ! -d $outputDir || -z "$toolArgs" ]]
 then

  if [[ ! -x $toolPath ]]
   then echo "ERROR: $toolPath is not executable!"
  fi
  if [[ ! -d $inputSearchDir ]]
   then echo "ERROR: $inputSearchDir is not a valid input directory!"
  fi
  if [[ ! -d $outputDir ]]
   then echo "ERROR: $outputDir is not a valid output directory!"
  fi
  if [[ ! -z "$toolArgs" ]]
   then echo "ERROR: $toolArgs is unset!"
  fi

    displayUsageExit
fi

# fix input and output paths to be full paths
inputSearchDir=`makeFullPath $inputSearchDir`
outputDir=`makeFullPath $outputDir`

# display the basic setup information
echo "$scriptName v$scriptVers"
echo "  Start: `date`"
echo "  Input directory: $inputSearchDir"
echo "  Output directory: $outputDir"
echo "  Minimum get track time: $minTrackTime mins"
echo "  Tool path: $toolPath"
echo "  Tool args: $toolArgs"
echo "  My args: $myArgs"
echo "  - - - - - - - - - - - - - - - -"

# find all the DVD videos in the input search directory tree
# spaces in file path temporarily become /008 and paths are separated with spaces
dvdTSVidList=`find $inputSearchDir -name VIDEO_TS -print0 | tr ' ' '\007' | tr '\000' ' '`

# process each DVD video found
for dvdTSDir in $dvdTSVidList
do
    # correct the tmp char back to spaces in the DVD file paths
    dvdTSDir=`echo $dvdTSDir | tr '\007' ' '`

    # get the DVD's name and path to root of the DVD
    dvdVolPath=`dirname "$dvdTSDir"`
    dvdName=`basename "$dvdVolPath"`
    dvdNameALNUM=`basename "$dvdVolPath" | sed 's/[^[:alnum:]^-^_]//g'`

    # display information
    echo "  * Processing DVD '$dvdName'"

    # create tmp link to the dvdVolPath to workaround a problem that
    # the HandBrakeCLI tool has a problem with spaces in the input
    # file paths in a script
    tmpNoSpacePath="/tmp/dvdVol-$dvdNameALNUM-$scriptPID"
    ln -s "$dvdVolPath" $tmpNoSpacePath

    # get the track list information from the DVD
    cmd="$toolPath -i $tmpNoSpacePath $toolTrackArgs /dev/null 2>&1"
    dvdTrackInfo=`eval $cmd`
    # save the DVD info
    outputFilePath="$outputDir/${dvdName}.txt"
    if [ $saveDVDinfo -eq 1 ]; then
        if [[ ! -e  $outputFilePath || skipDuplicates -eq 0 ]]; then
            echo "$dvdTrackInfo" | egrep '[ \t]*\+' > "$outputFilePath"
        fi
    fi
    # get the track number of tracks which are longer then the time desired
    trackFetchList=`getTrackListLongerThan $minTrackTime "$dvdTrackInfo"`
    if [ ! -z "$trackFetchList" ];
    then
        echo "   Will encode the following tracks: `echo $trackFetchList | sed 's/ /, /g'` "
    else
        echo "   No tracks on this DVD are longer than the minimum track time setting"
    fi

    trackCount=`echo $trackFetchList | wc -w`
    for aTrack in $trackFetchList
    do
        if [ $trackCount -gt 1 ]
            then outputFilePath="$outputDir/${dvdName}-${aTrack}.$mySuffix.m4v"
            else outputFilePath="$outputDir/${dvdName}.$mySuffix.m4v"
        # .m4v is important for AppleTV
        fi
        cmd="$toolPath $myArgs -i $tmpNoSpacePath $toolArgs -t $aTrack -o \"$outputFilePath\" > /tmp/${dvdNameALNUM}Results.txt 2>&1"

        if [[ ! -e  $outputFilePath || skipDuplicates -eq 0 ]];
        then
            # simple command execution
            #ripResult=`eval $cmd`

            # background command execution with some status

            echo "Command is: $cmd"

            eval $cmd &
            cmdPID=$!
            while [ `isPIDRunning $cmdPID` -eq 1 ]; do
                cmdStatusTxt="`tail -n 1 /tmp/${dvdNameALNUM}Results.txt | grep 'Encoding: '`"
                if [ ! -z "$cmdStatusTxt" ]; then
                    echo -n "$cmdStatusTxt"
                fi
                sleep 1s
            done
            echo ""
            wait $cmdPID

        else
            echo "   Output file SKIPPED because it ALREADY EXISTS"
        fi

        if [ -e /tmp/${dvdNameALNUM}Results.txt ]; then
            rm /tmp/${dvdNameALNUM}Results.txt
        fi
    done

    rm $tmpNoSpacePath
done

echo "  - - - - - - - - - - - - - - - -"
echo "  End: `date`"

exit 0

Wednesday, November 26 2008

HandBrake v0.9.3

HandBrake 0.9.3 is out, with many improvements. Unfortunately, the Linux binary is now built for Ubuntu. The Linux build instructions are a bit sparse. I needed jam & yasm RPMs from http://rpmfind.net/ I didn't find the list of HandBrake's Linux dependencies until later.

Note: In v0.9.3, make drives both configure & jam. jam drives wget, and my .wgetrc was somehow preventing the downloads from actually working (user-agent rejected by http://download.m0k.org/?):

pepper@inspector:~$ cat wgetrc.disabled 
reject = gif,txt
noclobber = on
robots = off
tries = 2
user-agent = Mozilla/4.77 (Macintosh; U; PPC)
#background = on
#recursive = on
quiet = on

Additionally, CentOS was missing the unversioned libbz2.so (arguably a bug), so I needed a symlink: "cd /usr/local/lib ; ln -s /usr/lib64/libbz2.so.1 libbz2.so". Reported to CentOS, since I haven't verified it on Red Hat, but I'm sure it's the same.

Tips for HandBrake debugging, and seeking help.

This got me HandBrakeCLI (I don't care about the Linux GUI -- I use the Mac GUI; and only do batch processing on Linux). Now to reconvert a few things!

PS-See also my hacked HandBrake wrapper script -- I expect to post an update which uses the new presets after I've tested a bit.

Thursday, May 22 2008

Nicer Batch Encoding with HandBrake

A while ago I posted a script for driving HandBrakeCLI. But it was lame that I had two not-quite-identical versions of the script -- one for iPhone output and another for Apple TV. At a guess, Brian Beardmore only needed one type. Now that we watch movies on the Apple TV and I watch on the iPhone, it was silly to have two different scripts. So I added simple argument processing.

hb.sh v1.0.3

If there first argument is iphone, then hb.sh optimizes for iPhone. If the argument is appletv or there are no arguments, hb.sh optimizes for Apple TV. It's very easy to tweak or add your own types -- just look for myArgs in the script and add or adjust as desired. I run this script on my Linux server, which has lots of disk space and is generally idle.


On my MacBook Pro, I have a couple aliases to facilitate things. I copy DVD folders to ~/tivo/tivo-inspector/input and run one of these. When done, the script opens up ~/tivo/tivo-inspector/. I move the DVD folders out of input and the processed .m4v video out of output; then I drop the .m4v files onto iTunes' LIBRARY area (so it doesn't stop whatever it's currently playing) and check iPhone videos to sync to the iPhone (the Apple TV has plenty of space, so everything syncs to it). Note that these lines may be too wide to display properly in WordPress -- just Copy and Paste, and you'll get the full text.

alias hbatv="ssh -t inspectore time screen bin/hb.sh appletv; open ~/tivo/tivo-inspector"
alias hbip="ssh  -t inspectore time screen bin/hb.sh iphone;  open ~/tivo/tivo-inspector"

Note that inspectore is the name of my Linux server. This would work just as well with HandBrakeCLI on a Mac "server" -- or even Windows, if you set it up to accept remote commands (CygWin, anyone?).


Reminder: You must adjust the inputSearchDir and outputDir paths for the running HandBrakeCLI.

pepper@inspector:~$ egrep tivo bin/hb.sh
inputSearchDir="$HOME/tivo-inspector/input"
outputDir="$HOME/tivo-inspector/output"

In the future version I'd like to support for arbitrary HandBrakeCLI arguments on the hb.sh command line, but I first have to see if HandBrakeCLI can handle gracefully conflicting arguments from built-ins and the command line.

Thursday, May 8 2008

Batch Encoding with HandBrake

I use Handbrake to rip DVDs for my iPhone and Apple TV (and previously for my Treo 650, at much lower quality). It's excellent, but takes a long time, and slows down the whole system while compressing. My PowerBook G4 wasn't powerful enough to do H.264 compression in reasonable time, so I got into the habit of ripping the DVDs on the Mac with Mac The Ripper, copying them to the server, converting on the server, and copying back down to the iPhone through iTunes on the laptop. Transferring a full DVD via gigabit Ethernet takes under 10 minutes, which is why we have 3 1/2 gigabit Ethernet switches (8-port, a pair of 5-ports, and the 3 ports built into the Time Capsule) in a 3 1/2 person (2 grown-ups, a 5-year-old, and the cat) home.

Since then I've upgraded the laptop and replaced the server, so they're now both 2.4GHz Core Duos, but I still prefer to avoid the load on my personal machine -- especially now that we have an Apple TV, which likes large high-quality video files. The MacBook Pro runs HandBrake.app (Mac GUI), while the server runs HandBrakeCLI (Linux).

HandBrakeCLI is designed to convert individual files and is awkward for converting whole DVDs. Fortunately I found MediaForkCLI-batch.sh, a wrapper which is good at converting all the real titles from one or more DVDs; it automatically ignores short titles such as previews, and titles that have already been transcoded. Unfortunately MediaForkCLI-batch.sh is languishing, and hasn't been updated for HandBrake v0.92, but it was straightforward to update it to the new syntax.

In the process I made some changes and added an alternate version with different settings optimized for our Apple TV. On the Linux box (named inspector), the scripts are ~/bin/appletv.sh & ~/bin/iphone.sh. I put newly ripped files into ~/tivo-inspector/input/ on inspector, and these scripts rip whatever they find there, generating files in ~/tivo-inspector/output/.

On the MacBook Pro, I keep video files in ~/tivo, and ~/tivo/tivo-inspector is a symbolic link to tivo-inspector on inspector, the server -- mounted via AFP. This makes it easy to move files back and forth.

For convenience, I have a couple aliases on the MacBook Pro which log into the Linux machine, start a screen session, and run the appropriate script. This means that if I disconnect the laptop, I can later ssh back into the server and use screen -DR to reconnect to my running conversion session. When the conversion is done, the aliases open the remote folder in the Finder. I move the files back up out of input & output, drop them onto iTunes, and then either Sync the Apple TV (which gets copies of my whole iTunes Library), or sync them to the iPhone.

The scripts are appletv.sh & iphone.sh.

If you use these scripts, you should carefully review the encoding settings. In particular, I encode Apple TV audio to AAC stereo, because our Apple TV is connected to a pair of stereo speakers with a subwoofer; they cannot handle Dolby Pro Logic, which is better for most TVs.

You will also have to update paths in the scripts -- to the input and output directories, and to HandBrakeCLI itself -- to make them work on your own system.


Here are the aliases in sh/bash format; change the equal signs to spaces for csh/tcsh:

alias appletv="ssh -t inspectore time screen bin/appletv.sh; open ~/tivo/tivo-inspector"
alias  iphone="ssh -t inspectore time screen bin/iphone.sh;  open ~/tivo/tivo-inspector"

Time Warner HD DVR Kicked to the Curb; Replaced by Apple TV

Our (cheap) 23" LCD TV's composite input gives lousy color. On the other hand, we've gotten loud buzzing noises a few times from its HDMI input, so we had our Time Warner (Scientific Atlanta) HD DVR connected to the composite inputs, and dealt with the lousy color and poor brightness. We also paid an additional $20.10/month for the second cable connection and DVR (Time Warner charges $9.95/month more for either HD or non-HD DVR than for a non-DVR cable box [HD or non-HD]). Now I wonder if the problem was with the DVR's HDMI output all along. Oh, well -- it no longer matters.

We do still pay $66.19/month for digital cable service upstairs. This lets Julia watch a couple kids' shows a day, and Annette & Amy check the Weather Channel. Our (pre-paid) TiVo also records the shows we like, so we can watch upstairs, but we generally watch downstairs. Neither of us knows if we'll watch more upstairs, or pay a few dollars a month to watch downstairs. It's an experiment.

Since we watch most of our "TV" from (ripped) DVDs, and our Time Warner signal is very unreliable, and their service is lousy, I returned the DVR on Saturday. That $20.10/month should pay for a Netflix upgrade and/or several shows from the iTunes Store (no longer the "iTunes Music Store", I noticed -- I wondered how long that would take, but missed the actual switch).

Good candidates for iTunes ducats -- (certain to total less the $241.20/year we'd been paying for the downstairs DVR):

  • $10: 16 consecutive episodes (4 weeks) of The Daily Show ($2/ea) -- we watch it infrequently these days.
  • $20: a season of South Park.
  • $26: a Torchwood season.
  • Doctor Who isn't available from iTunes, but we can watch it in VLC or upstairs, on cable.
  • free: Battlestar Galactica (on cable, upstairs)
  • free: The Sarah Jane Adventures (upstairs)
  • free: Robot Chicken (downloaded and watched on a laptop)

The TiVo S2 has a built-in web server, and I use tivodecode to extract MPEG video, but it won't play in QuickTime Player. They do play in the redoubtable VLC, but it's not quite as polished. This is not presently annoying enough to justify purchase of Toast, which can convert .TiVo files for QuickTime or iPhone, but I am not sure if DRM would be a problem; they don't provide any detail.

We haven't yet purchased anything through (or for) the Apple TV yet -- perhaps this week we'll try it.

Saturday, May 3 2008

Apple TV in the House

We got an Apple TV this week, and it's excellent, although I tripped over some serious network problems (more Mac problems than Apple TV problems, actually).

Compared to our TiVo (upstairs) or our Time Warner Scientific Atlanta HD DVR, the Apple TV is surpringly advanced. The SA box keeps losing signal (probably TWC's wiring at fault, but they keep not fixing it), and is much larger (and noisier) than the Apple TV; basically it's a piece of junk, but it's substantially cheaper than another TiVo. We'll probably get rid of this DVR and our downstairs cable connection in favor of the Apple TV very soon.

Comparing the Apple TV to the TiVo is more interesting, not least because people have been comparing the two companies for years, and keep demanding that Apple build a TiVo killer (both before and after the Apple TV release). Given how badly cable companies stink, it's hard to believe Apple should embroil themselves in this mess, but they seem to be doing okay with the iPhone, and phone companies aren't much better than cable companies. People also want Apple TVs to play DVDs, which is an obvious feature, but would be less profitable for Apple than iTunes Store rentals and purchases. But back to the comparisons.

The SA DVR has exactly one advantage over the TiVo (aside from price): its "Ouija board" -- when you need to "type" with a very limited keyboard, the TiVo makes it possible but not easy. The SA box improves the experience dimming (and skipping over) invalid letters (which would spell words that don't match the list of available shows). The Apple TV, interestingly, has an unimpressive on-screen keyboard and a very limited remote (it's the same one Macs ship with, meaning 6 buttons: 4 directions, play/pause, and menu/back). But it's easier to use, because the Apple TV doesn't lag behind user input as much (it doesn't have to match input against all possible titles, remember), and tactile response is very good; I only made one typo when entering usernames of several friends, and it was easy to correct, even though Delete is an onscreen selection (no Clear key, as on the TiVo remote).

This brings us to another interesting comparison: the SA box has Internet connectivity (I think it's channel 996 that shows the current IP), but doesn't use it for anything except the electronic program guide and purchasing pay-per-view (which we don't do). The TiVo adds TiVo-to-TiVo transfers of shows (we only have one, so haven't tried it), scheduling via http://www.tivo.com/tco/, an unsupported web server which allows downloading encrypted/watermarked television shows, and the ability to run applications from a server (either at home or across the Internet). Applications allow you to play music or slide shows from a Mac or Windows PC, or slide shows (from your Picasa or Yahoo Pictures account -- but not Flickr, even though Yahoo owns Flickr!). Unfortunately, you cannot combine these applications, so it's impossible to listen to music while watching a slide show on the TiVo. TiVo has apparently dropped support for third-party development.

The Apple TV, on the other hand, does this all much better. Out of the box, it comes with a set of high-quality flower photos, which run as a slide show when idle. Music can be a) played from the Apple TV's hard drive, b) streamed from iTunes on a Mac or PC (controlled from the Apple TV), or c) streamed from within iTunes in AirTunes+ mode -- iTunes sends audio and ID3-style metadata including cover art over the network to the Apple TV. In any of these modes, track information is displayed onscreen, and if the Apple TV is left idle, the it starts showing a slide show (ours is photos of Julia, of course); this doesn't interfere with music playback at all.

Compared to TiVo's lousy support for Yahoo Photos (!?!) and Picasa (they want you to create your own account and log into it before downloading any photos), the Apple TV supports Flickr and .Mac photos, as well as the owner's own via iTunes, of course. There is a clear hierarchy of user experience here: no support on SA/TWC; poor slide shows or mediocre media streaming on TiVo; high-quality music and photos on the Apple TV, pre-loaded with nice photos for a superior out-of-box experience.

One of the few things I regret about the Apple TV is that I bought it from Apple; I didn't get an educational or corporate discount, so I could have gotten it faster for $15 less from Amazon (via Prime), but when I tried to cancel the order at store.apple.com it had already gone through (less than 5 minutes after pressing Submit). This should be the worst problem I have with the new gadget!

Unfortunately, it wasn't. The Apple TV would not synchronize content from iTunes; I was able to play music through it (AirTunes), but it mostly refused to show up in iTunes' DEVICES list. I got a warning about port 3689 possibly being blocked by a firewall, which I initially ignored, knowing I had specifically allowed iTunes to connect through Leopard's "socket firewall".

The Apple TV AppleTV is not responding. Check that any firewall software running on this computer has been set to allow communication on port 3689.

pepper@prowler:~$ grep 3689 /etc/services 
daap            3689/udp    # Digital Audio Access Protocol
daap            3689/tcp    # Digital Audio Access Protocol

The second time I got this message, with iTunes' Preferences claiming the Apple TV was synching even while it wasn't fully accessible, I did some searching, and found out that indeed several people needed to open up the socket firewall before Apple TV synching would work. I did this, and lo and behold, our Apple TV now has the proper 12gb of video, 51gb of audio, and 3gb of photos it should. It's bad that iTunes wasn't properly whitelisted in the firewall, but it's much worse that people need to turn off a security feature to make the Apple TV work. Fortunately, after I switched the firewall back to "Set access for specific services and applications" (where it should be), the Apple TV continued to appear and synch properly; bug filed with Apple.

That brings up another bug: we have a Gigabit Ethernet network (3.5 switches -- 8-port, a couple 5-port, and the 3-port built into our Time Capsule) and an 802.11n network, but unfortunately the wireless doesn't work right. At 5GHz, I keep losing my connection; at 2.4GHz it stays up everywhere except the guest room (which has no Ethernet), but speeds throughout the apartment are poor and connectivity is less reliable than our 802.11g Airport Extreme network. Since I haven't fixed this yet, I much prefer to do large transfers over the wired network.

The Apple TV connects to a running copy of iTunes to download content; in my case, most of the connections (once I got past the firewall issue) were to the AirPort IP address, which prevented them from making progress on the 65gb transfer. I had to disable AirPort to force the Apple TV over to the Ethernet connection, which was much faster; after it was done I re-enabled AirPort, but that's another bug (also reported, and yes, I do have System Preferences set to prefer Ethernet to AirPort).

Sunday, March 30 2008

TiVo S2 in the house

Our original TiVo (hacked with web & FTP servers, 100mbps Ethernet, and 120gb hard drive) started showing a scrambled image; this has happened three times in the past, each time requiring drive replacement. The process is sufficiently awkward that when I put in the current 120gb drive, I decided to replace the TiVo entirely next time, rather than the drive -- with a MythTV or something else.

After TiVo's current promo, a TiVo Series 2 Dual Tuner (80gb) cost $80, which is entirely reasonable. I've been watching mostly ripped DVDs on the iPhone lately, so I was less worried about the fact that S2 and later TiVos encrypt the media files on disk, and were significantly harder to hack.

After installing the new TiVo, we discovered the problem is actually our Time Warner Cable signal again. They're supposed to be here this week, and hopefully will be able to fix our problem, although we don't have much confidence. They scramble the analog signal, thus breaking the new TiVo's signature feature (dual tuners -- the second one supports unencrypted analog cable, if we had it).

As it turns out, the new TiVo is a bit faster and much easier to download from; and onscreen UI is more capable and prettier. Unfortunately, it's also crowded with junk (unwanted features) we cannot remove, but they're easy enough to skip over and don't impact the normal TV-watching experience. I've downloaded and watched a bunch of music videos, which is nice since MTV doesn't show music videos any more.

Oh, and getting MPEGs out of the TiVo seems easier too -- tyc was problematic, but tivodecode works, so long as I watch in VLC instead of QuickTime Player (which only shows the first frame, while playing back all the audio).

Monday, June 25 2007

Time-Warner Redux (Redumb)

Time-Warner Cable was here again today. They have called at least half a dozen times since their last visit in May, twice to confirm appointments we hadn't made, several times during dinner to schedule appointments (the last time he was unable to actually schedule the appointment, though, as his computer wasn't working), and consistently failed to make promised follow-up calls.

Today they just showed up and buzzed, without the automated appointment-confirmation call yesterday -- fortunately we were around. When they arrived, we couldn't get channels 3, 6, 8, or 10 on either TV.

They ran new wire from Song (next door) over the building and back down, separating us from a neighbor who was apparently on the same coax. When they left, our upstairs (non-HD) TV & TiVo seemed fine, but our downstairs TV was still showing video artifacts and occasionally buzzing loudly, although we were at least getting picture on all channels. Apparently the run is so long they need an amplifier, but didn't have one. So tomorrow someone should be back to install an amplifier (supposed to take 10 minutes), which should fix our downstairs reception. We'll see if this also raises the signal:noise threshold, which the phone rep I spoke to said was a hard rule, but both field technicians have said was meaningless.

Saturday, May 19 2007

Time Warner Cable: 2 Thumbs down

We had a couple Time Warner DVRs. One Scientific Atlanta 8000 (non-HD) DVR upstairs on a Sony CRT (mostly watched by Julia these days), and an Scientific Atlanta 8300 HD DVR on our (lemon) Sceptre 23" 720p LCD TV.

They crash periodically, and Time Warner tells us just to reboot them and not worry about it. They are both inferior in numerous ways to our TiVo Series 1 (which is TiVo's original model -- so much for learning from the competition!). In early April, they both started failing to tune channels, and crashing a lot. We called Time Warner, they sent someone out, he "replaced a splitter" and left. A few days later we had more problems, so a second tech came out, "replaced a splitter" and yelled at Amy about a cabling problem to the TV (nothing to do with the issue, but it apparently caused him to waste some time). He left, but the problems stayed. In particular, a couple days later we got channel 1, but not 2-9 or 81 -- I didn't check beyond that.

Last week, I called Time Warner. The nice lady on the phone told me about channel 996, which provides status info on the DVR (including MAC, IP, and signal strength). She explained that my 33 "Reverse RF" (upstream?) dBmV (signal:noise) value was out of tolerance (35-65), and this was definitely the problem. So she sent someone on Tuesday to fix it. She also said "I'll put that number in the case notes, so they won't have any choice but to fix it." Foreshadowing! She also mentioned that since this was the third call they were supposed to send a foreman, but they did not.

Tired of not being able to get video onto my TiVo, I also asked to have our non-HD DVR replaced with a plain (digital) cable box, so I could reinstall our old TiVo S1. The TiVo has an upgraded hard drive, 10/100 Ethernet, and web server; so I can extract TV shows, convert to MPEG, and watch them on my Treo (it makes my 2-hour-daily subway commute go much faster). Unfortunately, this wasn't something that could be scheduled with the repair, so it was set for Thursday, at a $30 charge (it would have cost me $10 each way to get a cab to their storefront). Weak!

Tuesday, the repair tech came, disconnected a splitter (the same one that had been replaced by each of the previous techs, I presume, but he wouldn't say), and (with me) climbed up to the roof tracing out the cable. We then went into Song next door (the cable comes up from their yard, but it's behind a fence -- awkward! He re-crimped a few cable ends.

I asked about the signal strength (now up to 37 instead of 33, but still obviously not very good on either TV). The HD DVR crashed "tuning" to channel 7 (the 5th time Tuesday), so he replaced it (which I was expecting). He insisted that the signal:noise number was meaningless (several times), and we got all the channels, so he left. A half-hour later, Amy was tuning through the channels, and some weren't coming in again. At least the new DVR didn't crash on bad channels, just showed black. Talk about lowered expectations!

Oh, and the phone rep (when I scheduled the appointments) had promised me a credit for a month of interrupted service, but instead we got a bill for the full monthly rate. Amy called and the rep mumbled something about billing cycles, but the bill was dated several days after I was told the credit had been applied. Something to worry about next month...

Tuesday night we got a call from a Time Warner, asking if we were satisfied. NO Could they send a tech during the Thursday window, when I would be home? No. The TWC rep would call back, because he couldn't get a foreman that soon. We'll see how (if) they handle it. We currently have some channels, but not others.

It's enough to make us want to switch to RCN or DirecTV.

The pathetic irony here is that our problems have been a walk in the park compared to Alex's tale of woe. He spent months helping TWC figure out why their CableCards didn't work, but they didn't have any good ones to give him, so left him with incompatible CableCards. Last we heard, he thought they might have been fixed remotely, but wasn't willing to reboot to test this theory.

PS-An oddity is that downloding tystreams from the TiVo is slower than it used to be -- long pauses when nothing downloads, and generally just slower than it should be. I thought it was due to being uplinked through an AirPort Extreme via WDS, but connecting my PBG4 directly to the TiVo via an old 100mbps hub didn't help; something with the ancient TiVo, I guess.


Update: Our phone service was screwed up Wednesday. After several calls with Verizon (where they told us it was an inside problem, and that we should get a new phone, and that they would come Monday to fix it, but expected to charge us $90 to fix an inside wiring problem), someone showed up unexpected Friday morning and replaced an outside cable. Aside from the unpleasant similarities between Verizon and Time Warner, I'm convinced that the TWC repair tech caused the phone problem when he was tracing the coax up and down the outside of our building.

Wednesday, March 22 2006

Welcome back, Doctor Who!

Thanks to Sci Fi for bringing the new Doctor Who series across the Atlantic.

Wednesday, January 18 2006

Hacked TiVo

  • It's on its 3rd hard drive (this one is 120gb, but I was unable to find 5400rpm).
  • It has a 100mbit Ethernet TurboNet card (previously I had an old-skool 10mbit TiVoNet card).
  • It is accessible (on our private home network) via telnet, tivoftp (normal Linux filesystems, not MFS filesystems), and HTTP (TiVoWeb 1.0, with MFSStream v.98).

We watch all our TV on the PowerBook (TiVo2Go only supports Windows as of January 18th, 2005). Unfortunately there are several issues with sucking video off the TiVo onto a PowerBook. TiVo tools seem to be most advanced on Windows, where there are several slick tools for decoding, transcoding, and streaming. Next is Linux, and least-advanced are the Mac OS X tools.

I use MFSStream (a plug-in for TiVoWeb 1.0) to download .ty files through Safari, and tyc (which usually works, but not always) to strip the extra TiVo data and convert them to MPEG2, viewable in QuickTime (with the MPEG2 plug-in) or VLC. I'd like to upgrade to TiVoWeb 1.2.1, but haven't found a compatible MFSStream module.

Unfortunately, MFSStream generates bogus content-length headers for recordings over 2gb (feature movies). Both curl (latest version, from fink)