Hi all,
I have a stack of computers I use to encode video files using handbrakeCLI. I call them drones. I have written a universal script for them, which works GREAT.
Yesterday, I decided that it would be nice to have a simple web page for monitoring the drones as they work their way through their queues. So, I built a very simple HTML file and PHP files to pull the log information from the running process using only the STDERR (i.e. 2> Output.txt) and that worked, but did not contain the information I wanted.
What I am looking for is the STDOUT info which contains the percentage of completion, some stats, and the ETA of completion.
The problem is that, apparently the STDOUT for handbrakeCLI doesn't use any kind of CR or /n or /r, so my PHP files (which are coded to pull only the last line of the txt file(s)) wind up pulling in like 3K lines of logging...which is NOT what I was expecting.
I have been at this for over 12 hours. I have run countless searches to try to find an answer to my dilemma, but have come up short.
The command being run by my parsing script is as follows:
HandBrakeCLI -i "$i" -o "$of" --preset-import-gui -Z "$SIXCHANTVE1080PS" --srt-file "$fn.srt" --srt-burn >> "$LOGFILE2" 2>&1
The PHP I am using for pull only the last line of $LOGFILE2 is as follows:
<?php
$file = '/Shares/FalcorSAN-XL/Status/VidEnc1-2.txt';
$escaped_file = escapeshellarg($file);
if (file_exists($file)) {
$escaped_file = escapeshellarg($file);
$lastLine = `tail -n 1 $escaped_file`;
echo trim($lastLine);
} else {
echo "Powered off - NOT READY";
}
?>
For all other notifications prior to and after the handbrakeCLI command (above), everything works wonderfully and very quickly.
I guess I just don't understand how to parse the STDOUT directly from handbrakeCLI in a way that results in a SINGLE line.
Yes, I want "Encoding: task 1 of 2, 34.25 % (73.24 fps, avg 75.31 fps, ETA 00h09m37s), but I do NOT want the 1200 lines prior to it.
Someone, please...put me out of my misery and point out the excruciatingly simple fix I haven't thought of, stumbled across, or am simply too tired/drained to figure out on my own...
I should point out that I am using a debian-based linux distro (Ubuntu), my drone script is written in bash, and the script works in every way EXCEPT this.
Hell, maybe it isn't even the handbrakeCLI command but the PHP script...
TIA