私は2つの選択肢を提案します

私は2つの選択肢を提案します

以下のような for ループで検出され完了したファイルの数に基づいて、完了した進行状況を視覚的に表示できる進行状況バーはありますか?

mkdir -p hflip; for i in *.mp4; do ffmpeg -n -i "$i" -vf hflip -c:a copy hflip/"${i%.*}.mp4"; done

答え1

進行状況バー用の文字列を保持し、各ファイルの文字を入力して、ループ中に別の文字に置き換えることをお勧めします。

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

しかし、 はffmpeg出力を行うため、プログレス バーの印刷が妨げられます。 出力を にリダイレクトして/dev/nullまったく表示しないようにすることもできますが、何か問題が発生したかどうかを知ることは良いことかもしれません。そこで、 と のログ ファイルにリダイレクトすることをお勧めします。stdout今回stderrは、読みやすくするために複数行のスクリプトとして印刷します。

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

これにより、ファイルを処理した後、すべてのエラーを含むログが表示されます。 を表示することもできますlog.outが、これは に関するものなのでffmpeg、ほとんどの人が読みたくないような内容が大量に出力されます。(-;

答え2

簡単な解決策としては、次のようなものを試してみてください(tqdmパッケージ):

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

ファイル名に「変な」文字が含まれていないことを前提としています。

答え3

私は2つの選択肢を提案します

1.bashシェルスクリプトを使用してpv継続的に進行状況を表示する

インストールpv

sudo apt install pv  # in Debian and Ubuntu, other commands in other distros

デモプログラム付きシェルスクリプト

#!/bin/bash

# if only files (if directories, you may need another command)

cnt=0
for i in dir/*
do
 cnt=$((cnt+1))
done
files="$cnt"
> log
> err
for i in dir/*
do
 ls "$i" >> log 2>> err  # simulating the actual process
 sleep 2                 # simulating the actual process
 echo "$i"
done | pv -l -s "$files" > /dev/null  # progress view using lines with $i

デモ

プロセス中

$ ./pver
2.00  0:00:06 [0,00 /s] [===============>                        ] 40% ETA 0:00:09

終了後

$ ./pver
5.00  0:00:10 [ 499m/s] [======================================>] 100%

2.bash必要に応じて現在の進行状況を表示するシェルスクリプト

  • forバックグラウンドでループし、programカウンターを実行しますcnt
  • while文字入力を探すループ(もしあればc、進行状況を知らせる)

進行状況バーはありませんが、いつでも進行状況に関するステータス更新を取得できます。

デモプログラム付きシェルスクリプト

#!/bin/bash

cnt=0
echo "0" > clog

program () {

ls "$1"
sleep 5
}

# main

files=$(ls -1 dir|wc -l)

for i in dir/*
do
    program "$i"
    cnt=$((cnt+1))
    echo "$cnt" > clog
done > log &

while [ "$cnt" != "$files" ]
do
 cnt=$(cat clog)
 read -sn1 -t1 chr
 if [ "$chr" == "c" ]
 then
  echo "$cnt of $files files processed; running ..."
 fi
done
echo "$cnt of $files files processed; finished :-)"

デモ

$ ./loop
0 of 5 files processed; running ...
3 of 5 files processed; running ...
5 of 5 files processed; finished :-)

$ cat log
dir/file1
dir/file2
dir/file3
dir/file4
dir/file w space

関連情報