Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio normalization script #115

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions nulrdcscripts/tools/AudioNormalizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# General Information

Version Date: 6/21/2024

Document Owner: Sophia Francis

Software Used: ffmpeg-normalizer

# Description
This is a script that allows for the normalization of audio levels in AV files following our AV procedures for normalizing audio.

# Installation Instructions
This script runs through poetry and can be installed and updated from it.

## Usage
To run the script. From nul-rdc-scripts
```
poetry run norm -i \path\to\input'
```
Empty file.
49 changes: 49 additions & 0 deletions nulrdcscripts/tools/AudioNormalizer/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import os
import subprocess
import progressbar
from nulrdcscripts.tools.AudioNormalizer.params import args



def normalizerAudio (input_file,norm_file):
ffmpeg_normalize_path = args.ffmpeg_norm_path
command = ffmpeg_normalize_path + ' '+ input_file + ' '+ "-o" + ' '+ norm_file + ' '+ "-t -18 --keep-loudness-range-target -tp -1 -c:a pcm_s16l2 -ar 44100"
subprocess.run(command)

def normalizerVideo (input_file,norm_file):
ffmpeg_normalize_path = args.ffmpeg_norm_path
command = ffmpeg_normalize_path + ' ' + input_file + ' '+ "-o"+ ' '+ norm_file+ ' '+"-t -18 --keep-loudness-range-target -tp -1 -c:a aac -b:a 256k -ar 48000"
subprocess.run(command)


def single(input_path):
filename, ext = os.path.splitext(input_path)
output_path = filename + "_normalized" + ext
if ext == ".wav":
normalizerAudio(input_path,output_path)
elif ext == ".mp4":
normalizerVideo(input_path,output_path)

def batch(input_path):
ext = ["_a.wav","_a.mp4"]
for file in os.listdir(input_path):
if file.endswith(".mp4.md5"):
pass
elif file.endswith(ext):
single(file)

def run():
input_path = os.path.normpath(args.input_path)
fileType = os.path.isdir(input_path)
if fileType:
batch(input_path)
else:
single(input_path)

def main():
run()

main()



22 changes: 22 additions & 0 deletions nulrdcscripts/tools/AudioNormalizer/params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import argparse

parser = argparse.ArgumentParser()
parser.add_argument(
"-i",
dest="input_path",
action = "store",
type = str,
required=True,
help = "Enter your input_path to the file or folder of files that you want to normalize"
)

parser.add_argument(
"-ffmpeg-norm",
dest="ffmpeg_norm_path",
default="ffmpeg-normalize",
action="store",
type=str,

)

args = parser.parse_args()
56 changes: 51 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
progressbar2 = "^4.4.2"

[tool.poetry.dev-dependencies]

Expand All @@ -23,6 +24,7 @@ vproc = 'nulrdcscripts.vproc.vproc:main'
ingest = 'nulrdcscripts.ingest.ingest:main'
embedExtract = 'nulrdcscripts.tools.EmbedExtract.runfile:main'
ffplaywindow = 'nulrdcscripts.tools.ffplaywindow.main:main'
norm = 'nulrdcscripts.tools.AudioNormalizer.main:main'
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"