Skip to content

Commit

Permalink
Livense
Browse files Browse the repository at this point in the history
  • Loading branch information
Werner Robitza committed Jul 31, 2014
1 parent 9701ad7 commit c9bb8f2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
normalize.m
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down
36 changes: 15 additions & 21 deletions README.md 100644 → 100755
@@ -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-<input>.wav`.

Usage
=====

Very simple:

./normalize.py -i <input-file> -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-<input>.wav`.

Usage
=====

Very simple:

./normalize.py -i <input-file> -v

The `-v` option turns on info messages. Check out `./normalize.py -h` for more options.
46 changes: 44 additions & 2 deletions normalize.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand All @@ -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")
Expand Down

0 comments on commit c9bb8f2

Please sign in to comment.