0

I have pulled the Bash script from here, which checks the AVI file for bad frames using ffmpeg and cygwin extension. I am able to execute the code in Mingw. I put ffmpeg.exe (ren ffmpeg), cygwin1.dll & cygz.dll in Mingw's bin dir (/c/mingw/bin/). Now, I am looking to port this bash code to PowerShell. Can anyone shed some PowerShell light on this one?

Script: (path: /c/mygw/bin/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
5
  • How far did you get when you tried it yourself? What exactly are you stuck on? Commented Dec 28, 2011 at 7:03
  • Its working just fine. For each AVI file in the target folder, it generates a report file with either *.ok (if the file has no defected frame), *.txt (if there were any frame errors fround) or *.tmp (while its under process). But the processing is extremely slow. I thought running the script in PowerShell might improve the performance as mingw is emulating bash environment (meaning lot of overheads?). CMIIW! Commented Dec 28, 2011 at 7:44
  • 3
    I suspect the thing taking the longest is the command ffmpeg -v 5 -i "$i" -f null - 2> "$TMP_OUTP". Have you tried using a build for windows avaialble here.? You can compare cygwin and Powershell by just processing 1 of your AVI files and comparing completion times. Commented Dec 28, 2011 at 19:53
  • @vulcanraven Andy is spot on - running this under powershell will make zero difference. The heaving lifting is being done by ffmpeg which neither cares about nor depends on the parent shell because it is an independent process. Commented Dec 29, 2011 at 4:07
  • Thanks Andy, that definitely makes sense. I guess in order to make the process faster I need to run the parallel processes and probably try a different video conversion engine (perhaps a .NET-based) to evaluate the difference. Commented Jan 15, 2012 at 3:48

1 Answer 1

3

If you would not be able to find similar already cooked in PowerShell, your only chance is to understand this script's logic and write one in PowerShell from scratch since there are big differences.

Look at the difference in syntax/commands and make appropriate translation. Some Bash vs Powershell related posts/docs available in web, e.g. this. And of course refer to PowerShell Getting Started manuals. For example syntax for for is different, for PowerShell it is:

for (_init_, _cond_, _incr_) { 
   _operators_
}

BTW, in your case it's better to use foreach, i.e. having something like:

(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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.