Filter multiple items from the output of a long running command
2
votes
1
answer
428
views
**TLDR:**
How do I run handbrakecli, get progress **and** ETA, pipe into dialog without flickering.
**Details:**
I have a script that finds all video files in a directory and then runs handbrakecli on them one at a time. Everytime handbrakecli runs it spits out a bunch of information about the file etc. and then the line:
Encoding: task 1 of 1, 3.30 % (295.53 fps, avg 303.23 fps, ETA 00h02m54s)
In my script I pipe the handbrakecli command to some other commands to filter out everything except the progress and then I pipe that to dialog like so:
**Snippet 1**
HandBrakeCLI --preset "Normal" -i "$f" -o "$DEST" | \
stdbuf -o0 tr -s '\r' '\n' | \
stdbuf -o0 grep -oP '(?<=, )\d+(?=\.\d\d \%)' | \
dialog --gauge "$DIALOG_MSG" 10 70;
This works fine. It shows the progress and it doesn't flicker. Second task was to come up with a way to show both the progress AND the ETA and this is what I came up with:
**Snippet 2**
HandBrakeCLI --preset "Normal" -i "$f" -o "$DEST_FULL_FILE" | \
stdbuf -oL tr -s '\r' '\n' | \
while read -r str; do
local REMAINING=$(echo "$str" | grep -oP "(?<=ETA )\d\dh\d\dm\d\ds(?=\))");
local PROGRESS=$(echo "$str" | grep -oP "(?<=, )\d+(?=.\d\d)");
echo "$PROGRESS" | dialog --gauge "$DIALOG_MSG Time remaining: $REMAINING" 10 70;
done
This works but the dialog window flickers. I don't know if it's performance related (doubt it) or if the whole *while read* loop just doesn't work well with dialog.
I also tried doing it without piping to dialog but that just showed dialog once and then didn't update it at all.
**Snippet 3**
HandBrakeCLI --preset "Normal" -i "$f" -o "$DEST_FULL_FILE" | \
stdbuf -oL tr -s '\r' '\n' | \
while read -r str; do
local REMAINING=$(echo "$str" | grep -oP "(?<=ETA )\d\dh\d\dm\d\ds(?=\))");
local PROGRESS=$(echo "$str" | grep -oP "(?<=, )\d+(?=.\d\d)");
dialog --gauge "$DIALOG_MSG Time remaining: $REMAINING" 10 70 $PROGRESS;
done
Finally I tried this:
**Snippet 4**
HandBrakeCLI --preset "Normal" -i "$f" -o "$DEST_FULL_FILE" | \
stdbuf -o0 tr -s '\r' '\n' | (
read -r str;
local REMAINING=$(echo "$str" | grep -oP "(?<=ETA )\d\dh\d\dm\d\ds(?=\))");
local PROGRESS=$(echo "$str" | grep -oP "(?<=, )\d+(?=.\d\d)");
echo "$PROGRESS";
) | dialog --gauge "$DIALOG_MSG Time remaining: $REMAINING" 10 70;
And that didn't work out well at all.
I'm aware there are some fundamental things wrong here.
Asked by Peter Lee
(23 rep)
Jul 30, 2017, 05:53 PM
Last activity: Aug 6, 2017, 12:01 PM
Last activity: Aug 6, 2017, 12:01 PM