2

Bit of a noob question, I know...

I want to batch convert my videos to h265, which I can do with the help of Zernity and ffmpeg, but I'm having a little problem with the progress bar, in that there isn't one.

The actual "meaty bit" works wonderfully, with or without the last part, which is:

zenity --pulsate --title "Processing " --text "${filename} " --pulsate --auto-close --auto-kill

The whole code is:

d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory"  --directory)"
d2="$(zenity  --file-selection --title="Bulk Move    Choose destination directory"  --directory)"
if [ "$?" != 0 ]; then
   exit
fi
##
for i in "$d1"/*
  do
## filter out the actual file name
  filename=$(basename -- "$i")
## the meaty bit
ffmpeg -i "$i" -c:v libx265 -preset medium -x265-params crf=28 -c:a aac -strict experimental -b:a 128k "$d2"/"${filename%.*}.mkv" ; done | zenity --pulsate --title "Processing " --text "${filename} " --pulsate --auto-close --auto-kill

The only way I know it's working is by either calling the script on a command line and watching the ffmpeg (very verbose) output, or monitoring CPU usage.

Can someone point me in the right direction?

Thanks

user256787
  • 39
  • 1
  • 5

1 Answers1

2

You aren't checking if the starting directory was aborted only the destination directory. Also you can shorten if - then - fi like this:

d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory"  --directory)"
[[ "$?" != 0 ]] && exit
d2="$(zenity  --file-selection --title="Bulk Move    Choose destination directory"  --directory)"
[[ "$?" != 0 ]] && exit

This gives double the amount of abort checking with 1 less line of code.

To test the progress bar on any system use this:

$ for i in ./* ; do echo $i ; sleep .1 ;  done | zenity --pulsate --title "Processing " --text "${filename} " --pulsate --auto-close --auto-kill

--pulsate is not supported for this dialogue

Ah there is an error message! --progress is missing to tell zenity a progress bar is desired. So the working script would be:

d1="$(zenity  --file-selection --title="Bulk Move    Choose starting directory" \
    --directory)"
[[ "$?" != 0 ]] && exit

d2="$(zenity  --file-selection --title="Bulk Move    Choose destination     directory" \
    --directory)"
[[ "$?" != 0 ]] && exit

for i in "$d1"/* ; do

    ## filter out the actual file name
    filename=$(basename -- "$i")
    ## the meaty bit
    ffmpeg -i "$i" -c:v libx265 -preset medium -x265-params crf=28 \
        -c:a aac -strict experimental -b:a 128k "$d2"/"${filename%.*}.mkv"

done | zenity --progress --pulsate --title "Processing " \
              --text "ffmpeg - convert files" \
              --pulsate --auto-close --auto-kill

Passing ${filename} to --text option will not update display with each file name processed. If you want this you will need to switch to yad (Yet Another Dialog) which is a super-charged version of zenity:

yad-progress-bar.gif

Although the source code appears in the .gif you can copy and paste in your own script from this Q&A:

  • Thanks for your help.
    It works very well, except the filename doesn't come up.
    2 pulsates?
    Your extra bit about testing a progress bar is interesting in that maybe I could use it to show percentage of files done, instead of pulsate.
    – user256787 Oct 18 '19 at 15:08
  • @user256787 I've added filename handling the only way I know it can be done. Also percentage complete has been added which you can still use in zenity if you like. – WinEunuuchs2Unix Oct 20 '19 at 13:40
  • Tried yad. Promising, but the filename scrolls off the "current filename" immediately, and its window is only one line high. – user256787 Oct 22 '19 at 12:55
  • Sounds like --log-height=250 is missing or incorrect. You can post a question on this problem if unable to fix. – WinEunuuchs2Unix Oct 22 '19 at 15:02