Think about what it would take to write this in Python right now:
for wmv_file in $(find $1 -name '*.wmv'); do
echo -n "${wmv_file} "
ffmpeg -i $wmv_file ${wmv_file%.wmv}.mpg 2>&1 | grep kb/s: || echo "ERROR $?"
done
With a few handy variables and functions predefined, this could be something like: for wmv_file in find(argv[1], glob="\*.wmv"):
print(wmv_file, end=" ")
result = do("ffmpeg", "-i", wmv_file, basename(wmv_file, ".wmv") + ".mpg")
if result: print(grep(str(result), "kb/s:"))
else: print("ERROR", result.status) for wmv in Path(sys.argv[1]).rglob("\*.wmv"):
print(wmv, end=" ")
r = subprocess.run(
["ffmpeg", "-i", wmv, wmv.with_suffix(".mpg")],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
)
lines = [l for l in r.stdout.decode().splitlines() if "kb/s:" in l]
print("\n".join(lines) if lines else f"ERROR {r.returncode}")
?If you go outside stdlib you can use the sh library instead of subprocess.run.