slhck / ffmpeg-normalize

Audio Normalization for Python/ffmpeg
MIT License
1.28k stars 118 forks source link

Stats only? #179

Closed jimlynnjulian closed 2 years ago

jimlynnjulian commented 2 years ago

I did my first video. I got this message: "Input file had loudness range of 22.7, which is larger than the loudness range target (7.0). Normalization will revert to dynamic mode. Choose a higher target loudness range if you want linear normalization." Can the program be run to return a stats report on files in a folder? I'd like to get some information before processing a file/folder. For example, the degree to which an audio stream's maximum exceeds a standard and the dynamic range of an audio stream. I have several thousand videos I need to process and I'd like to get as much right as possible with as little redo as possible. I have set up a test folder for trying out various settings and various file/audio formats.

slhck commented 2 years ago

You can run this program on multiple files, output nothing (-n), and print the stats (-p):

$ ffmpeg-normalize 1.wav 2.wav -n -f -p
[
    {
        "input_file": "1.wav",
        "output_file": "normalized/1.mkv",
        "stream_id": 0,
        "ebu": {
            "input_i": -23.11,
            "input_tp": -7.0,
            "input_lra": 4.6,
            "input_thresh": -33.24,
            "output_i": -23.32,
            "output_tp": -6.12,
            "output_lra": 4.1,
            "output_thresh": -33.38,
            "normalization_type": "dynamic",
            "target_offset": 0.32
        },
        "mean": null,
        "max": null
    },
    {
        "input_file": "2.wav",
        "output_file": "normalized/2.mkv",
        "stream_id": 0,
        "ebu": {
            "input_i": -23.11,
            "input_tp": -7.0,
            "input_lra": 4.6,
            "input_thresh": -33.24,
            "output_i": -23.32,
            "output_tp": -6.12,
            "output_lra": 4.1,
            "output_thresh": -33.38,
            "normalization_type": "dynamic",
            "target_offset": 0.32
        },
        "mean": null,
        "max": null
    }
]

This will output a valid JSON to stdout.

You can also parallelize this, e.g. with GNU parallel, outputting one JSON file per file:

parallel ffmpeg-normalize {} -n -f -p '>' {.}.json  ::: 1.wav 2.wav
jimlynnjulian commented 2 years ago

Thanks for the program. Ran the program as a script for a test mkv file, and got this error:

ffmpeg-normalize: error: argument -p/--print-stats: ignored explicit argument '\r' script.sh: line 2: [: missing `]' script.sh: line 23: syntax error: unexpected end of file

Using WSL. Also, the indentation spaces are not indicated in the paste to this response. I also tried replacing the EOL commas with backslashes. No effect.

Script:

!/bin/bash

ffmpeg-normalize Zola.mkv -n -f -p [ { "input_file": "Zola.mkv", "output_file": "normalized/Zola.mkv", "stream_id": 0, "ebu": {, "input_i": -23.11, "input_tp": -7.0, "input_lra": 4.6, "input_thresh": -33.24, "output_i": -23.32, "output_tp": -6.12, "output_lra": 4.1, "output_thresh": -33.38, "normalization_type": "dynamic", "target_offset": 0.32, }, "mean": null, "max": null } ]

slhck commented 2 years ago

I think you got confused by what I wrote above.

All you have to put into your script is ffmpeg-normalize Zola.mkv -n -f -p.

The rest is the output of the command. Usually when a line is prefixed with a $, it means that this is what you type in the shell, and the part below is the output.

jimlynnjulian commented 2 years ago

Thanks. I haven't done a lot of prograqmming lately and the output has a strong resemblance to a script. While I didn't, necessarily, jump to a conclusion, I managed to get there anyway. Too long a night. Thanks again.

slhck commented 2 years ago

Sure. Let me know if you need any more help.