0

Is there a progress bar that can show visually completed progress based on the number of detected files found and completed in a for loop like the one below?

mkdir -p hflip; for i in *.mp4; do ffmpeg -n -i "$i" -vf hflip -c:a copy hflip/"${i%.*}.mp4"; done
  • Did one of the answers solve your problem? Then please close the question by marking the answer – Philippos Jun 3 at 5:45
1

Try something like this for a simple solution (you need the tqdm package):

for i in *.EXT; do PROGRAM OPTION1 OPTION2 "$(echo $i|tqdm)"; done

assuming there are no "funny" characters in your filenames.

  • How to make it work with this command? I have tried many ways but keep failing. mkdir -p hflip; for i in *.mp4; do ffmpeg -n -i "$i" -vf hflip -c:a copy hflip/"${i%.*}.mp4"; done I also updated my question, very sorry about the change. – Anonymous Jun 7 at 19:21
1

I suggest to keep a string for the progress bar, fill it with some character for each file and replace them with another during your loop:

bar=""; for i in *.EXT; do bar=$bar-; done; for i in *.EXT; do PROGRAM OPTION1 OPTION2 "$i"; bar=${bar/-/=}; printf "%s\r" $bar; done

But since your ffmpeg gives output, it will interfere with the printing of the progress bar. You could redirect the output to /dev/null not to see it at all, but it may be good to know if something went wrong, so I suggest to redirect it into log files for stdout and stderr, this time printed as multi-line script to make it more readable:

mkdir -p hflip 
bar=""
for i in *.mp4; do
  bar=$bar-
done
for i in *.mp4; do
  ffmpeg -n -i "$i" -vf hflip -c:a copy hflip/"${i%.*}.mp4" > /tmp/log.out 2> /tmp/log.err
  bar=${bar/-/=}
  printf "%s\r" $bar
done
more /tmp/log.err

This will display the log with all errors after processing the files. You can also display the log.out, but because this is about ffmpeg, it likes to output a lot of stuff most people don't want to read. (-;

  • This code is making my ffmpeg commands give me No such file or directory errors, also I could not see a progress bar anywhere. – Anonymous May 27 at 6:54
  • 1
    1) Try with a dummy command like sleep 1 if this progress bar is what you are looking for. 2) Your command is not changed; if it worked before, it still works; if it fails, it did fail before. 3) Of course, if your command produces output, it will interfere with the progress bar. ffmpeg is extremely chatty, so you need to redirect its output (to a logfile or /dev/null) to avoid it. If you want a progress bar and to see the program output, you need to define it, because obviously, there can't be a general solution. Name your command and expected way to deal with the output and bar. – Philippos May 27 at 8:55
  • Ohhh I see! Thank you! So how can I redirect output of a script.sh and see a progress bar instead? – Anonymous May 28 at 15:00
  • I edited my answer to demonstrate the redirection. Good luck. – Philippos May 28 at 15:39
  • Sorry, would you mind editing your answer once more and use this instead? mkdir -p hflip; for i in *.mp4; do ffmpeg -n -i "$i" -vf hflip -c:a copy hflip/"${i%.*}.mp4"; done I updated my question, very sorry for the change. Hope this is okay. – Anonymous Jun 7 at 19:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.