2011-12-28 37 views
0

我從here中抽取了Bash腳本,它使用ffmpeg和cygwin擴展名檢查AVI文件中的壞幀。我能夠在Mingw執行代碼。我把ffmpeg.exe(ren ffmpeg),cygwin1.dll & cygz.dll放在Mingw的bin目錄(/ c/mingw/bin /)中。現在,我正在尋找將此bash代碼移植到PowerShell。任何人都可以在這個版本上發佈PowerShell?將簡單的Bash腳本轉換爲PowerShell?

腳本:(路徑:/ C/mygw /斌/ AviConvert)

#!/bin/bash 

FFMPEG="ffmpeg" 
LIST=`find | grep \.avi$` 

for i in $LIST; do 
    OUTP="$i.txt" 
    OUTP_OK="$i.txt.ok" 
    TMP_OUTP="$i.tmp" 
    if [ -f "$OUTP" -o -f "$OUTP_OK" ] ; then 
    echo Skipping "$i" 
    else 
    echo Checking "$i"... 
    RESULT="bad" 
    ffmpeg -v 5 -i "$i" -f null - 2> "$TMP_OUTP" && \ 
     mv "$TMP_OUTP" "$OUTP" && \ 
     RESULT=`grep -v "\(frame\)\|\(Press\)" "$OUTP" | grep "\["` 
    if [ -z "$RESULT" ] ; then 
     mv "$OUTP" "$OUTP_OK" 
    fi 
    fi 
done 
+0

多遠沒有你當你自己嘗試時得到它?你究竟在幹什麼? – zdan 2011-12-28 07:03:01

+0

它的工作很好。對於目標文件夾中的每個AVI文件,它會生成一個報告文件,其中包含* .ok(如果該文件沒有缺陷幀),* .txt(如果存在任何幀錯誤)或* .tmp(當其處理中)。但處理過程非常緩慢。我認爲在PowerShell中運行腳本可能會提高性能,因爲mingw模擬bash環境(意味着很多開銷?)。 CMIIW! – 2011-12-28 07:44:42

+3

我懷疑花時間最長的是命令'ffmpeg -v 5 -i「$ i」-f null - 2>「$ TMP_OUTP」'。你有沒有嘗試過使用Windows版本[這裏](http://ffmpeg.zeranoe.com/builds/)。您可以通過處理1個AVI文件並比較完成時間來比較cygwin和Powershell。 – 2011-12-28 19:53:37

回答

3

如果你不能夠找到類似的已熟在PowerShell中,你唯一的機會是瞭解這個腳本的邏輯並從頭寫入PowerShell中,因爲存在很大差異

查看語法/命令的差異並進行適當的翻譯。某些Bash與Powershell相關的帖子/文檔可在網絡上獲得,例如this。當然,請參閱PowerShell入門手冊。例如語法是不同的,PowerShell的是:

for (_init_, _cond_, _incr_) { 
    _operators_ 
} 

順便說一句,在你的情況下,最好使用的foreach,即具有類似:

(get-childitem $path -Recurse | select-string -pattern .avi | % {$_.Path} > matchingfiles.txt) 
$FILESARRAY = get-content matchingfiles.txt 
foreach ($FILE in $FILESARRAY) 
{ 
(get-content $FILE) |foreach-object {$_ -replace $find, $replace} | set-content $FILE 
} 
+0

例如鏈接已損壞/無法解析。 – Neil 2016-12-22 11:53:19