You are not logged in.

#1 2021-09-27 11:44:00

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

How to Normalise Audio of MP4s, without Re-encoding the Audio

I have a large batch of MP4s (hundreds of files) for which I'd like to normalise the audio. I'm currently using the following script, but it re-encodes the audio, which I know is a lossy process. Knowing that the original audio stream for each of the MP4s is 2-channel, 32-bit, 48 kHz MPEG AAC Audio, is there a cleaner method I can use which would not actually re-encode the audio? I should mention that I do want the final product to also be similar AAC audio rather than something like WAV or FLAC, to keep the file size reasonable.

for f in *.mp4 ; do
	ffmpeg -i "$f" -map 0:1 -vn audio.wav
	sox audio.wav audio_normalised.wav norm -3
	rm audio.wav
	ffmpeg -i "$f" -i audio_normalised.wav -c:v copy -map 0:v:0 -map 1:a:0 new.mp4
	rm audio_normalised.wav
	mv new.mp4 "$f"
done

Offline

#2 2021-09-27 12:55:01

Morn
Member
Registered: 2012-09-02
Posts: 886

Re: How to Normalise Audio of MP4s, without Re-encoding the Audio

Use ReplayGain tagging, e.g. with https://github.com/Moonbase59/loudgain

Of course then you also need to use a player that recognizes those tags.

Last edited by Morn (2021-09-27 12:56:28)

Offline

#3 2021-09-27 20:16:23

Maniaxx
Member
Registered: 2014-05-14
Posts: 732

Re: How to Normalise Audio of MP4s, without Re-encoding the Audio

There also is AACGAIN.


sys2064

Offline

#4 2021-09-28 01:25:26

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 442

Re: How to Normalise Audio of MP4s, without Re-encoding the Audio

Have you tried https://superuser.com/a/323127 option 3?

Offline

#5 2021-09-28 04:25:51

kokoko3k
Member
Registered: 2008-11-14
Posts: 2,390

Re: How to Normalise Audio of MP4s, without Re-encoding the Audio

icar wrote:

Have you tried https://superuser.com/a/323127 option 3?

Option 3 re-encodes the audio.


Help me to improve ssh-rdp !
Retroarch User? Try my koko-aio shader !

Offline

#6 2021-09-28 12:41:28

teckk
Member
Registered: 2013-02-21
Posts: 518

Re: How to Normalise Audio of MP4s, without Re-encoding the Audio

Audio, is there a cleaner method I can use which would not actually re-encode the audio?

Use the ability of a media player to change it during playback

Examples:

mplayer -af equalizer=0:0:0:0:0:0:0:0:12:12 file.mp4
mpv −−af=equalizer=0:0:0:0:0:0:0:0:12:12 file.mp4

ffplay -af "equalizer=f=100:width_type=o:width=20:g=15" file.mp4

ffplay INPUT -af lowpass=3000,highpass=200

I'm sure that vlc can do the same.

Offline

#7 2021-09-28 15:27:35

latalante1
Member
Registered: 2018-08-30
Posts: 110

Re: How to Normalise Audio of MP4s, without Re-encoding the Audio

Do not recode these files. Most of the time, this is absolutely not an option.
Use metadata (tagging) - replaygain. Players know how to use them.

mpv --replaygain=track

Normalizing with ffmpeg gives the best results with the loudnorm filter.
https://ffmpeg.org/ffmpeg-filters.html#ebur128-1

For example.

mpv --af=lavfi=[loudnorm=I=-16:LRA=11:TP=-1.5] file.m4a

Best quality in two passes.

ffmpeg -i file.m4a -af loudnorm=I=-16:TP=-1.5:LRA=11:print_format=summary -f null /dev/null

Substitute the proposed data accordingly.
$II, $ILRA, $ITP, $IT, $TO

ffmpeg -i input.wav -af loudnorm=linear=true:I=-16:LRA=11:TP=-1.5:measured_I=$II:measured_LRA=$ILRA:measured_tp=$ITP:measured_thresh=$IT:offset=$TO:print_format=summary -ar 44100 out.wav

Only by playing with mpv.

mpv --af=lavfi=[loudnorm=linear=true:I=-16:LRA=11:tp=-2:measured_I=$II:measured_LRA=$ILRA:measured_tp=$ITP:measured_thresh=$IT:offset=$TO] file.m4a

Last edited by latalante1 (2021-09-28 15:29:00)

Offline

Board footer

Powered by FluxBB