zenity 진행 표시줄을 사용하여 스크립트 종료

zenity 진행 표시줄을 사용하여 스크립트 종료

(GNOME2, Ubuntu 10.04 LTS) 다양한 코덱으로 가득 찬 디렉토리가 있는 경우 폴더 -> 스크립트 -> THISSCRIPT.txt를 마우스 오른쪽 버튼으로 클릭하면 모든 비디오 파일을 재귀적으로 변환할 수 있도록 노틸러스 스크립트를 만들었습니다( 비디오 MIME 유형으로 식별됨)를 x.264 코덱으로 변환합니다. 여기서 128Kbit mp3는 avi입니다. 이렇게 하면 작은 크기 + 높은 품질을 갖게 됩니다. 정말 효과가 있어요!

질문: Zenity 진행 표시줄에서 "취소"를 누르면 mencoder가 종료되지 않습니다. 어떻게 해야 합니까? Zenity 진행 표시줄에서 "취소"를 누르면 mencoder가 종료됩니다. 어떻게 해야 하나요?

#!/bin/bash

which mencoder > /dev/null 2>&1; if [[ $? -ne 0 ]]; then echo -e '\nerror, no mencoder package detected'; exit 1; fi
which zenity > /dev/null 2>&1; if [[ $? -ne 0 ]]; then echo -e '\nerror, no zenity package detected'; exit 1; fi

HOWMANYLEFT=0
find . -type f | xargs -I {} file --mime-type {} | fgrep "video/" | rev | awk 'BEGIN {FS="/oediv :"} { print $NF}' | rev | while read ONELINE
    do
    if file "$ONELINE" | egrep -qvi "x.264|h.264"
        then echo $ONELINE
    fi
done | sed 's/^.\///' | tee /tmp/vid-conv-tmp.txt | while read ONELINE
    do
    HOWMANY=`wc -l /tmp/vid-conv-tmp.txt | cut -d " " -f1`
    mencoder "$ONELINE" -o "OK-$ONELINE.avi" -ovc x264 -x264encopts bitrate=750 nr=2000 -oac mp3lame -lameopts cbr:br=128 > /dev/null 2>&1
    HOWMANYLEFT=`expr $HOWMANYLEFT + 1`
    echo "scale=10;($HOWMANYLEFT / $HOWMANY) * 100" | bc | cut -d "." -f1
done | zenity --progress --text="Processing files ..." --auto-close --percentage=0

답변1

이 옵션을 사용해야 합니다 --auto-kill. 스크립트를 약간 수정했습니다.고정관념에서 벗어나 생각해보세요를 사용하세요 rev. 하지만 다른 방법도 있습니다. :) ...이것이 하나입니다.

yad대신 사용했어요 zenity포크였어요, 명령은 기본적으로 동일합니다. 내가 읽은 바에 의하면,마당는 더욱 활발하게 개발되고 있으며 더 많은 기능을 갖추고 있습니다. (이것은 제가 사용할 수 있는 좋은 기회입니다.) 이 --auto-kill옵션은 두 가지 모두에 적용됩니다.그리고마당.

백분율을 표시하는 것 외에도 스크립트는 다음도 표시합니다.너무 많이 세어보니(예: 3/8)과 현재 파일 이름. 백분율 계산은 awk(구문에 만족하기 때문에) ..를 사용합니다.

귀하의 구체적인 질문에 대해서는 그것으로 --auto-kill충분합니다.

for p in mencoder yad ;do
    which $p >/dev/null 2>&1 || { echo -e '\nerror, no $p package detected'; exit 1; }
done

list="$(mktemp)"
find . -type f -print0 |   # -print0 caters for any filename 
  xargs --null file --print0 --mime-type | 
    sed -n 's|\x00 *video/.*|\x00|p' | tr -d $'\n' |
      xargs --null file --print0 |
        sed -nr '/\x00.*(x.264|h.264)/!{s/^\.\///; s/\x00.*//; p}' >"$list"
        # At this point, to count how many files there are to process, break out of the pipe.
        # You can't know how many there are until they have all passed through the pipe.

fct=0; wcfct=($(wc "$list"));
while IFS= read -r file ;do
    ((fct+=1)); pcnt=$(awk -v"OFMT=%.2f" "BEGIN{ print (($fct-1)/$wcfct)*100 }")
    echo "# $pcnt%: $fct of $wcfct: $file"; echo $pcnt
    mencoder "$file" -o "OK-$file.avi" -ovc x264 -x264encopts bitrate=750 nr=2000 -oac mp3lame -lameopts cbr:br=128 >/dev/null 2>&1
done <"$list" | yad --title="Encoding Progress" --progress --geometry +100+100 --auto-close --auto-kill 
rm "$list"

관련 정보