diff --git a/.gitignore b/.gitignore
index 51cbe85..bc6dff8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+normalize.m
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
diff --git a/LICENSE b/LICENSE
index 5acbd97..6cba77e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014 Werner
+Copyright (c) 2014 Werner Robitza
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
old mode 100644
new mode 100755
index 58c6f4e..931ef89
--- a/README.md
+++ b/README.md
@@ -1,21 +1,15 @@
-audio-normalize
-===============
-
-Audio Normalization Script for Python/ffmpeg. I've only tested it with Python 2.6, not Python 3.
-
-The script normalizes media files to -26 dB RMS. It outputs PCM WAV files named as `normalized-.wav`.
-
-Usage
-=====
-
-Very simple:
-
- ./normalize.py -i -v
-
-The `-v` option turns on info messages. Check out `./normalize.py -h` for more options.
-
-
-What's with the MATLAB Code?
-============================
-
-This is the reference I've used for testing whether the Python script does the same thing. You can of course use it too, if you want.
+audio-normalize
+===============
+
+Audio Normalization Script for Python/ffmpeg. I've only tested it with Python 2.6, not Python 3.
+
+The script normalizes media files to -26 dB RMS. It outputs PCM WAV files named as `normalized-.wav`.
+
+Usage
+=====
+
+Very simple:
+
+ ./normalize.py -i -v
+
+The `-v` option turns on info messages. Check out `./normalize.py -h` for more options.
diff --git a/normalize.py b/normalize.py
index 384ebcc..42f5ccd 100755
--- a/normalize.py
+++ b/normalize.py
@@ -3,14 +3,34 @@
# Audio normalization script, normalizing media files to WAV output
#
# Requirements: Recent ffmpeg installed on your system (above 2.0 would suffice)
-# Author: Werner Robitza
+#
+# The MIT License (MIT)
+#
+# Copyright (c) 2014 Werner Robitza
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all
+# copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
import argparse
import subprocess
import os
import re
-
args = dict()
def run_command(cmd, raw = False, dry = False):
@@ -64,6 +84,24 @@ def print_verbose(message):
if args.verbose:
print(message)
+# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python
+def which(program):
+ def is_exe(fpath):
+ return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = os.path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for path in os.environ["PATH"].split(os.pathsep):
+ path = path.strip('"')
+ exe_file = os.path.join(path, program)
+ if is_exe(exe_file):
+ return exe_file
+
+ return None
+
# -------------------------------------------------------------------------------------------------
parser = argparse.ArgumentParser(
@@ -79,6 +117,10 @@ def print_verbose(message):
args = parser.parse_args()
+if not which("ffmpeg"):
+ print("[error] ffmpeg could not be found in your PATH")
+ raise SystemExit
+
for input_file in args.input:
if not os.path.exists(input_file):
print("[error] file " + input_file + " does not exist")