| #!/bin/bash |
| |
| function printUsage() { |
| echo |
| echo |
| echo "Usage:" |
| echo " probatron path/to/raw/file desired/transcoded/filename [settop IP]" |
| echo |
| echo "The probatron automates the process of transcoding a raw input file " |
| echo "as the miniclient would and analyzing it against all of the *.ts_* HLS " |
| echo "segments in the local directory, checking for issues. Issues that " |
| echo "appear in just the HLS analysis point to a miniclient problem. Issues " |
| echo "that appear in the transcoded or both analyses) point to a BroadCom issue." |
| echo |
| echo "The probatron will use \$DVR_BOX as the default settop to use for " |
| echo "transcoding, but you can specify a different IP by passing it as the " |
| echo "third parameter." |
| echo |
| echo "The analysis tools require dvbsnoop and ffmpeg! It also needs gnuplot to " |
| echo "print pretty graphs, but that's optional." |
| echo |
| echo " 'apt-get install dvbsnoop ffmpeg gnuplot'" |
| echo |
| |
| exit |
| } |
| |
| ################################### |
| |
| function checkReturnCode() { |
| ## Uncomment next line to debug - force keystroke after most commands |
| #read -n 1 |
| if [ $? != 0 ] |
| then |
| exit |
| fi |
| } |
| |
| ## Sanitize args |
| |
| if [ $# -lt 2 ] |
| then |
| printUsage |
| fi |
| |
| INPUT_FILE=$1 |
| TRANSCODED_PATH=$2 |
| TRANSCODED_FILENAME=$(basename $TRANSCODED_PATH) |
| SETTOP_IP=$3 |
| |
| if [[ "$SETTOP_IP" == "" ]] |
| then |
| SETTOP_IP=$DVR_BOX |
| if [[ "$SETTOP_IP" == "" ]] |
| then |
| echo |
| echo " Settop IP not provided and \$DVR_BOX is not set!" |
| printUsage |
| fi |
| fi |
| |
| ## Get duration of input file, for the probe |
| TIME_HHMMSS=$(ffprobe -i $INPUT_FILE 2>&1 | grep "Duration" | awk '{split($2, a, "."); print a[1]}') |
| IFS=: read -r h m s <<<"$TIME_HHMMSS" |
| DURATION=$(((h * 60 + m) * 60 + s)) |
| |
| ## Let's Get To Work! |
| |
| if [ -e "$INPUT_FILE" ] |
| then |
| CURRENT_DIR=$(pwd) |
| ## Upload the raw file, and the prober |
| echo |
| echo "Uploading $INPUT_FILE to $SETTOP_IP" |
| ssh root@$SETTOP_IP "rm -f /var/media/videos/raw.mpg" |
| scp $INPUT_FILE root@$SETTOP_IP:/var/media/videos/raw.mpg |
| checkReturnCode |
| |
| echo |
| echo "Building Probe" |
| echo |
| ##### TODO: Fix this when the build is proper-like |
| cd probe/ |
| make |
| checkReturnCode |
| echo |
| echo "Uploading Probe" |
| ssh root@$SETTOP_IP "rm -f /rw/probe" |
| scp probe root@$SETTOP_IP:/rw/ |
| checkReturnCode |
| cd $CURRENT_DIR |
| ##### |
| |
| ## Wait for transcoding to complete |
| echo |
| echo "Starting Transcode..." |
| echo |
| # Stop miniclient as it interferes with the probe, then restore it after... |
| ssh root@$SETTOP_IP 'stop miniclient' |
| # Keep app up until we press a key to kill it - without doing that probe never stops! TODO Fix this in the probe |
| #ssh root@$SETTOP_IP "/rw/probe /var/media/videos/raw.mpg /var/media/videos/$TRANSCODED_FILENAME & read -n 1; kill \$!" |
| ssh root@$SETTOP_IP "/rw/probe /var/media/videos/raw.mpg /var/media/videos/$TRANSCODED_FILENAME $DURATION" |
| ssh root@$SETTOP_IP 'start miniclient' |
| |
| ## Capture the transcoded file and analyze it |
| echo |
| echo "Downloading Transcoded file..." |
| scp root@$SETTOP_IP:/var/media/videos/$TRANSCODED_FILENAME $TRANSCODED_PATH |
| checkReturnCode |
| |
| if [ -e "$TRANSCODED_PATH" ] |
| then |
| echo |
| ./analyzer $TRANSCODED_PATH |
| else |
| echo |
| echo "Failed to retrieve $TRANSCODED_PATH!" |
| fi |
| |
| else |
| echo |
| echo " The file $INPUT_FILE doesn't exist!" |
| printUsage |
| fi |
| |