[mythtv-users] file to flash

Eric Sharkey eric at lisaneric.org
Sun Oct 20 15:00:00 UTC 2013


On Sun, Oct 20, 2013 at 9:23 AM, Daryl McDonald <darylangela at gmail.com> wrote:
> I'm afraid you've given me more credit than is due. I've had a brief
> peek at your script, would modifying it be as simple as changing out
> one of your brand name products for one of mine?

Let me explain what it does, then I think the appropriate
modifications should be clear:

  #!/bin/sh

The first line says to use the standard Bourne shell /bin/sh.

  set -e;

This line says if any command in the script fails, the whole script should fail.

  echo $@ >> /tmp/videoexport.log

Append a copy of the arguments given to this script to the file
/tmp/videoexport.log.  This is just to aid debugging.

  OUTNAME="$3"

Set the variable OUTNAME equal to the third parameter (%STARTTIME%).

  if test -d /var/autofs/misc/innotab/LLN/MOVIE/ ; then

Test for the presence of a folder called
/var/autofs/misc/innotat/LLN/MOVIE/.  If this folder exists, execute
the following lines, otherwise jump down to the "elif" clause.  This
folder will only be found if a particular SD card has been inserted
into a card reader.  Specifically the one for my son's Innotab tablet.

      CONVERTER=/usr/local/bin/toinnotab.sh

Set the variable CONVERTER to the name of the script I use to prepare
video for an Innotab tablet.

      TARGET="/var/autofs/misc/innotab/LLN/MOVIE"

Set the TARGET variable to the name of the folder the video should be
placed in.  The Innotab is a very limited device.  All videos need to
go in one folder.

      OUTNAME="$2"

Change the variable OUTNAME to the second argument (%TITLE%).  Since
all the videos will be in the same folder, %STARTTIME% will not be a
good name.

  elif test -d /var/autofs/misc/centon/video/ ; then

Only if /var/autofs/misc/innotab/LLN/MOVIE/ was not found, then look
instead for /var/autofs/misc/centon/video/.  This folder will only
exist if I've plugged in a Centon media player.

      CONVERTER=/usr/local/bin/tomp4.sh

The Centon uses a different format than the Innotab, so this line sets
the CONVERTER variable to the name of a script that formats the video
for that player.

      TARGET="/var/autofs/misc/centon/video/$2"

This line sets the TARGET variable to the name of the folder the video
should be placed in.  Note that in this case, this player supports
folders in the video directory, so the second parameter (%TITLE%) is
used as a folder name, and the file name is left as the %STARTTIME%.

  elif test -d /var/autofs/misc/n900/mythtv/ ; then
      CONVERTER=/usr/local/bin/ton900mp4.sh
      TARGET="/var/autofs/misc/n900/mythtv/$2"
  elif test -d /var/autofs/misc/n97/Videos/ ; then
      CONVERTER=/usr/local/bin/ton97mp4.sh
      TARGET="/var/autofs/misc/n97/Videos/mythtv/$2"
  fi

These next seven lines follow the same pattern.  Test for the
existence of a folder, if found set TARGET and CONVERTER as the output
location and conversion script respectively.

  if test -z "${CONVERTER}" -o \! -x ${CONVERTER} ; then
      echo "Cannot run converter: ${CONVERTER}"
      exit 0
  fi

This block checks if the variable CONVERTER is zero length (-z) or if
the script it names is not (\!) present and executable (-x).  In this
case it prints and error message and exits.  That "exit 0" line really
should be "exit -1" or something like that.  I don't know why I wrote
exit 0.  If it was exit -1 it would be considered a failure and you
would see failure in the mythtv backend log.  Using exit 0 will show
success even if this script can't find a place to put the video.

  mkdir -p "$TARGET"

Make the TARGET folder if it doesn't already exist.

  cd "$TARGET"

Change directory to the TARGET folder.  This lets converter scripts
put the output in the current directory without needing to worry about
what that is.

  if test -n "$4" ; then
      OUTNAME="${OUTNAME} - $4"
  fi

Check if there was a fourth parameter given (%SUBTITLE%).  If it was,
expand the output filename to include the subtitle as well.

  SAFEOUTNAME=`echo "${OUTNAME}" | tr -c -d 'a-zA-Z0-9\040()~#!@$_-'`

Remove from the output name any characters that aren't a letter,
number, or a safe punctuation character.  The point of this is to
remove characters like ':' which can't safely exist on a FAT formated
file system.

  ${CONVERTER} "$1" "${SAFEOUTNAME}"

Finally execute the converter script, passing in the first parameter
(%DIR%/%FILE%) and the value of SAFEOUTNAME.  The job of the converter
script is to copy the video from its first argument to its second
argument, making any conversion necessary.  So, for example, my script
tomp4.sh is just:


#!/bin/sh
FILE=$1
TITLE=$2
mencoder ${FILE} -ovc xvid -oac twolame -ofps 15 -xvidencopts
bitrate=300:max_bframes=0:nogmc:noqpel -twolameopts br=64 -vf
harddup,kerndeint,scale=320:240,dsize=320:240 -af
resample=44100,volnorm=2 -o "${TITLE}.avi"


You need to modify the script to test for the folders where you want
the video to go and call an appropriate converter script.  Of course,
if you don't actually need to transcode, you can set CONVERTER=/bin/cp
and just have the file copied and everything should work.

This also works best if you've set up your automounter to
automatically mount your media in specific places.  For example in
/etc/auto.misc I have a line:

innotab         -fstype=vfat,gid=video,umask=002
:/dev/disk/by-id/usb-Generic-_SD_MMC_20060413092100000-0\:2-part1

It's this line which establishes the mapping of an SD card with a
given volume id with the folder /var/autofs.misc/innotab so that the
export script, simply by testing for the presence of this folder can
trigger the automounter to look for this device and mount it at that
location.

Does that clear things up?

Eric


More information about the mythtv-users mailing list