diff options
author | Greg Frost <gregfrost1@bigpond.com> | 2009-08-04 01:22:18 (GMT) |
---|---|---|
committer | Greg Frost <gregfrost1@bigpond.com> | 2009-08-04 01:22:18 (GMT) |
commit | e85c92735d5ce5f790cf95a0ea02e08c264e170a (patch) | |
tree | 037a1921e8f6899fea9b5daaaf998ec746367298 /abs/core-testing/linhes-scripts | |
parent | 82af083e07eb189ac930678224a5748551cf69f8 (diff) | |
parent | 120212bdd438d98c52aaab5b43443258be81a7e4 (diff) | |
download | linhes_pkgbuild-e85c92735d5ce5f790cf95a0ea02e08c264e170a.zip linhes_pkgbuild-e85c92735d5ce5f790cf95a0ea02e08c264e170a.tar.gz linhes_pkgbuild-e85c92735d5ce5f790cf95a0ea02e08c264e170a.tar.bz2 |
Merge branch 'master' of ssh://gregfrost@knoppmyth.net/mount/repository/LinHES-PKGBUILD
Diffstat (limited to 'abs/core-testing/linhes-scripts')
21 files changed, 1611 insertions, 2 deletions
diff --git a/abs/core-testing/linhes-scripts/PKGBUILD b/abs/core-testing/linhes-scripts/PKGBUILD index 98a133c..01f4291 100644 --- a/abs/core-testing/linhes-scripts/PKGBUILD +++ b/abs/core-testing/linhes-scripts/PKGBUILD @@ -3,13 +3,12 @@ pkgname=linhes-scripts pkgver=1 -pkgrel=17 +pkgrel=18 pkgdesc="Various scripts that help to make LinHES, LinHES." arch=('i686' 'x86_64') license=('GPL2') depends=('xosd' 'cpulimit') url="http://linhes.org/" -source=(ftp://ftp.knoppmyth.net/R6/sources/linhes-scripts.tar.bz2) build() { cd $startdir/src/ diff --git a/abs/core-testing/linhes-scripts/src/770-wrapper.sh b/abs/core-testing/linhes-scripts/src/770-wrapper.sh new file mode 100755 index 0000000..65573f4 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/770-wrapper.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# 770-wrapper.sh by Cecil Watsona +# Modifed from +# pdatranscode +# +# created by Jeff Volckaert (inspired by Zach White) +# modified 01/16/06 +VIDEODIR=$1 +FILENAME=$2 +TITLE=$3 +# Remove non-alpha characters from TITLE +TITLE=${TITLE//[^a-zA-Z0-9]/} +STARTTIME=$4 +DIROUT=/myth/n770 + +# Sanity checking, to make sure everything is in order. +if [ -z "$VIDEODIR" -o -z "$FILENAME" ]; then + echo "Usage: $0 <VideoDirectory> <FileName> "<Title>" <Starttime>" + exit 5 +fi +if [ ! -f $VIDEODIR/$FILENAME ]; then + echo "File does not exist: $VIDEODIR/$FILENAME" + exit 6 +fi + +# Transcode the file + + +perl /usr/local/bin/770-encode.pl -q -p mplayer $VIDEODIR/$FILENAME $DIROUT/$TITLE-$STARTTIME.avi + +chmod 664 $DIROUT/$TITLE-$STARTTIME.avi + +ERROR=$? +if [ $ERROR -ne 0 ]; then + echo "Transcoding failed for ${FILENAME} with error $ERROR" + exit 3 +fi diff --git a/abs/core-testing/linhes-scripts/src/idle.sh b/abs/core-testing/linhes-scripts/src/idle.sh new file mode 100755 index 0000000..f95b9fa --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/idle.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +usage () { + echo "Usage: $0 [-h] [-s] [-t <minutes_needed>]" + echo + echo "-h - Print this help/usage message and quit" + echo "-s - Run silently (default is verbose)" + echo "-t - Minutes of idle time needed (default is 20)" + echo "-v - Be more verbose for debugging" + echo + echo "Silent mode is recommended for use in cron jobs or scripts." + exit $1 +} + +msg () { # A status reporting function + [ "$VERBOSE" -ne 0 ] && echo "$*" +} + +mysql_cmd () { + /usr/bin/mysql -u root mythconverg -sBe "$*" +} + +# Command line argument handling +VERBOSE=1 +TIME_BEFORE=20 +TIME_AFTER=5 # Only adjustable by editing here + +while getopts "hst:v" OPT ; do + case $OPT in + h) usage 0 ;; + s) VERBOSE=0 ;; + t) TIME_BEFORE=$OPTARG ;; + v) VERBOSE=2 ;; + *) usage 1 ;; + esac +done +# Check for extra cruft on the command line... +shift $(($OPTIND - 1)) +[ -n "$*" ] && usage 1 + +msg "Checking what MythTV is doing now or plans within $TIME_BEFORE minutes..." +msg + +/usr/bin/mythshutdown -s 1 +BUSY="$?" +msg "mythshutdown returned $BUSY" +# Ignore certain non-zero flag values +BUSY=$(($BUSY & 0x2F)) + +SCHEMALOCK=$(mysql_cmd "select count(*) from schemalock") +msg "schemalock $SCHEMALOCK" + +JOBS=$(mysql_cmd "select count(*) from jobqueue where status = 4") +msg "running jobs $JOBS" + +INUSE=$(mysql_cmd "select count(*) from inuseprograms") +msg "inuse programs $INUSE" + +POTENTIAL=$(mysql_cmd "select count(*) from recordmatch as rm, program as p + where rm.chanid = p.chanid and rm.starttime = p.starttime + and rm.starttime < now() + interval $TIME_BEFORE minute + and now() < p.endtime + interval $TIME_AFTER minute") +msg "potential recordings $POTENTIAL" +# See if any of the potential upcoming recordings are real. +# This is ugly, but only the backend knows what programs it really +# plans to record or ignore, so we can't just check the DB. :-( +if [ "$VERBOSE" -ge 2 ] ; then + mysql_cmd "select p.starttime, p.endtime, p.title, subtitle + from recordmatch as rm, program as p + where rm.chanid = p.chanid and rm.starttime = p.starttime + and rm.starttime < now() + interval $TIME_BEFORE minute + and now() < p.endtime + interval $TIME_AFTER minute + order by p.starttime, p.endtime" +fi +UPCOMING=$(/usr/bin/mythbackend --printsched 2>&1 | + /bin/awk -v potential=$POTENTIAL ' + BEGIN {item=-1;real=0} + /--- print list start ---/,/--- print list end ---/ { + if (item>0 && item<=potential && substr($0,70,1) ~ "[0-9]") real+=1; + item += 1; + } + END {print real} +') +msg "planned recordings $UPCOMING" +if [ "$VERBOSE" -ge 2 ] ; then + /usr/bin/mythbackend --printsched 2>&1 | + /bin/awk -v potential=$POTENTIAL ' + BEGIN {item=-1} + /--- print list start ---/,/--- print list end ---/ { + if (item>0 && item<=potential) print $0; + item += 1; + }' +fi +activities=$(($BUSY + $SCHEMALOCK + $JOBS + $INUSE + $UPCOMING)) +msg +if [ "$activities" -eq 0 ] ; then + msg "System is idle" + exit 0 +else + msg "System is busy" + exit 1 +fi diff --git a/abs/core-testing/linhes-scripts/src/importfiles.sh b/abs/core-testing/linhes-scripts/src/importfiles.sh new file mode 100755 index 0000000..84f1ab5 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/importfiles.sh @@ -0,0 +1,18 @@ +#!/bin/bash +export FONT="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" + +DVD_or_CD=`cat /proc/mounts |grep iso9660|awk '{print $2}'|tail -1` +if [ "$DVD_or_CD" != "" ]; then + echo "Copying files from $DVD_or_CD to /myth/video." > /tmp/screens + echo "This could take several minutes, depending on the" >> /tmp/screens + echo "speed and size of your optical media." >> /tmp/screens + cat /tmp/screens | osd_cat --font=$FONT --shadow=3 --pos=middle --align=centre --color=yellow --delay=0 & + /bin/cp -R $DVD_or_CD/* /myth/video/ + killall osd_cat + echo "Copied videos from $DVD_or_CD to /myth/video" > /tmp/screens + cat /tmp/screens | osd_cat --font=$FONT --shadow=3 --pos=middle --align=centre --color=yellow --delay=2 & +else + echo "No optical media found. If you just inserted" > /tmp/screens + echo "your media, please wait a moment and try again." >> /tmp/screens + cat /tmp/screens | osd_cat --font=$FONT --shadow=3 --pos=middle --align=centre --color=yellow --delay=5 & +fi diff --git a/abs/core-testing/linhes-scripts/src/limit-mythcommflag.sh b/abs/core-testing/linhes-scripts/src/limit-mythcommflag.sh new file mode 100755 index 0000000..8ca61c7 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/limit-mythcommflag.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# limit-mythcommflag.sh v0.1 05/17/09 +# Utility to automatically limit mythcommflag if CPU usage is above a certain level. +# Uses cpulimit from http://cpulimit.sourceforge.net/ +# Free for any use. +# Installation: +# cp limit-mythcommflag.sh /usr/LH/bin +# chmod +x /usr/LH/bin/limit-mythcommflag.sh +# Usage: Executed from runit limit-mythcommflag at boot + +# Threshold for when mythcommflag will be paused +CPUTHRESHOLD=43 + +# Limit mythcommflag to percentage +LIMITCPU=20 + +# Log file to write (use /dev/null for no log) +#LOG=/var/log/mythtv/limit-mythcommflag.log +LOG=/dev/null + +# Number of seconds to wait between checking for mythcommflag process +SLEEP=5 + +#sleep $SLEEP + +touch $LOG + +ALREADYLIMITED=0 + +while true; do + PROCCOMMFLAG=`pidof mythcommflag` + if [ -n "${PROCCOMMFLAG}" ] + then + FRONTENDCPU=`top -bn1u mythtv | grep mythfrontend | awk '{ print $9 }'` + if [ "$FRONTENDCPU" -ge "$CPUTHRESHOLD" ] + then + echo "$(date) FE CPU $FRONTENDCPU% is greater than $CPUTHRESHOLD%, LIMIT Commflagging" # >> $LOG + if [ $ALREADYLIMITED -eq 0 ]; then + cpulimit -e mythcommflag -l $LIMITCPU & + cpulimit_pid=$! + ALREADYLIMITED=1 + fi + else + echo "$(date) FE CPU $FRONTENDCPU% is less than $CPUTHRESHOLD%, UNLIMIT Commflagging" #>> $LOG + if [ $ALREADYLIMITED -eq 1 ]; then + kill $cpulimit_pid + ALREADYLIMITED=0 + fi + fi +# else +# echo "No COMMFLAG Process Active" >> $LOG + fi + sleep $SLEEP +done diff --git a/abs/core-testing/linhes-scripts/src/linhes-scripts.tar.bz2 b/abs/core-testing/linhes-scripts/src/linhes-scripts.tar.bz2 Binary files differnew file mode 100644 index 0000000..d9bd8e7 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/linhes-scripts.tar.bz2 diff --git a/abs/core-testing/linhes-scripts/src/mplayer-resumer-vdpau.pl b/abs/core-testing/linhes-scripts/src/mplayer-resumer-vdpau.pl new file mode 100755 index 0000000..9c82158 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/mplayer-resumer-vdpau.pl @@ -0,0 +1,204 @@ +#!/usr/bin/perl + +use Shell; +use strict; +use POSIX qw(floor); + +# Written by Bob Igo from the MythTV Store at http://MythiC.TV +# Email: bob@stormlogic.com +# +# If you run into problems with this script, please send me email + +# CHANGE LOG: +# 3/9/2009 +# Modded Bob's wonderful resumer script to work with the vdpau +# options detector script someone anonymously posted to the wiki +# +# http://www.knoppmythwiki.org/index.php?page=HardwareAcceleratedVideo +# +# You need to have both this and the vdpau-detector script in the same +# dir for this to work properly. Also, change your default mplayer +# options in mythfrontend to read simply: # mplayer-resumer-vdpau.pl %s +# +# To tweak the shell commands for mplayer, edit the vdpau-detector script. +# It has a small README inside it as comments +# ENJOY! + +# 5/3/2006 +# Added last time started checking. +# If this script is restarted within $tdiff (default 5 seconds) +# then it will delete the file used to keep track of the videos +# resume position. + +# PURPOSE: +# -------------------------- +# This is a wrapper script to prove the concept of having MythTV +# resume playback of previously-stopped video where you left off. +# It's likely that a good solution will look different than this +# initial code. + +# RATIONALE: +# -------------------------- +# Watching 90% of a video and stopping causes you to return to the +# beginning again the next time you watch it. Remembering where +# you were in the video and resuming at that position is a much nicer +# behavior for the user. +# +# By default, mplayer spits out timecode information that tells you +# where you are in the video, to the tenth of a second. Mplayer also +# supports a seek feature on the command-line. We can make use of these +# features to write an mplayer wrapper that will remember the last +# position in a video file and resume to it on playback. + +# PARAMETERS: +# -------------------------- +# see print_usage() below + +# FILES: +# -------------------------- +# $infile, the video to play +# $resumefile, the video's resume file (see get_resume_filename() below) + +# KNOWN ISSUES: +# -------------------------- +# Mplayer misreports the timecodes on .nuv MPEG-2 files. Currently, anything +# captured via an HDTV tuner card and put into your /myth/video directory +# will fail with this resumer. +# +# Current theories include the timecode having to do with the show's broadcast +# time, recording time, or perhaps its upload time to the station that +# broadcast it. + +# DESIGN LIMITATION: +# ------------------------- +# If the video file to be played is on a read-only filesystem, or otherwise +# lives in a location that cannot be written to, resume will fail. This is +# because the current implementation uses a file parallel to the video file +# to store the timecode. +# + +my $infile; +my $resumefile; +my $mplayer_parameters; +my $fudge_factor=2; # number of additional seconds to skip back before playback +my $tnow; # Time now. +my $tprev; # Time the prog was last started. + # Returned from the modification time of the xx.resume file. +my $tdiff=5; # How many seconds before we should start from + # the beginning of the movie +#DEBUG +#open(DEBUG,">/tmp/debug") || die "unable to open debug file"; + +sub init () { + $tnow = time(); + $infile = @ARGV[$#ARGV]; + + $resumefile = &get_resume_filename($infile); + # This returns the 9th element of the 13 element array + # created by the stat function. + $tprev = (stat ($resumefile))[9]; + # if this file is restarted in less than 5 seconds then + # remove the .resume file + if ( ($tnow - $tprev) < $tdiff ) { + unlink($resumefile); + } + + $mplayer_parameters = join(' ',@ARGV[0..$#ARGV-1]); +} + +&init(); +&save_time_offset(&mplayer($mplayer_parameters,$infile), $resumefile); + +#close(DEBUG); + +# For $pathname, return $path.$filename.resume +sub get_resume_filename () { + my($pathname)=@_; + + my $idx = rindex($pathname,"/"); + + if ($idx == -1) { # There was no "/" in $pathname + return ".".$pathname.".resume"; + } else { + # Now we need to split out the path from the filename. + my $path = substr($pathname,0,$idx+1); + my $filename = substr($pathname,$idx+1); + return "$path.$filename.resume"; + } +} + +# Calls mplayer and returns the last known video position +sub mplayer () { + my($parameters,$infile)=@_; + my $seconds=0; + my $timecode=&get_time_offset($infile); + my $mplayeropts=`./vdpau-detector $infile`; chomp $mplayeropts; + my @lines = split "\n", $mplayeropts; + my $last_line = pop(@lines); + my $command = "mplayer $last_line $parameters -ss $timecode \"$infile\" 2>&1 2>/dev/null |"; + + open(SHELL, $command); + # The kind of line we care about looks like this example: + # A:1215.2 V:1215.2 A-V: 0.006 ct: 0.210 207/201 13% 0% 1.9% 0 0 68% + # But all we care to look at is the first number. + + while (<SHELL>) { + #print DEBUG $_; + if (m/A: *[0-9]+\.[0-9]/) { # See if this line has timecodes on it + my $last_timecode_line = &extract_last_timecode_line($_); + if ($last_timecode_line =~ m/ *([0-9]+\.[0-9]) V/) { + $seconds=$1; + } + } + } + close(SHELL); + + return $seconds; + + sub extract_last_timecode_line () { + my ($line)=@_; + my @lines=split('A:',$line); + return @lines[$#lines-1]; + } +} + +# Save the last known video position +sub save_time_offset () { + my($seconds, $resumefile)=@_; + + open(RESUMEFILE, ">$resumefile") || die "Unable to open $resumefile for writing"; + print RESUMEFILE "$seconds"; + close(RESUMEFILE); +} + +# returns the number of seconds corresponding to the last known video position, +# in hh:mm:ss format, compatible with the "-ss" parameter to mplayer +sub get_time_offset () { + my($videofile)=@_; + my($resumefile) = &get_resume_filename($videofile); + my $seconds=0; + my $timecode; + + open(RESUMEFILE, "<$resumefile") || return "00:00:00"; + while(<RESUMEFILE>) { + $seconds=$_; + } + close(RESUMEFILE); + + my $hours = floor($seconds/3600); + $seconds = $seconds - $hours*3600; + + my $minutes = floor($seconds/60); + $seconds = int($seconds - $minutes*60) - $fudge_factor; + + $timecode = sprintf "%02d:%02d:%02d",$hours,$minutes,$seconds; +# print "TIMECODE: $timecode\n"; + return $timecode; +} + +sub print_usage () { + print "USAGE:\n"; + print "\t",$ARGV[0], "[mplayer parameters] video_file\n"; + print "\t","e.g. ",$ARGV[0], "-fs -zoom my.mpg\n"; + print "\t","Version 3/9/2009\n"; +} diff --git a/abs/core-testing/linhes-scripts/src/mplayer-resumer.pl b/abs/core-testing/linhes-scripts/src/mplayer-resumer.pl new file mode 100755 index 0000000..c785a25 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/mplayer-resumer.pl @@ -0,0 +1,188 @@ +#!/usr/bin/perl + +use Shell; +use strict; +use POSIX qw(floor); + +# Written by Bob Igo from the MythTV Store at http://MythiC.TV +# Email: bob@stormlogic.com +# +# If you run into problems with this script, please send me email + +# PURPOSE: +# -------------------------- +# This is a wrapper script to prove the concept of having MythTV +# resume playback of previously-stopped video where you left off. +# It's likely that a good solution will look different than this +# initial code. + +# RATIONALE: +# -------------------------- +# Watching 90% of a video and stopping causes you to return to the +# beginning again the next time you watch it. Remembering where +# you were in the video and resuming at that position is a much nicer +# behavior for the user. +# +# By default, mplayer spits out timecode information that tells you +# where you are in the video, to the tenth of a second. Mplayer also +# supports a seek feature on the command-line. We can make use of these +# features to write an mplayer wrapper that will remember the last +# position in a video file and resume to it on playback. + +# PARAMETERS: +# -------------------------- +# see print_usage() below + +# FILES: +# -------------------------- +# $infile, the video to play +# $resumefile, the video's resume file (see get_resume_filename() below) + +# KNOWN ISSUES: +# -------------------------- +# Mplayer misreports the timecodes on .nuv MPEG-2 files. Currently, anything +# captured via an HDTV tuner card and put into your /myth/video directory +# will fail with this resumer. +# +# Current theories include the timecode having to do with the show's broadcast +# time, recording time, or perhaps its upload time to the station that +# broadcast it. + +# DESIGN LIMITATION: +# ------------------------- +# If the video file to be played is on a read-only filesystem, or otherwise +# lives in a location that cannot be written to, resume will fail. This is +# because the current implementation uses a file parallel to the video file +# to store the timecode. +# + +# CHANGE LOG: +# 5/3/2006 +# Added last time started checking. +# If this script is restarted within $tdiff (default 5 seconds) +# then it will delete the file used to keep track of the videos +# resume position. + + +my $infile; +my $resumefile; +my $mplayer_parameters; +my $fudge_factor=2; # number of additional seconds to skip back before playback +my $tnow; # Time now. +my $tprev; # Time the prog was last started. + # Returned from the modification time of the xx.resume file. +my $tdiff=5; # How many seconds before we should start from + # the beginning of the movie +#DEBUG +#open(DEBUG,">/tmp/debug") || die "unable to open debug file"; + +sub init () { + $tnow = time(); + $infile = @ARGV[$#ARGV]; + + $resumefile = &get_resume_filename($infile); + # This returns the 9th element of the 13 element array + # created by the stat function. + $tprev = (stat ($resumefile))[9]; + # if this file is restarted in less than 5 seconds then + # remove the .resume file + if ( ($tnow - $tprev) < $tdiff ) { + unlink($resumefile); + } + + $mplayer_parameters = join(' ',@ARGV[0..$#ARGV-1]); +} + +&init(); +&save_time_offset(&mplayer($mplayer_parameters,$infile), $resumefile); + +#close(DEBUG); + +# For $pathname, return $path.$filename.resume +sub get_resume_filename () { + my($pathname)=@_; + + my $idx = rindex($pathname,"/"); + + if ($idx == -1) { # There was no "/" in $pathname + return ".".$pathname.".resume"; + } else { + # Now we need to split out the path from the filename. + my $path = substr($pathname,0,$idx+1); + my $filename = substr($pathname,$idx+1); + return "$path.$filename.resume"; + } +} + +# Calls mplayer and returns the last known video position +sub mplayer () { + my($parameters,$infile)=@_; + my $seconds=0; + my $timecode=&get_time_offset($infile); + my $command = "mplayer $parameters -ss $timecode \"$infile\" 2>&1 2>/dev/null |"; + + open(SHELL, $command); + # The kind of line we care about looks like this example: + # A:1215.2 V:1215.2 A-V: 0.006 ct: 0.210 207/201 13% 0% 1.9% 0 0 68% + # But all we care to look at is the first number. + + while (<SHELL>) { + #print DEBUG $_; + if (m/A: *[0-9]+\.[0-9]/) { # See if this line has timecodes on it + my $last_timecode_line = &extract_last_timecode_line($_); + if ($last_timecode_line =~ m/ *([0-9]+\.[0-9]) V/) { + $seconds=$1; + } + } + } + close(SHELL); + + return $seconds; + + sub extract_last_timecode_line () { + my ($line)=@_; + my @lines=split('A:',$line); + return @lines[$#lines-1]; + } +} + +# Save the last known video position +sub save_time_offset () { + my($seconds, $resumefile)=@_; + + open(RESUMEFILE, ">$resumefile") || die "Unable to open $resumefile for writing"; + print RESUMEFILE "$seconds"; + close(RESUMEFILE); +} + +# returns the number of seconds corresponding to the last known video position, +# in hh:mm:ss format, compatible with the "-ss" parameter to mplayer +sub get_time_offset () { + my($videofile)=@_; + my($resumefile) = &get_resume_filename($videofile); + my $seconds=0; + my $timecode; + + open(RESUMEFILE, "<$resumefile") || return "00:00:00"; + while(<RESUMEFILE>) { + $seconds=$_; + } + close(RESUMEFILE); + + my $hours = floor($seconds/3600); + $seconds = $seconds - $hours*3600; + + my $minutes = floor($seconds/60); + $seconds = int($seconds - $minutes*60) - $fudge_factor; + + $timecode = sprintf "%02d:%02d:%02d",$hours,$minutes,$seconds; +# print "TIMECODE: $timecode\n"; + return $timecode; +} + +sub print_usage () { + print "USAGE:\n"; + print "\t",$ARGV[0], "[mplayer parameters] video_file\n"; + print "\t","e.g. ",$ARGV[0], "-fs -zoom my.mpg\n"; + print "\t","Version 5/3/2006\n"; +} diff --git a/abs/core-testing/linhes-scripts/src/myth2mp3 b/abs/core-testing/linhes-scripts/src/myth2mp3 new file mode 100755 index 0000000..89181c1 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/myth2mp3 @@ -0,0 +1,82 @@ +#!/bin/sh +# convert recordings to as mp3 audio only +# version 0.9 + +# usage: +# first parameter must be %DIR%/%FILE% of the recording +# second parameter must be the desired base name of the output +# third parameter must be %CHANID% if you set USECUTLIST=Y +# fourth parameter must be %STARTTIME% if you set USECUTLIST=Y +# In the mythtv setup screen invoke this script like this: +# MYTHTV User Job Command: +# /usr/LH/bin/myth2mp3 "%DIR%/%FILE%" "%TITLE% - %SUBTITLE%" "%CHANID%" "%STARTTIME%" + +# options: +BITRATE=256k #ie. 128k, 160k, 192k, 224k, 256k +USECUTLIST=Y #Y or N + +# where the converted audio is stored +OUT_DIR=/myth/music + +# create temp filename so multiple instances won't conflict +TMPNAME=toMP3-$$ +TMPFILE=/myth/tmp/$TMPNAME.mp3 +TMPCUTFILE=/myth/tmp/$TMPNAME.mpg +FFINPUTFILE=$1 + +# log file location +LOGFILE=/var/log/mythtv/myth2mp3.log +CDate="`date`" +echo "" >> $LOGFILE +echo $CDate >> $LOGFILE +echo "File to encode: $1 Name: $2" >> $LOGFILE + +# start timer +beforetime="$(date +%s)" + +# check if using cutlist +if [ $USECUTLIST = Y ];then + MYTHCOMMFRAMES=`mythcommflag --getcutlist -f "$FFINPUTFILE" | grep 'Cutlist:' | cut -d \ -f 2` + if [ -n "$MYTHCOMMFRAMES" ]; then + echo "Extracting Cutlist..." >> $LOGFILE + /usr/bin/nice -n19 /usr/bin/mythtranscode --chanid "$3" --starttime "$4" --outfile "$TMPCUTFILE" --mpeg2 --honorcutlist + FFINPUTFILE=$TMPCUTFILE + fi +fi + +# run ffmpeg to do conversion +echo "Encoding..." >> $LOGFILE +/usr/bin/nice -n19 /usr/bin/ffmpeg -i "$FFINPUTFILE" -vn -acodec libmp3lame -ab $BITRATE -ar 44100 -ac 2 "$TMPFILE" +ERROR=$? + +# make output filename unique +OUTPUTFILE=$OUT_DIR/$2.mp3 +i=1 +while [ -e "$OUTPUTFILE" ] +do + OUTPUTFILE=$OUT_DIR/$2-$i.mp3 + i=`expr $i + 1` +done + +# move temp file to output location +chown mythtv "$TMPFILE" && mv "$TMPFILE" "$OUTPUTFILE" + +# stop timer +aftertime="$(date +%s)" +seconds="$(expr $aftertime - $beforetime)" + +if [ $ERROR -eq 0 ]; then + echo "File Encoded Sucessfully: $OUTPUTFILE" >> $LOGFILE + hours=$((seconds / 3600)) + seconds=$((seconds % 3600)) + minutes=$((seconds / 60)) + seconds=$((seconds % 60)) + echo "Encoding Time: $hours hour(s) $minutes minute(s) $seconds second(s)" >> $LOGFILE +else + echo "ERROR: $ERROR" >> $LOGFILE +fi + +# clean up left over files +unlink $TMPFILE 2> /dev/null +unlink $TMPCUTFILE 2> /dev/null +unlink $TMPCUTFILE.map 2> /dev/null diff --git a/abs/core-testing/linhes-scripts/src/myth2x264 b/abs/core-testing/linhes-scripts/src/myth2x264 new file mode 100755 index 0000000..014fcbe --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/myth2x264 @@ -0,0 +1,223 @@ +#!/bin/sh +# convert recording to x264 encoded avi +# version 0.6 + +# usage: +# first parameter must be %DIR%/%FILE% of the recording +# second parameter must be the desired base name of the output +# third parameter must be %CHANID% if you set USECUTLIST=Y +# fourth parameter must be %STARTTIME% if you set USECUTLIST=Y +# fifth parameter must be %JOBID% for the User Job status to be updated in MythTV +# in the mythtv setup screen invoke this script like this: +# MYTHTV User Job Command: +# /usr/LH/bin/myth2x264 "%DIR%/%FILE%" "%TITLE% - %SUBTITLE%" "%CHANID%" "%STARTTIME%" "%JOBID%" + +# options: +RESOLUTION=960:544 # to keep the source resolution use -1 or to scale down use xxx:xxx (ie 960:544) +BITRATE=2500 # use negative bitrate to set output file size in KB (ie. -700000) +USECUTLIST=Y # Y or N + +# where the converted video is stored +OUT_DIR=/myth/video + +# database settings +BACKEND_HOSTNAME=${BACKEND_HOSTNAME:-"localhost"} +DBUSERNAME=${DBUSERNAME:-"mythtv"} +DBPASSWORD=${DBPASSWORD:-"mythtv"} +SQLCMD="mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e" + +#------FUNCTIONS--------------- +update_comment() +# Arg_1 = COMMENT +{ +if [ $NO_JOBID = 0 ]; then + `$SQLCMD "update jobqueue set comment=\"$1\" where id=\"$JOBID\";"` +fi +} + +update_status() +# Arg_1 = status code +{ +if [ $NO_JOBID = 0 ]; then + `$SQLCMD "update jobqueue set status=\"$1\" where id=\"$JOBID\";"` +fi +} + +check_background_progress() +# check mencoder progress in background +# Arg_1 = PROGRESS CALCULATION +{ +while [ `tail -1 $STATUSFILE | grep -c "^x264 \[info\]: kb/s:"` = 0 ] +do + sleep 10 + check_myth_jobcmds + current_status=`tail -1 $STATUSFILE | grep "([ 0-9]\{1,\}%)"` + prog_percent=`echo "$current_status" | sed 's_.*(\([ 0-9][ 0-9]\)%).*_\1_'` + current_FPS=`echo "$current_status" | sed 's_.*\([ 0-9][ 0-9].[ 0-9][ 0-9]\)fps.*_\1_'` + if [ -n "$prog_percent" ]; then + prog_percent=`expr $prog_percent / $1` + echo "$prog_percent% Completed @ $current_FPS fps" + update_comment "$prog_percent% Completed @ $current_FPS fps" + fi + sleep 10 +done +} + +check_myth_jobcmds() +# check the myth database for stop pause or resume commands +{ +if [ $NO_JOBID = 0 ]; then + CURRENT_CMD=`$SQLCMD "select cmds from jobqueue where id=\"$JOBID\";" | sed '/[0-9]/!d'` + case "$CURRENT_CMD" in + # JOB_RUN + 0) ;; + # JOB_PAUSE + 1) update_status 6 + kill -s STOP $mencoder_pid ;; + # JOB_RESUME + 2) update_status 4 + `$SQLCMD "update jobqueue set cmds=\"0\" where id=\"$JOBID\";"` + kill -s CONT $mencoder_pid ;; + # JOB_STOP + 4) update_status 5 + `$SQLCMD "update jobqueue set cmds=\"0\" where id=\"$JOBID\";"` + kill -9 $mencoder_pid $command_pid + clean_up_files + echo "Encode Cancelled" >> $LOGFILE + update_status 320 + exit ;; + esac +fi +} + +get_mencoder_pid() +{ +process_name="" +i1=1 +while [ "$process_name" != "found" ]; do + if [ "`ps $mencoder_pid | grep mencoder | sed 's_.*\(mencoder\).*_\1_'`" = "mencoder" ]; then + process_name="found" + else + mencoder_pid=`expr $mencoder_pid + 1` + fi + i1=`expr $i1 + 1` + if [ $i1 -gt 20 ]; then + break + fi +done +} + +clean_up_files() +# clean up left over files +{ +unlink $TMPFILE 2> /dev/null +unlink $TMPCUTFILE 2> /dev/null +unlink $TMPCUTFILE.map 2> /dev/null +unlink $TWOPASSFILE 2> /dev/null +unlink $TWOPASSFILE.tmp 2> /dev/null +unlink $STATUSFILE 2> /dev/null +unlink $MENCODER_RETURN_CODE 2> /dev/null +unlink $MENCODER_RETURN_CODE_2 2> /dev/null +} + +#-------MAIN SCRIPT------------ + +# check if %JOBID% is passed from command line +JOBID=$5 +if [ -z "$JOBID" ]; then + NO_JOBID=1 +else + NO_JOBID=0 +fi + +# create temp filename so multiple instances won't conflict +TMPNAME=toX264-$$ +TMPFILE=/myth/tmp/$TMPNAME.avi +TMPCUTFILE=/myth/tmp/$TMPNAME.mpg +MENINPUTFILE=$1 +TWOPASSFILE=/myth/tmp/$TMPNAME-2pass.log +STATUSFILE=/myth/tmp/$TMPNAME-status.log +MENCODER_RETURN_CODE=/myth/tmp/$TMPNAME-mencoder_return_code +MENCODER_RETURN_CODE_2=/myth/tmp/$TMPNAME-mencoder_return_code_2 + +# log file location +LOGFILE=/var/log/mythtv/myth2x264.log +CDate="`date`" +echo "" >> $LOGFILE +echo $CDate >> $LOGFILE +echo "File to encode: $MENINPUTFILE Name: $2" >> $LOGFILE + +# start timer +beforetime="$(date +%s)" + +check_myth_jobcmds + +# check if using cutlist +if [ $USECUTLIST = Y ]; then + MYTHCOMMFRAMES=`mythcommflag --getcutlist -f $MENINPUTFILE | grep 'Cutlist:' | cut -d \ -f 2` + if [ -n "$MYTHCOMMFRAMES" ]; then + echo "Extracting Cutlist..." >> $LOGFILE + update_comment "Extracting Cutlist" + /usr/bin/nice -n19 /usr/bin/mythtranscode --chanid "$3" --starttime "$4" --outfile "$TMPCUTFILE" --mpeg2 --honorcutlist + MENINPUTFILE=$TMPCUTFILE + fi +fi + +# run mencoder in background to do 1st pass conversion +echo "Encoding 1st Pass at $RESOLUTION..." >> $LOGFILE +( /usr/bin/nice -n19 /usr/bin/mencoder $MENINPUTFILE -passlogfile $TWOPASSFILE \ +-oac copy -ovc x264 -vf lavcdeint,scale=$RESOLUTION \ +-x264encopts threads=auto:pass=1:turbo=1:subq=1:frameref=1:bframes=3:bitrate=$BITRATE \ +-o /dev/null > $STATUSFILE 2>&1 ; echo $? > $MENCODER_RETURN_CODE ) & +mencoder_pid=$! +command_pid=$mencoder_pid +get_mencoder_pid + +check_background_progress "2" + +# run mencoder in background to do 2nd pass conversion +echo "Encoding 2nd Pass at $RESOLUTION..." >> $LOGFILE +( /usr/bin/nice -n19 /usr/bin/mencoder $MENINPUTFILE -passlogfile $TWOPASSFILE \ +-oac copy -ovc x264 -vf lavcdeint,scale=$RESOLUTION \ +-x264encopts threads=auto:pass=2:subq=5:8x8dct:frameref=3:bframes=3:b_pyramid:weight_b:bitrate=$BITRATE \ +-o "$TMPFILE" > $STATUSFILE 2>&1 ; echo $? > $MENCODER_RETURN_CODE_2 ) & +mencoder_pid=$! +command_pid=$mencoder_pid +get_mencoder_pid + +check_background_progress "2 + 50" + +ERROR=$? + +# make output filename unique +OUTPUTFILE=$OUT_DIR/$2.avi +i=1 +while [ -e "$OUTPUTFILE" ] +do + OUTPUTFILE=$OUT_DIR/$2-$i.avi + i=`expr $i + 1` +done + +# move temp file to output location +chown mythtv "$TMPFILE" && mv "$TMPFILE" "$OUTPUTFILE" + +# stop timer +aftertime="$(date +%s)" +seconds="$(expr $aftertime - $beforetime)" + +if [ $ERROR -eq 0 ]; then + echo "File Encoded Successfully: $OUTPUTFILE" >> $LOGFILE + hours=$((seconds / 3600)) + seconds=$((seconds % 3600)) + minutes=$((seconds / 60)) + seconds=$((seconds % 60)) + echo "Encoding took $hours hour(s) $minutes minute(s) $seconds second(s) @ $current_FPS fps." >> $LOGFILE + update_status 272 + update_comment "Encode Successful. Encoding Time: $hours hour(s) $minutes minute(s) $seconds second(s)" +else + update_status 304 + update_comment "Encode Failed. Exit status: $ERROR" + echo "ERROR: $ERROR" >> $LOGFILE +fi + +clean_up_files diff --git a/abs/core-testing/linhes-scripts/src/myth2xvid b/abs/core-testing/linhes-scripts/src/myth2xvid new file mode 100755 index 0000000..d0fcb42 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/myth2xvid @@ -0,0 +1,223 @@ +#!/bin/sh +# convert recording to xvid encoded avi +# version 1.3 + +# usage: +# first parameter must be %DIR%/%FILE% of the recording +# second parameter must be the desired base name of the output +# third parameter must be %CHANID% if you set USECUTLIST=Y +# fourth parameter must be %STARTTIME% if you set USECUTLIST=Y +# fifth parameter must be %JOBID% for the User Job status to be updated in MythTV +# in the mythtv setup screen invoke this script like this: +# MYTHTV User Job Command: +# /usr/LH/bin/myth2xvid "%DIR%/%FILE%" "%TITLE% - %SUBTITLE%" "%CHANID%" "%STARTTIME%" "%JOBID%" + +# options: +RESOLUTION=960:544 # to keep the source resolution use -1 or to scale down use xxx:xxx (ie 960:544) +BITRATE=2500 # use negative bitrate to set output file size in KB (ie. -700000) +USECUTLIST=Y # Y or N + +# where the converted video is stored +OUT_DIR=/myth/video + +# database settings +BACKEND_HOSTNAME=${BACKEND_HOSTNAME:-"localhost"} +DBUSERNAME=${DBUSERNAME:-"mythtv"} +DBPASSWORD=${DBPASSWORD:-"mythtv"} +SQLCMD="mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e" + +#------FUNCTIONS--------------- +update_comment() +# Arg_1 = COMMENT +{ +if [ $NO_JOBID = 0 ]; then + `$SQLCMD "update jobqueue set comment=\"$1\" where id=\"$JOBID\";"` +fi +} + +update_status() +# Arg_1 = status code +{ +if [ $NO_JOBID = 0 ]; then + `$SQLCMD "update jobqueue set status=\"$1\" where id=\"$JOBID\";"` +fi +} + +check_background_progress() +# check mencoder progress in background +# Arg_1 = PROGRESS CALCULATION +{ +while [ `tail -1 $STATUSFILE | grep -c "^Audio stream:"` = 0 ] +do + sleep 10 + check_myth_jobcmds + current_status=`tail -1 $STATUSFILE | grep "([ 0-9]\{1,\}%)"` + prog_percent=`echo "$current_status" | sed 's_.*(\([ 0-9][ 0-9]\)%).*_\1_'` + current_FPS=`echo "$current_status" | sed 's_.*\([ 0-9][ 0-9].[ 0-9][ 0-9]\)fps.*_\1_'` + if [ -n "$prog_percent" ]; then + prog_percent=`expr $prog_percent / $1` + echo "$prog_percent% Completed @ $current_FPS fps" + update_comment "$prog_percent% Completed @ $current_FPS fps" + fi + sleep 10 +done +} + +check_myth_jobcmds() +# check the myth database for stop pause or resume commands +{ +if [ $NO_JOBID = 0 ]; then + CURRENT_CMD=`$SQLCMD "select cmds from jobqueue where id=\"$JOBID\";" | sed '/[0-9]/!d'` + case "$CURRENT_CMD" in + # JOB_RUN + 0) ;; + # JOB_PAUSE + 1) update_status 6 + kill -s STOP $mencoder_pid ;; + # JOB_RESUME + 2) update_status 4 + `$SQLCMD "update jobqueue set cmds=\"0\" where id=\"$JOBID\";"` + kill -s CONT $mencoder_pid ;; + # JOB_STOP + 4) update_status 5 + `$SQLCMD "update jobqueue set cmds=\"0\" where id=\"$JOBID\";"` + kill -9 $mencoder_pid $command_pid + clean_up_files + echo "Encode Cancelled" >> $LOGFILE + update_status 320 + exit ;; + esac +fi +} + +get_mencoder_pid() +{ +process_name="" +i1=1 +while [ "$process_name" != "found" ]; do + if [ "`ps $mencoder_pid | grep mencoder | sed 's_.*\(mencoder\).*_\1_'`" = "mencoder" ]; then + process_name="found" + else + mencoder_pid=`expr $mencoder_pid + 1` + fi + i1=`expr $i1 + 1` + if [ $i1 -gt 20 ]; then + break + fi +done +} + +clean_up_files() +# clean up left over files +{ +unlink $TMPFILE 2> /dev/null +unlink $TMPCUTFILE 2> /dev/null +unlink $TMPCUTFILE.map 2> /dev/null +unlink $TWOPASSFILE 2> /dev/null +unlink $TWOPASSFILE.tmp 2> /dev/null +unlink $STATUSFILE 2> /dev/null +unlink $MENCODER_RETURN_CODE 2> /dev/null +unlink $MENCODER_RETURN_CODE_2 2> /dev/null +} + +#-------MAIN SCRIPT------------ + +# check if %JOBID% is passed from command line +JOBID=$5 +if [ -z "$JOBID" ]; then + NO_JOBID=1 +else + NO_JOBID=0 +fi + +# create temp filename so multiple instances won't conflict +TMPNAME=toXVID-$$ +TMPFILE=/myth/tmp/$TMPNAME.avi +TMPCUTFILE=/myth/tmp/$TMPNAME.mpg +MENINPUTFILE=$1 +TWOPASSFILE=/myth/tmp/$TMPNAME-2pass.log +STATUSFILE=/myth/tmp/$TMPNAME-status.log +MENCODER_RETURN_CODE=/myth/tmp/$TMPNAME-mencoder_return_code +MENCODER_RETURN_CODE_2=/myth/tmp/$TMPNAME-mencoder_return_code_2 + +# log file location +LOGFILE=/var/log/mythtv/myth2xvid.log +CDate="`date`" +echo "" >> $LOGFILE +echo $CDate >> $LOGFILE +echo "File to encode: $MENINPUTFILE Name: $2" >> $LOGFILE + +# start timer +beforetime="$(date +%s)" + +check_myth_jobcmds + +# check if using cutlist +if [ $USECUTLIST = Y ]; then + MYTHCOMMFRAMES=`mythcommflag --getcutlist -f $MENINPUTFILE | grep 'Cutlist:' | cut -d \ -f 2` + if [ -n "$MYTHCOMMFRAMES" ]; then + echo "Extracting Cutlist..." >> $LOGFILE + update_comment "Extracting Cutlist" + /usr/bin/nice -n19 /usr/bin/mythtranscode --chanid "$3" --starttime "$4" --outfile "$TMPCUTFILE" --mpeg2 --honorcutlist + MENINPUTFILE=$TMPCUTFILE + fi +fi + +# run mencoder in background to do 1st pass conversion +echo "Encoding 1st Pass at $RESOLUTION..." >> $LOGFILE +( /usr/bin/nice -n19 /usr/bin/mencoder $MENINPUTFILE -passlogfile $TWOPASSFILE \ +-oac copy -ovc xvid -vf lavcdeint,scale=$RESOLUTION \ +-xvidencopts pass=1:vhq=0:turbo:me_quality=5:quant_type=mpeg:max_bframes=0:bitrate=$BITRATE \ +-o /dev/null > $STATUSFILE 2>&1 ; echo $? > $MENCODER_RETURN_CODE ) & +mencoder_pid=$! +command_pid=$mencoder_pid +get_mencoder_pid + +check_background_progress "2" + +# run mencoder in background to do 2nd pass conversion +echo "Encoding 2nd Pass at $RESOLUTION..." >> $LOGFILE +( /usr/bin/nice -n19 /usr/bin/mencoder $MENINPUTFILE -passlogfile $TWOPASSFILE \ +-oac copy -ovc xvid -vf lavcdeint,scale=$RESOLUTION \ +-xvidencopts pass=2:vhq=0:bvhq=1:me_quality=5:quant_type=mpeg:max_bframes=0:bitrate=$BITRATE \ +-o "$TMPFILE" > $STATUSFILE 2>&1 ; echo $? > $MENCODER_RETURN_CODE_2 ) & +mencoder_pid=$! +command_pid=$mencoder_pid +get_mencoder_pid + +check_background_progress "2 + 50" + +ERROR=$? + +# make output filename unique +OUTPUTFILE=$OUT_DIR/$2.avi +i=1 +while [ -e "$OUTPUTFILE" ] +do + OUTPUTFILE=$OUT_DIR/$2-$i.avi + i=`expr $i + 1` +done + +# move temp file to output location +chown mythtv "$TMPFILE" && mv "$TMPFILE" "$OUTPUTFILE" + +# stop timer +aftertime="$(date +%s)" +seconds="$(expr $aftertime - $beforetime)" + +if [ $ERROR -eq 0 ]; then + echo "File Encoded Successfully: $OUTPUTFILE" >> $LOGFILE + hours=$((seconds / 3600)) + seconds=$((seconds % 3600)) + minutes=$((seconds / 60)) + seconds=$((seconds % 60)) + echo "Encoding took $hours hour(s) $minutes minute(s) $seconds second(s) @ $current_FPS fps." >> $LOGFILE + update_status 272 + update_comment "Encode Successful. Encoding Time: $hours hour(s) $minutes minute(s) $seconds second(s)" +else + update_status 304 + update_comment "Encode Failed. Exit status: $ERROR" + echo "ERROR: $ERROR" >> $LOGFILE +fi + +clean_up_files
\ No newline at end of file diff --git a/abs/core-testing/linhes-scripts/src/mythwelcome-set-alarm.sh b/abs/core-testing/linhes-scripts/src/mythwelcome-set-alarm.sh new file mode 100755 index 0000000..6dbd39e --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/mythwelcome-set-alarm.sh @@ -0,0 +1,23 @@ +#!/bin/sh +#$1 is the first argument to the script. It is the time in seconds since 1970 +#This is defined in mythwelcome with the time_t argument + +# Configure mythwelcome --setup page: +# Command to Set Wakeup Time: sudo sh -c "/usr/LH/bin/mythwelcome-set-alarm.sh $time" +# Wakeup Time Format: time_t +# nvram-wakeup Restart Command: Leave this blank +# Command to reboot: sudo /sbin/reboot +# Command to shutdown: sudo /sbin/poweroff +# Command to run Xterm: xterm +# Command to start the Frontend: /usr/bin/mythfrontend -l /var/log/mythtv/mythfrontend.log + +# Configure mythtv-setup Shutdown/Wakeup Options page: +# Idletimeout (secs): any value greater that 0 +# Wakeup time format: yyyy-MM-dd:hh:mm +# Set wakeup time command: /usr/bin/mythshutdown --setwakeup $time +# Server Halt command: /usr/bin/mythshutdown --shutdown +# Pre shutdown check command: /usr/bin/mythshutdown --check + +echo 0 > /sys/class/rtc/rtc0/wakealarm #this clears your alarm +echo $1 > /sys/class/rtc/rtc0/wakealarm #this writes your alarm +cat /proc/driver/rtc > /var/log/wake_alarm diff --git a/abs/core-testing/linhes-scripts/src/mythwelcome-test-wakeup.sh b/abs/core-testing/linhes-scripts/src/mythwelcome-test-wakeup.sh new file mode 100755 index 0000000..4aadf6d --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/mythwelcome-test-wakeup.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm" #this clears your alarm +sudo sh -c "echo `date '+%s' -d '+ 4 minutes'` > /sys/class/rtc/rtc0/wakealarm" #this writes your alarm +cat /proc/driver/rtc +cat /proc/driver/rtc > /var/log/wake_alarm +echo "Your computer is set to start up in 4 minutes using ACPI." +echo -n "Do you want to shutdown the computer now? (y/n): " +read -n 1 shutdown +if [ "$shutdown" == "y" ]; then + echo -e "\nShutting down now..." + sudo shutdown -t 5 -h now +else + echo -e "\nTo shutdown execute the following:" + echo " sudo shutdown -t 5 -h now" +fi diff --git a/abs/core-testing/linhes-scripts/src/pause-mythcommflag.sh b/abs/core-testing/linhes-scripts/src/pause-mythcommflag.sh new file mode 100755 index 0000000..4da808b --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/pause-mythcommflag.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# pause-mythcommflag.sh v0.2 05/21/09 +# Utility to automatically pause & unpause mythcommflag if CPU usage is above a certain level +# Free for any use. +# Installation: +# cp pause-mythcommflag.sh /usr/LH/bin +# chmod +x /usr/LH/bin/pause-mythcommflag.sh +# Usage: Executed from sv start pause-mythcommflag + +# Threshold for when mythcommflag will be paused +CPUTHRESHOLD=75 + +# Second Threshold for when mythcommflag is already paused +PAUSEDCPUTHRESHOLD=45 + +# Log file to write (change to /dev/null for no log) +LOG=/var/log/mythtv/pause-mythcommflag.log + +# Number of seconds to wait between checking for mythcommflag process +SLEEP=5 + +#sleep $SLEEP + +touch $LOG + +COMMFLAGSTATE=1 + +while true; do + PROCCOMMFLAG=`pidof mythcommflag` + if [ -n "${PROCCOMMFLAG}" ] + then + FRONTENDCPU=`top -bn1u mythtv | grep mythfrontend | awk '{ print $9 }'` + if [ $COMMFLAGSTATE -eq 1 ] + then + CPUTHRESHOLD1=$CPUTHRESHOLD + else + CPUTHRESHOLD1=$PAUSEDCPUTHRESHOLD + fi + if [ "$FRONTENDCPU" -ge "$CPUTHRESHOLD1" ] + then +# echo "$(date) FE CPU $FRONTENDCPU% is greater than $CPUTHRESHOLD1%, PAUSE Commflagging" >> $LOG + kill -s STOP $PROCCOMMFLAG + COMMFLAGSTATE=0 + else +# echo "$(date) FE CPU $FRONTENDCPU% is less than $CPUTHRESHOLD1%, CONTINUE Commflagging" >> $LOG + kill -s CONT $PROCCOMMFLAG + COMMFLAGSTATE=1 + fi +# else +# echo "No COMMFLAG Process Active" >> $LOG + fi + sleep $SLEEP +done diff --git a/abs/core-testing/linhes-scripts/src/pause_mythcommflag b/abs/core-testing/linhes-scripts/src/pause_mythcommflag new file mode 100755 index 0000000..da9e659 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/pause_mythcommflag @@ -0,0 +1,7 @@ +/var/log/mythtv/pause-mythcommflag.log { + daily + rotate 7 + notifempty + copytruncate + compress +} diff --git a/abs/core-testing/linhes-scripts/src/run-limit-mythcommflag b/abs/core-testing/linhes-scripts/src/run-limit-mythcommflag new file mode 100755 index 0000000..38ca45f --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/run-limit-mythcommflag @@ -0,0 +1,2 @@ +#!/bin/sh +exec /usr/bin/nice -19 /usr/LH/bin/limit-mythcommflag.sh diff --git a/abs/core-testing/linhes-scripts/src/run-pause-mythcommflag b/abs/core-testing/linhes-scripts/src/run-pause-mythcommflag new file mode 100755 index 0000000..8bd25ac --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/run-pause-mythcommflag @@ -0,0 +1,2 @@ +#!/bin/sh +exec /usr/bin/nice -19 /usr/LH/bin/pause-mythcommflag.sh diff --git a/abs/core-testing/linhes-scripts/src/screenshooter.sh b/abs/core-testing/linhes-scripts/src/screenshooter.sh new file mode 100755 index 0000000..9e35786 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/screenshooter.sh @@ -0,0 +1,225 @@ +#!/bin/bash + +# Written by Bob Igo from the MythTV Store at http://MythiC.TV +# with contributions from TJC and Sarah Hayes +# Email: bob@stormlogic.com +# +# If you run into problems with this script, please send me email + +# This is alpha code to auto-generate thumbnails for previews in MythVideo. +# It won't currently work on some filenames that have spaces in them. +# It's surely just a matter of escaping or quoting, but I have yet to find +# the right incantation. + +# example usage: +# find -L /myth/video -wholename '*.covers' -prune -o -name '*.resume' -o -type f -exec screenshooter.sh -v {} \; + +# limitations: +# -- +# In an MBE/SBE/FE setup this might get the settings for the wrong machine... +# The script has no AI to know if a grabbed frame is useful to identify the video, only that it was able to grab it. +# Doesn't clean up after itself if videos are deleted, though MythTV may do this on its own. +# Minimum theoretical compatible video length is 4 seconds. Shorter videos will not work with this version. +# Surely more limitations I can't think of because it's my baby :) + +Usage() { + echo "USAGE:" + echo `basename $0` "-v PATHNAME [-s SECONDS] [-c] [-b HOSTNAME] [-u USERNAME] [-p PASSWORD] [-o]" + echo "-v: pathname to Video" + echo "-s: number of Seconds to skip before capturing (270 by default)" + echo "-c: Clobber any previous screenshot found for this video (off by default)" + echo "-b: mysql server (Backend) hostname (localhost by default)" + echo "-u: mysql Username (mythtv by default)" + echo "-p: mysql Password (mythtv by default)" + echo "-o: verbOse mode (off by default)" + echo "-x: check for valid video eXtension (off by default)" + echo + echo "EXAMPLE: $0 -v /myth/video/HDTV/shuttle.mpg -c -s 30" + exit 3 +} + +if [ -z $1 ]; then + Usage +fi + +V_MISSING=1 + +while getopts "v:sbupochx" FLAG ; do + case "$FLAG" in + v) VIDEO_PATHNAME="$OPTARG" + V_MISSING=0;; + s) SKIPAHEAD="$OPTARG";; + c) CLOBBER=1;; + b) BACKEND_HOSTNAME="$OPTARG";; + u) DBUSERNAME="$OPTARG";; + p) DBPASSWORD="$OPTARG";; + o) VERBOSE=1;; + x) EXTENSION_CHECK=1;; + *) Usage;; + esac +done + +if [ $V_MISSING == 1 ]; then + Usage +fi + +# Declaring Variables here and assigning sensible defaults. + +# SKIPAHEAD is the number of seconds to skip ahead before starting the frame capture. +# Set it to an arbitrary value if none is specified. +SKIPAHEAD=${SKIPAHEAD:-"270"} +BACKEND_HOSTNAME=${BACKEND_HOSTNAME:-"localhost"} +DBUSERNAME=${DBUSERNAME:-"mythtv"} +DBPASSWORD=${DBPASSWORD:-"mythtv"} +# Defaults to quiet. +VERBOSE=${VERBOSE:-0} +# Unless otherwise told, do not clobber existing cover files. +CLOBBER=${CLOBBER:-0} +# Unless otherwise told, do not check the file extension against +# MythTV's list of registered video file types. +EXTENSION_CHECK=${EXTENSION_CHECK:-0} + +VIDEO_CAPTURE_HOME=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select data from settings where value='VideoArtworkDir' limit 1") +if [ ! -d "$VIDEO_CAPTURE_HOME" ] ; then + echo "Directory $VIDEO_CAPTURE_HOME does not exist, nowhere to put the screen shot!" + echo "Have you configured MythVideo yet?" + exit 1 +fi + +VIDEO_HOME=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select data from settings where value='VideoStartupDir' limit 1") +if [ ! -d "$VIDEO_HOME" ] ; then + echo "Directory $VIDEO_HOME does not exist, nowhere to put the screen shot!" + echo "Have you configured MythVideo yet?" + exit 1 +fi + +VIDEO_FILENAME=$(basename "$VIDEO_PATHNAME") +VIDEO_EXTENSION=${VIDEO_FILENAME##*.} +# Since we cron'd lets first make sure the validity of the file +if [ "$EXTENSION_CHECK" == "1" ]; then + EXCHECK=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select f_ignore from videotypes where extension=\"$VIDEO_EXTENSION\";") + #excheck returns blank, it found nothing. + if [ "$EXCHECK" == "" ]; then + if [ "$VERBOSE" == "1" ]; then + echo "$VIDEO_EXTENSION does not appear to be a valid media file, skipping." + fi + exit 1 + else + # It is valid, but should we ignore it. If so then excheck will equal 1. + if [ "EXCHECK" == "1" ]; then + if [ "$VERBOSE" == "1" ]; then + echo "$VIDEO_EXTENSION is set to ignore." + fi + exit 1 + fi + # It is valid, it's not set to ignore. + if [ "$VERBOSE" == "1" ]; then + echo "$VIDEO_EXTENSION appears in the Database, checking further." + fi + EXCHECK=$(mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "select title from videometadata where filename=\"$VIDEO_PATHNAME\";") + #Right, the file is supposed to be playable. Has it been imported to the Db yet? + if [ "$EXCHECK" == "" ] ; then + if [ "$VERBOSE" == "1" ]; then + echo "$VIDEO_FILENAME does not exist in the database." + fi + exit 1 + # If you decide you want the system to 'auto import' the video then comment out + # the exit line and uncomment the rest of it. Bewarned, this is sucky SQL at + # the best but will give sensible defaults. + # + # if [ "$VERBOSE" == "1" ]; then + # echo "Importing $VIDEO_FILENAME in to database." + # fi + # mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -sNBe "insert into videometadata (intid, title, director, plot, rating, inetref, year, userrating, length, showlevel, filename, coverfile, childid, browse, playcommand, category) values (' ', '$VIDEO_FILENAME', 'Unknown', 'Unknown', 'NR', '00000000', 1895, 0.0, 0, 1, '$VIDEO_PATHNAME', 'No Cover', -1, 1, ' ', 0);" + fi + fi +fi + +if [ "$CLOBBER" -eq 0 ]; then + # Since we're not clobbering, first check to see if this video already has a coverfile entry in MySQL: + SQL_CMD="select coverfile from videometadata where filename=\"$VIDEO_PATHNAME\";" + CURRENT_COVERFILE=`mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -B -e "$SQL_CMD" | tail -1` + + if [[ "$CURRENT_COVERFILE" != "" ]] && [[ "$CURRENT_COVERFILE" != "No Cover" ]]; then + # there's already a cover file for this video + if [ "$VERBOSE" == "1" ]; then + echo "$VIDEO_FILENAME has cover file, skipping." + fi + exit 2 + fi +fi + + +# Swap the video file extension for png. Should work assuming the extension only appears ONCE! +VIDEO_CAPTURE_PATHNAME="$VIDEO_CAPTURE_HOME/$VIDEO_FILENAME.png" + +# How many frames of video to capture. We'll grab the last frame as our screenshot. +if [ "$VIDEO_EXTENSION" == "m4v" ]; then + FRAMES_TO_CAPTURE="90" + SHOTFILE="000000"$FRAMES_TO_CAPTURE".png" +else + FRAMES_TO_CAPTURE="05" +fi + +SHOTFILE="000000"$FRAMES_TO_CAPTURE".png" +VIDEO_STATS="/tmp/screenshooter_video_stats.txt" + +cd /tmp + +# The video we're processing may be shorter than SKIPAHEAD seconds. +# Keep trying to capture until we find a SKIPAHEAD value within the length of the video. +# Give up if we reach 0 seconds. +while [ ! -f "$SHOTFILE" ]; do + /usr/bin/mplayer -ss $SKIPAHEAD -vf scale=640:-2 -ao null -vo png -quiet -frames $FRAMES_TO_CAPTURE -identify "$VIDEO_PATHNAME" &> $VIDEO_STATS & + TIMEOUT=9 + + # Some video formats will play audio only. This loop gives the above command 20 seconds to + # finish, otherwise it gets killed. + while [ -n "`ps -p $! --no-heading`" ]; do + TIMEOUT=$(expr $TIMEOUT - 1) + if [ "$TIMEOUT" -le 0 ]; then + kill -9 $! + break + fi + sleep 1 + done + + SKIPAHEAD=$(expr $SKIPAHEAD / 2) + if [ "$SKIPAHEAD" -le 0 ]; then + break + fi +done + +if [ -f "$SHOTFILE" ]; then + # Now, the video_capture is taken, and the name of the shot is in $SHOTFILE + # Rename it and move it to the place where video_captures live. + /bin/mv -f "$SHOTFILE" "$VIDEO_CAPTURE_PATHNAME" + /bin/rm -f 000000*png + chown mythtv: "$VIDEO_CAPTURE_PATHNAME" + + # We've got the shotfile nailed, now calculate video run length. + VIDEO_LENGTH_IN_SECONDS=`grep ID_LENGTH $VIDEO_STATS | awk -F'=' '{print $2}'` + VIDEO_LENGTH_IN_INTEGER_SECONDS=${VIDEO_LENGTH_IN_SECONDS/%.*/} + if [ $VIDEO_LENGTH_IN_INTEGER_SECONDS -lt 60 ]; then + VIDEO_LENGTH_IN_MINUTES="1" + else + VIDEO_LENGTH_IN_MINUTES=$(expr $VIDEO_LENGTH_IN_INTEGER_SECONDS / 60) + fi + + SQL_CMD="update videometadata set length=\"$MIN_LENGTH\" where filename=\"$VIDEO_PATHNAME\";" + mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e "$SQL_CMD" + + + # put the screenshot pathname and any runlength info into videometadatatable + + # Pre-escape any single or double quotes for the SQL command. + + VIDEO_CAPTURE_PATHNAME=`echo $VIDEO_CAPTURE_PATHNAME | sed -e "s/'/\\\'/g" -e 's/"/\\\"/g' ` + VIDEO_PATHNAME=`echo $VIDEO_PATHNAME | sed -e "s/'/\\\'/g" -e 's/"/\\\"/g' ` + SQL_CMD="update videometadata set coverfile=\"$VIDEO_CAPTURE_PATHNAME\", length=\"$VIDEO_LENGTH_IN_MINUTES\" where filename=\"$VIDEO_PATHNAME\";" + + mysql -u $DBUSERNAME --password=$DBPASSWORD -h $BACKEND_HOSTNAME mythconverg -e "$SQL_CMD" +else + echo "No image could be captured from $VIDEO_PATHNAME" + exit 1 +fi diff --git a/abs/core-testing/linhes-scripts/src/shootscreens-mythtv.sh b/abs/core-testing/linhes-scripts/src/shootscreens-mythtv.sh new file mode 100755 index 0000000..db01147 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/shootscreens-mythtv.sh @@ -0,0 +1,11 @@ +#! /bin/bash +# available sizes: 34, 25, 24, 20, 18, 17, 14, 12, 11, 10 +export FONT="-adobe-helvetica-bold-*-*-*-34-*-*-*-*-*-*-*" +echo "This could take several minutes," > /tmp/screens +echo "depending on your hardware and the" >> /tmp/screens +echo "number and type of videos you have." >> /tmp/screens +echo "It will only work on videos scanned" >> /tmp/screens +echo "with Video Manager." >> /tmp/screens +cat /tmp/screens | osd_cat --font=$FONT --shadow=3 --pos=middle --align=centre --offset=200 --color=yellow --delay=0 & +shootscreens.sh 1 +/bin/rm -f /tmp/screens
\ No newline at end of file diff --git a/abs/core-testing/linhes-scripts/src/shootscreens.sh b/abs/core-testing/linhes-scripts/src/shootscreens.sh new file mode 100755 index 0000000..7b1260c --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/shootscreens.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Written by Bob Igo from the MythTV Store at http://MythiC.TV +# Email: bob@stormlogic.com +# +# If you run into problems with this script, please send me email + +# This code generates screenshots (cover files) for all videos in +# MythTV's videometadata table that do not have covers associated with them. + +if [ "$1" == "1" ]; then + OSD=1 +else + OSD=0 +fi + +> /tmp/shooter.log +{ + percentage=0 + # Change IFS to be a newline so that filenames with spaces will be handled properly. + IFS=$'\n' + vidcount=`mysql -u root mythconverg -B -e "select filename from videometadata where coverfile=\"No Cover\";" | wc -l` + increment=$(expr 100 / $vidcount) + for vid in `mysql -u root mythconverg -B -e "select filename from videometadata where coverfile=\"No Cover\";" | grep -v -e "^filename$"` + do + if [ $OSD == 1 ]; then + osd_cat --barmode=percentage --percentage=$percentage --pos=middle --align=center --color=white --text="Generating Video Thumbnails..." --font=$FONT --shadow=3 --color=yellow --delay=0 & + percentage=$(expr $percentage + $increment) + fi + + screenshooter.sh -v $vid + done + if [ $OSD == 1 ]; then + killall -9 osd_cat + osd_cat --barmode=percentage --percentage=100 --pos=middle --align=center --color=white --text="Video Thumbnails Generated!" --font=$FONT --shadow=3 --color=yellow --delay=3 & + fi +}
\ No newline at end of file diff --git a/abs/core-testing/linhes-scripts/src/vdpau-detector b/abs/core-testing/linhes-scripts/src/vdpau-detector new file mode 100755 index 0000000..c8cd155 --- /dev/null +++ b/abs/core-testing/linhes-scripts/src/vdpau-detector @@ -0,0 +1,103 @@ +#!/bin/bash + +# This script written by an anonymous author +# Original page http://www.knoppmythwiki.org/index.php?page=HardwareAcceleratedVideo +# +# It's modded to allow vdpau switches commands to pass to a modded version of Bob Igo's +# mplayer-resumer.pl wrapper for mplayer +# +# User can customize commandline for mplayer by editing the appropriate sections below +# They include BASIC_OPTS, NOHD_OPTS, and LOW_OPTS + +IAM=$0 +FILE=$1 + +#if no input display usage +if [[ -z "$FILE" ]]; then + echo usage: $0 /path/to/file + exit +fi + +MPLAYER="/usr/bin/mplayer" + +# For a complete list of options, see the mplayer DOCS +# http://www.mplayerhq.hu/DOCS/man/en/mplayer.1.html +# + +# Options for all videos: fullscreen, zoom, and use software eq +BASIC_OPTS="-fs -zoom" + +# Options for non-HD videos: force aspect to 16x10 (to ensure video fills TV screen) +# You'll need to modify the ratio if your res differs +# Example: 1920x1080 = 1.778 = 16:9 +# Example: 1680x1050 = 1.600 = 16:10 +# Example: 1280x720 = 1.778 = 16:9 + +NOHD_OPTS="-aspect 16:10" + +# Options for normal and lowres videos: use XV forcing 16x10 +LOW_OPTS="-aspect 16:10 -vo xv" + +VWIDTH=$($MPLAYER -identify -vo vdpau -frames 0 "$FILE" | grep ID_VIDEO_WIDTH | cut -c 16-25) +VCODEC=$($MPLAYER -identify -vo vdpau -frames 0 "$FILE" | grep ID_VIDEO_CODEC | cut -c 16-25) + +# all following echo commands can be uncommented for debug info +#echo . +#echo " DEBUG info: video codec: $VCODEC" +#echo " DEBUG info: video width: $VWIDTH" +#echo " Debug info: + + +# Test for codec, if it's supported by VDPAU, set options to use it. Then, check if the video is in HD, +# and if it's not, set non-HD options. +case $VCODEC in +ffh264) + #echo -e "Playing h.264 file $FILE:\n" + MPLAYEROPTS="$BASIC_OPTS -vo vdpau -vc ffh264vdpau" + if [ $VWIDTH -lt 1280 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$MPLAYEROPTS $NOHD_OPTS" + fi + if [ $VWIDTH -lt 700 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$BASIC_OPTS $LOW_OPTS" + fi + ;; +ffmpeg2) + #echo -e "Playing MPEG2 file $FILE:\n" + MPLAYEROPTS="$BASIC_OPTS -vo vdpau -vc ffmpeg12vdpau" + if [ $VWIDTH -lt 1280 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$MPLAYEROPTS $NOHD_OPTS" + fi + if [ $VWIDTH -lt 700 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$BASIC_OPTS $LOW_OPTS" + fi + ;; +ffwmv3) + #echo -e "Playing WMV3 file $FILE:\n" + MPLAYEROPTS="$BASIC_OPTS -vo vdpau -vc ffwmv3vdpau" + if [ $VWIDTH -lt 1280 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$MPLAYEROPTS $NOHD_OPTS" + fi + if [ $VWIDTH -lt 700 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$BASIC_OPTS $LOW_OPTS" + fi + ;; +# VC-1 is largely unsupported by nvidia - uncomment this section if you're sure your card supports it. +ffvc1) + #echo -e "Playing VC-1 file $FILE:\n" + MPLAYEROPTS="$BASIC_OPTS -vo vdpau -vc ffvc1vdpau" + if [ $VWIDTH -lt 1280 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$MPLAYEROPTS $NOHD_OPTS" + fi + if [ $VWIDTH -lt 700 ] && [ $VWIDTH != 0 ]; then + MPLAYEROPTS="$BASIC_OPTS $LOW_OPTS" + fi + ;; +*) + #echo -e "Playing normal file $FILE:\n" + # Use XV and yadif filter with 'normal' (DiVX, XViD, old WMV, etc.) files, and force 16:9 + # -vf filters only seem to work with XV, or at least they don't work w/VDPAU + MPLAYEROPTS="$BASIC_OPTS $LOW_OPTS" + ;; +esac + +echo $MPLAYEROPTS |