I have a script to cut/trim media files - initial details here and here; after some more recent adjustments adjustments it looks like this:
#!/bin/bash
INPUT=$1
eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" "${INPUT/%.}-out.${INPUT##.}" | awk -F'|' '{printf "START=%s\nEND=%s\nOUTPUT="%s"\n", $1, $2, $3}')
[[ -z $START || -z $END || -z $OUTPUT ]] && exit 1
DIFF=$(($(date +%s --date="$END")-$(date +%s --date="$START")))
OFFSET=""$(($DIFF / 3600)):$(($DIFF / 60 % 60)):$(($DIFF % 60))
$(ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -c copy "$OUTPUT")
(for i in $(seq 0 3 100); do echo "$i"; sleep 0.1; done) | zenity --progress --width=400 --auto-close
if [ $? -eq 0 ]; then
kdialog --msgbox "Process completed successfully!"
else
kdialog --msgbox "SOMETHING WENT WRONG!"
fi
It includes a line to show the progress of ffmpeg process with zenity.
~$ zenity --help-progress
Usage:
zenity [OPTION…]
Progress options
--progress Display progress indication dialog
--text=TEXT Set the dialog text
--percentage=PERCENTAGE Set initial percentage
--pulsate Pulsate progress bar
--auto-close Dismiss the dialog when 100% has been reached
--auto-kill Kill parent process if Cancel button is pressed
--no-cancel Hide Cancel button
--time-remaining Estimate when progress will reach 100%
but just using zenity --progress --percentage=1 shows no real progress, the only useful option seems to be to use --pulsate, which at least shows something is happening with a line that goes back and forth.
ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -c copy "$OUTPUT" | zenity --width=400 --progress --pulsate --text="Running" --percentage=1 --auto-close --auto-kill
Trying to mimic this answer I do get a progress bar, but that is shown after the process has ended and the progress itself has nothing to do with the real process.
$(ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -c copy "$OUTPUT")
(for i in $(seq 0 3 100); do echo "$i"; sleep 0.1; done) | zenity --progress --width=400
When I try to use something like this, and the script is adjusted like this
#!/bin/bash
(
INPUT=$(kdialog --getopenfilename ~/Videos/ '.m4a .ogg .mp3 .mp4 .avi .aac .flac .avi .mkv .mp4')
echo "5"
eval $(yad --width=400 --form --field=start --field=end --field=output:SFL "00:00:00" "00:00:00" "${INPUT/%.}-out.${INPUT##.}" | awk -F'|' '{printf "START=%s\nEND=%s\nOUTPUT="%s"\n", $1, $2, $3}')
[[ -z $START || -z $END || -z $OUTPUT ]] && exit 1
DIFF=$(($(date +%s --date="$END")-$(date +%s --date="$START")))
echo "5"
OFFSET=""$(($DIFF / 3600)):$(($DIFF / 60 % 60)):$(($DIFF % 60))
echo "10"
echo "# Running processing task." ; sleep 1
echo "35"
echo "# Running processing task." ; sleep 1
echo "60"
echo "# Running processing task." ; sleep 1
echo "85"
echo "# Running processing task." ; sleep 1
echo "99"
echo "# Running processing task." ; sleep 1
ffmpeg -ss "$START" -t "$OFFSET" -i "$INPUT" -c copy "$OUTPUT"
echo "# All finished." ; sleep 1
echo "100"
I get a progress bar but the progress bar is shown before the actual process takes place.
The question is:
How to have something like in the image above, but synchronized in real time with the actual ffmpeg process?

