LinHES Forums
http://forum.linhes.org/

Interim stream live tv script
http://forum.linhes.org/viewtopic.php?f=6&t=9523
Page 1 of 1

Author:  elgordo123 [ Fri Apr 07, 2006 12:35 pm ]
Post subject:  Interim stream live tv script

I've been hacking away at getting mythweb streamlivetv working, but am having problems on the very last page generates the files. I am taking a break from it, but am almost there.
In the interim I created a script that you can use. I run it from my /home/mythtv directory. You will just need to ssh in and run the script, which prompts you for the settings you want. Ctrl-C in the ssh window to kill the stream. There is a section for presets too.
It is based on my setup, 2 PVR250's both being fed by dishnetwork receivers. The first receiver is controlled via an IR blaster. Someone with more knowledge than I will have to modify it to change the channel on the tuner itself. (Mine always remain on channel 3). You also have to add the --freq.. tags to the vlc script.
I am fairly new at bash scripts so dont flame me if it isn't right. It works for me. I used part of Chris Menards parseTunerStatus to display the tuner's status and display when the next recording is coming up.

Code:
 #mythtv: cat live.sh
#!/bin/bash
clear
echo

### Taken from parseTunerStatus of mythstreamtvLive scripts #################
MYTH_WEB_STATUS=http://192.168.0.3:8081/mythweb/status
#Note if using mythweb security, enter your name/pwd like this:
#MYTH_WEB_STATUS=http://user:pwd@192.168.0.3:8081/mythweb/status

# Figure out if tuner has a recording scheduled and when - add message to ddl
FindNextSchedule()
{
   PARM=${1}
   DEVICE=${2}

   TUNER=`echo ${PARM} | awk '{ print $1, $2}'`
   ScheduleBegin=`grep -n "The next 10 shows" ${STATUS} | cut -f1 -d:`
   NEXTTIME=`tail +${ScheduleBegin} ${STATUS} | \
              grep " - ${TUNER} - " | \
              head -1 | cut -f2 -d\> | cut -f1 -d- `
   
   if [ -z "${NEXTTIME}" ]
    then
    #echo "<option value=\"${DEVICE}\" selected=\"SELECTED\">$LINE - No scheduled recordings</option>"
    echo "\$LINE - No scheduled recordings."
    else
    #echo "<option value=\"${DEVICE}\" selected=\"SELECTED\">$LINE - Next recording at ${NEXTTIME}</option>"
    echo "\"$LINE - Next recording at ${NEXTTIME}."
    fi 
}

#----------------------------------------------------------------------------
# Main Routine
#----------------------------------------------------------------------------
cd /tmp

# get the HTML status page
wget ${MYTH_WEB_STATUS} 2> /tmp/wget.error
STATUS=/tmp/status

# grab local Encoder status lines
EncoderStatusBegin=`grep -n "Encoder status" ${STATUS} | cut -f1 -d:`

tail +${EncoderStatusBegin} ${STATUS} | head -5 | \
              egrep "^[    ]*Encoder.*local" > /tmp/tunerstatus

# Clean up the the status text
cat /tmp/tunerstatus | awk '/not recording/ {print $1, $2, "- Free"}
                            /is recording/ {print $1, $2, "- Recording"}' > /tmp/tnrsts.terse

# Now loop through each tuner and create ddl entry
while read  LINE
do
   TUNER_NUM=`echo ${LINE} | awk '{ print $2}'`
   DEVICE="/dev/video$((${TUNER_NUM}-1))"

   if [ ! -z "`echo $LINE | grep Recording`" ]
   then
      # if recording - just ues 'cleaned up' terse text
      echo "<option value=\"${DEVICE}\">$LINE</option>"
   else
      # if not recording, figure out next scheduled recording for tuner
      FindNextSchedule "${LINE}" "${DEVICE}"
   fi
       
done < /tmp/tnrsts.terse

# cleanup
rm -f /tmptnrsts.terse  /tmp/tunerstatus /tmp/status
########## END parseTunerStats ##################################

##########  Prompt for variables ###################
# Set variables to 0 to validate presets
VSPEED=0
ASPEED=0
VSIZE=0
VSIZE2=0
FPS=0

echo
echo "Use Encoder 1 or 2?"
read DEVICE
  if [ $DEVICE == "1" ]; then
      DEV='/dev/video0'
      echo "Channel?"    #These 4 lines for ext. chan chng script
      read CHAN
      echo "Changing to Channel: "$CHAN
      change_channel $CHAN
  elif [ $DEVICE == "2" ]; then
      DEV='/dev/video1'
  fi
echo

############ Add Presets here #################
echo "Use Presets for work or ppc (work,ppc,n)?"
read vPRESET
  if [ $vPRESET == "work" ]; then
    VSPEED='300'
    ASPEED='48'
    VSIZE='75'
    VSIZE2='.75'
    FPS='25'
  elif [ $vPRESET == "ppc" ]; then
    VSPEED='256'
    ASPEED='48'
    VSIZE='50'
    VSIZE2='.50'
    FPS='20'
  fi
echo

if [ $VSPEED == "0" ]; then
echo "Video Speed (500,300,256,192,128)?"
read VSPEED
echo
fi

if [ $ASPEED == "0" ]; then
echo "Audio Speed (128,96,64,48,32)?"
read ASPEED
echo
fi

if [ $VSIZE2 == "0" ]; then
echo "Video Size% (100,75,50,25)?"
read VSIZE
  if [ $VSIZE == "100" ]; then
     VSIZE2='1.0'
  elif [ $VSIZE == "75" ]; then
     VSIZE2='.75'
  elif [ $VSIZE == "50" ]; then
     VSIZE2='.50'
  elif [ $VSIZE == "25" ]; then
     VSIZE2='.25'
  fi
fi
echo

if [ $FPS == "0" ]; then
echo "FPS (25,20,15,10,5)?"
read FPS
echo
fi

echo "Device: "$DEV
echo "VSpeed: "$VSPEED
echo "ASpeed: "$ASPEED
echo " VSize: "$VSIZE " ("$VSIZE2")"
echo "   FPS: "$FPS
echo "Use above settings (y/n)?"
read YESNO
  if [ $YESNO == "n" ]; then
    echo "Exiting..."
    exit 1
  elif [ $YESNO == "y" ]; then
    echo "Starting VLC..."
    vlc -I http --http-host=8002 pvr:$DEV:norm=ntsc:size=720x576:bitrate=3000000:maxbitrate=4000000 --sout-transcode-fps=$FPS --sout-transcode-deinterlace ":sout=#transcode{vcodec=DIV3,acodec=mp3,vb=$VSPEED,ab=$ASPEED,scale=$VSIZE2}:std{access=http{user='',pwd='',mime=video/x-ms-asf},mux=asf,url=:8001}"
  fi
done

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/