$pluginName = "MatrixMessage";
$fpp_matrixtools_Plugin = "fpp-matrixtools";
$fpp_matrixtools_Plugin_Script = "scripts/matrixtools";
$FPP_MATRIX_PLUGIN_ENABLED = false;
$logFile = $settings['logDirectory'] . "/" . $pluginName . ".log";
$P10Matrix = urldecode(ReadSettingFromFile("P10Matrix", $pluginName));
echo "outputing video!!! \n";
$VIDEO_PATH = "/home/pi/media/effects/";
$IMAGE_BASE = "image-";
$IMAGE_EXT = ".jpg";
$FPPMM = "/opt/fpp/bin/fppmm";
$NUM_OF_FRAMES = 1200;
$CONVERT_BINARY = "/usr/bin/convert";
$frame = 0;
for ($frame = 0; $frame <= $NUM_OF_FRAMES; $frame++) {
    $cmd = $CONVERT_BINARY . " -scale '32x16!' -depth 8 " . $VIDEO_PATH . $IMAGE_BASE . $frame . $IMAGE_EXT . " rgb:" . $VIDEO_PATH . "RGB" . $IMAGE_BASE . $frame . $IMAGE_EXT;
    //convert the image and then output it to the fppmm
    //$cmd = "cat ".$VIDEO_PATH.$IMAGE_BASE.$frame.$IMAGE_EXT. " > /home/pi/matrix";
    //exec($cmd);
    echo "CMD: " . $cmd . "\n";
}
$frame = 0;
for ($frame = 0; $frame <= $NUM_OF_FRAMES; $frame++) {
    $cmd = $FPPMM . " -m " . $P10Matrix . " -f " . $VIDEO_PATH . $IMAGE_BASE . $frame . $IMAGE_EXT;
    //convert the image and then output it to the fppmm
    //$cmd = "cat ".$VIDEO_PATH.$IMAGE_BASE.$frame.$IMAGE_EXT. " > /home/pi/matrix";
    exec($cmd);
    //	echo "CMD: ".$cmd."\n";
}
clearMatrix();
///Users/bshaver/ffmpeg/ffmpeg -i /Users/bshaver/Movies/Halloween.mp4 -r 20 -vframes 120 -vf scale=32:16 -f image2 /Volumes/FPP/FPP3/effects/image-%1d.jpg
function outputMessages($queueMessages)
{
    global $pluginDirectory, $MESSAGE_TIMEOUT, $fpp_matrixtools_Plugin, $fpp_matrixtools_Plugin_Script, $Matrix, $MATRIX_FONT, $MATRIX_FONT_SIZE, $MATRIX_PIXELS_PER_SECOND, $COLOR, $INCLUDE_TIME, $TIME_FORMAT, $HOUR_FORMAT, $SEPARATOR;
    //print_r($queueMessages);
    if (count($queueMessages) <= 0) {
        //	echo "No messages to output \n";
        return;
    }
    if (strtoupper(trim($COLOR)) == "RANDOM") {
        //print_r ("Start counter");
        $counter = rand(0, 5);
        //print_r ("Start switch");
        switch ($counter) {
            case "0":
                $mycolor = "indigo";
                //echo $mycolor;
                break;
            case "1":
                $mycolor = "red";
                //echo $mycolor;
                break;
            case "2":
                $mycolor = "green";
                //echo $mycolor;
                break;
            case "3":
                $mycolor = "blue";
                //echo $mycolor;
                break;
            case "4":
                $mycolor = "yellow";
                //echo $mycolor;
                break;
            case "5":
                $mycolor = "purple";
                //echo $mycolor;
                break;
        }
        logEntry("Selecting RANDOM COLOR: " . $mycolor);
        //print_r ("End switch");
        $COLOR = $mycolor;
        //print_r ($COLOR);
    }
    enableMatrixToolOutput();
    for ($i = 0; $i <= count($queueMessages) - 1; $i++) {
        $messageText = "";
        if ($INCLUDE_TIME == 1 || $INCLUDE_TIME == "on") {
            switch ($HOUR_FORMAT) {
                case "12":
                    $messageTime = date($TIME_FORMAT);
                    break;
                case "24":
                    $messageTime = date($TIME_FORMAT);
                    break;
            }
            logEntry("Message time: " . $messageTime);
            $messageText = "Time: " . $messageTime . " " . $SEPARATOR . " ";
        }
        //for($i=0;$i<=count($queueMessages)-1;$i++) {
        $messageParts = explode("|", $queueMessages[$i]);
        //echo "0: ".$messageParts[0]."\n";
        //echo "1: ".$messageParts[1]."\n";
        //echo "2: " .$messageParts[2]."\n";
        //echo "3: ".$messageParts[3]."\n";
        $messageText .= urldecode($messageParts[1]);
        //echo "Sending message: ".$messageText." to matrix FIFO\n";
        $cmd = $pluginDirectory . "/" . $fpp_matrixtools_Plugin . "/" . $fpp_matrixtools_Plugin_Script . " --blockname \"" . $Matrix . "\" --color '" . $COLOR . "' --font " . $MATRIX_FONT . " --fontsize " . $MATRIX_FONT_SIZE . " --pixelspersecond " . $MATRIX_PIXELS_PER_SECOND . " --message \"" . urldecode($messageText) . "\"";
        //echo "p10 output cmd: ".$cmd."\n";
        logEntry("Matrix output cmd: " . $cmd);
        exec($cmd, $outputResults);
        //print_r($outputResults);
        //	$cmd = "/bin/echo \"".$messageText. "\" > ".$matrixFIFO;
        //	exec($cmd,$output);
        //echo "sleeping ".$MESSAGE_TIMEOUT. " sending clear line then";
        //	echo "sleeping: ".$MESSAGE_TIMEOUT." before clear \n";
        //	sleep($MESSAGE_TIMEOUT);
        sleep(1);
        clearMatrix();
        //$clearLineCmd = "/bin/echo \"\" > ".$matrixFIFO;
        //exec($clearLineCmd,$clearOutput);
    }
}