normalize audio in mp4s

classic Classic list List threaded Threaded
42 messages Options
123
Reply | Threaded
Open this post in threaded view
|

normalize audio in mp4s

Emanuel Berg-4
how can I normalize the audio in mp4 video files? both WRT not
having to lower the volume when there's a firefight and raise it
when they start talking again, _and_ WRT playing several files, e.g.
music videos, and having them have basically the same volume?

if need be, I can set volume modifications to each file, manually if
I knew how to do it. this wouldn't work for firefight/talk
movies tho.

or can it be done automatically, on the fly?

I use mpv.

TIA

--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Christensen
On 2020-03-06 11:33, Emanuel Berg wrote:

> how can I normalize the audio in mp4 video files? both WRT not
> having to lower the volume when there's a firefight and raise it
> when they start talking again, _and_ WRT playing several files, e.g.
> music videos, and having them have basically the same volume?
>
> if need be, I can set volume modifications to each file, manually if
> I knew how to do it. this wouldn't work for firefight/talk
> movies tho.
>
> or can it be done automatically, on the fly?
>
> I use mpv.

You want audio compression.


Some media editors, such as Audacity, have compression (and many other
features).


Some media players, such as VLC, have real-time audio compression during
playback.


I use Xfce.   I do not see a compressor in its PulseAudio Plugin/ mixer.


There have been various audio API's/ subsystems in Linux over the years.
  JACK was designed for profession audio on Linux, and is very flexible.
  If you can get your audio streams into JACK, it should be possible to
patch in a software compressor:

     https://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit


Alternatively, hardware.  If you are running old-school stereo speakers,
you could buy an electronic compressor.  There are many choices.  Rolls
makes good purpose-built stuff at reasonable prices:

     https://rolls.com/product/SL33


David

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Emanuel Berg-4
David Christensen wrote:

> You want audio compression.
>
> Some media editors, such as Audacity, have compression (and many
> other features).
>
> Some media players, such as VLC, have real-time audio compression
> during playback.
>
> I use Xfce. I do not see a compressor in its PulseAudio
> Plugin/ mixer.
>
> There have been various audio API's/ subsystems in Linux over the
> years. JACK was designed for profession audio on Linux, and is
> very flexible. If you can get your audio streams into JACK, it
> should be possible to patch in a software compressor:
>
>     https://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit
>
> Alternatively, hardware. If you are running old-school stereo
> speakers, you could buy an electronic compressor. There are many
> choices. Rolls makes good purpose-built stuff at reasonable
> prices:
>
>     https://rolls.com/product/SL33

Thank you, you seem very knowledgeable in this area...

Well, it sounds advanced... Yes, its a stereo alright, that much
I know.

I tried this but it sounds so bad I even had to put a warning in
a comment:

# first do:
# $ pip install ffmpeg-normalize
#
# but... don't use, at least not with music, sounds terrible :(
get-mp3-normalized () {
    local -a files
    files=($@)

    local dB=-10 # db/LUFS

    for f in $files; do
        ffmpeg-normalize -f -c:a libmp3lame -t $dB -ext mp3 $f
    done
} # [1]


[1] https://dataswamp.org/~incal/conf/.zsh/audio-convert

--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Christensen
On 2020-03-06 18:05, Emanuel Berg wrote:

<snip>

> Well, it sounds advanced... Yes, its a stereo alright, that much
> I know.
>
> I tried this but it sounds so bad I even had to put a warning in
> a comment:
>
> # first do:
> # $ pip install ffmpeg-normalize
> #
> # but... don't use, at least not with music, sounds terrible :(
> get-mp3-normalized () {
>      local -a files
>      files=($@)
>
>      local dB=-10 # db/LUFS
>
>      for f in $files; do
>          ffmpeg-normalize -f -c:a libmp3lame -t $dB -ext mp3 $f
>      done
> } # [1]
>
>
> [1] https://dataswamp.org/~incal/conf/.zsh/audio-convert

It is going to be difficult or impossible to get good results across
many different mp4 files by feeding them all through a command-line tool
with the same set of options.  It might be possible to script a solution
that uses command-line tools to analyze each file and tune the options,
but I dunno...


The most direct path to good results would be to use an interactive
audio editor.  Then it's up to your skills as an audio engineer.  As,
Audacity only does audio files, the workflow would be to use a video
tool to extract the audio tracks, rework the audio with Audacity, and
then use a video tool to replace the old audio with the new audio.


Be sure you backup your original files before you start messing with them.


David

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Emanuel Berg-4
In reply to this post by Emanuel Berg-4
> I tried this but it sounds so bad I even had to put a warning in
> a comment

I used it the wrong way, one is supposed to experiment with dB/LUFS
values for a single problematic file, meanwhile I just injected all
my mp3s :$

> # first do:
> # $ pip install ffmpeg-normalize
> #
> # but... don't use, at least not with music, sounds terrible :(
> get-mp3-normalized () {
>     local -a files
>     files=($@)
>
>     local dB=-10 # db/LUFS
>
>     for f in $files; do
>         ffmpeg-normalize -f -c:a libmp3lame -t $dB -ext mp3 $f
>     done
> } # [1]
>
> [1] https://dataswamp.org/~incal/conf/.zsh/audio-convert

Do it today... in a different way!

--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Emanuel Berg-4
In reply to this post by David Christensen
David Christensen wrote:

> It is going to be difficult or impossible to get good results
> across many different mp4 files by feeding them all through
> a command-line tool with the same set of options. It might be
> possible to script a solution that uses command-line tools to
> analyze each file and tune the options, but I dunno...

Yes, I get it. I actually thought the opposite to begin with, i.e.
the more file the better since then the computer would be able to
compute some grand framework and pruning everything that ended up
outside of it...

--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Jonas Smedegaard-2
In reply to this post by David Christensen
Quoting David Christensen (2020-03-07 03:41:22)

> On 2020-03-06 18:05, Emanuel Berg wrote:
>
> <snip>
>
> > Well, it sounds advanced... Yes, its a stereo alright, that much
> > I know.
> >
> > I tried this but it sounds so bad I even had to put a warning in
> > a comment:
> >
> > # first do:
> > # $ pip install ffmpeg-normalize
> > #
> > # but... don't use, at least not with music, sounds terrible :(
> > get-mp3-normalized () {
> >      local -a files
> >      files=($@)
> >
> >      local dB=-10 # db/LUFS
> >
> >      for f in $files; do
> >          ffmpeg-normalize -f -c:a libmp3lame -t $dB -ext mp3 $f
> >      done
> > } # [1]
> >
> >
> > [1] https://dataswamp.org/~incal/conf/.zsh/audio-convert
>
> It is going to be difficult or impossible to get good results across
> many different mp4 files by feeding them all through a command-line tool
> with the same set of options.  It might be possible to script a solution
> that uses command-line tools to analyze each file and tune the options,
> but I dunno...
>
>
> The most direct path to good results would be to use an interactive
> audio editor.  Then it's up to your skills as an audio engineer.  As,
> Audacity only does audio files, the workflow would be to use a video
> tool to extract the audio tracks, rework the audio with Audacity, and
> then use a video tool to replace the old audio with the new audio.
>
>
> Be sure you backup your original files before you start messing with them.
If you want something you can throw into a script, I recommend to look
at melt and use its "loudness" filter.

You will want to run it in two-pass mode, so that it knows ahead the
dynamics of each "tune" (or movie).

It can be tricky to capture the output from first pass and feed it into
second pass (because the main use for the MLT framework is not the
command-line tool melt but instead XML-based linkage to GUI tools).

Maybe this script is useful for inspiration:
http://source.jones.dk/bin.git/tree/localvideowebencode


 - Jonas

--
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Wright-3
In reply to this post by Emanuel Berg-4
On Fri 06 Mar 2020 at 20:33:48 (+0100), Emanuel Berg wrote:
> how can I normalize the audio in mp4 video files? both WRT not
> having to lower the volume when there's a firefight and raise it
> when they start talking again, _and_ WRT playing several files, e.g.
> music videos, and having them have basically the same volume?
>
> if need be, I can set volume modifications to each file, manually if
> I knew how to do it. this wouldn't work for firefight/talk
> movies tho.

I use the compand and gain effects in sox, but my target is different
from yours: movies would involve splitting and recombining the audio
and video streams.

My process converts anything that ffmpeg will play into WAV files
(CD format), which sox then concatenates and compands into another
WAV file, which lame then encodes to an MP3.

My target is to convert (possibly segue'd) classical music tracks
(potentially huge dynamic range) into something that can be listened
to on an MP3 player in noisy places like, say, the street.

The critical lines (embedded in a load of shell) are
  ffmpeg -hide_banner -y -i "$1" -ar 44100 -ac 2 "$Unique0/$Filenumber.wav"
where the $Filenumbers are 10000+ sequence numbers so they collate,
  sox "$Unique0"/1*.wav -t wav -r 44100 -b 16 -c 2 "$Unique0/0.wav" compand 0.3,1 6:-70,-60,-20 -15 -90 0.2 gain -n -0.01;
where the companding parameters are reasonably aggressive and the
normalisation is "turned up to ten", and
  lame -b "${Fixedbitrate:-128}" "$Unique0/0.wav" "$Unique0/0.mp3"
is for fairly unendowed MP3 players.

($Unique0 is just a nonce working directory.)

> or can it be done automatically, on the fly?

On the fly would mean delaying the video to match the audio, which is
necessarily delayed (by sox needing look-ahead in the audio stream).
I've thought about it over the years, but never tried it, mainly
because in the situation where it would have been most useful
(ie driving, particularly commuting alone), I didn't have any way
of intercepting the audio between tuner and amplifier. (Nowadays,
I rely on the thumb control on the steering wheel.) That's for the
radio, and occasional CD. Otherwise, the tracks on my USB stick would
usually have been companded as above.

I would be interested if someone worked out how to do splitting, sox,
and recombining reliably enough to preserve the synchronisation.
(Automatic, but not on the fly.)

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Jonas Smedegaard-2
Quoting David Wright (2020-03-07 04:56:05)

> On Fri 06 Mar 2020 at 20:33:48 (+0100), Emanuel Berg wrote:
> > how can I normalize the audio in mp4 video files? both WRT not
> > having to lower the volume when there's a firefight and raise it
> > when they start talking again, _and_ WRT playing several files, e.g.
> > music videos, and having them have basically the same volume?
> >
> > if need be, I can set volume modifications to each file, manually if
> > I knew how to do it. this wouldn't work for firefight/talk
> > movies tho.
>
> I use the compand and gain effects in sox,
[...]
> The critical lines (embedded in a load of shell) are
>   ffmpeg -hide_banner -y -i "$1" -ar 44100 -ac 2 "$Unique0/$Filenumber.wav"
> where the $Filenumbers are 10000+ sequence numbers so they collate,
>   sox "$Unique0"/1*.wav -t wav -r 44100 -b 16 -c 2 "$Unique0/0.wav" compand 0.3,1 6:-70,-60,-20 -15 -90 0.2 gain -n -0.01;
> where the companding parameters are reasonably aggressive and the
> normalisation is "turned up to ten", and
>   lame -b "${Fixedbitrate:-128}" "$Unique0/0.wav" "$Unique0/0.mp3"
> is for fairly unendowed MP3 players.
[...]
> I would be interested if someone worked out how to do splitting, sox,
> and recombining reliably enough to preserve the synchronisation.
> (Automatic, but not on the fly.)

ffmpeg should be able to do the whole processing, if you want peak or
RMS normalization.  If you want EBU R128 normalization then you need
e.g. melt (which uses ffmpeg internally and adds aditional plugins).

Here is a good explanation on the difference between "peak", "RMS", and
"EBU R-128": https://www.learndigitalaudio.com/normalize-audio

Hhere are some example of using ffmpeg:
https://superuser.com/questions/323119/how-can-i-normalize-audio-using-ffmpeg

I use melt because I can then handle video as well - either do various
compression of that as well, or "just" pass-through (which still
involves the challenge of keeping audio and video in sync - which is
more or less reliable depending on the container format of each video).


 - Jonas

--
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Wright-3
On Sat 07 Mar 2020 at 12:12:18 (+0100), Jonas Smedegaard wrote:

> Quoting David Wright (2020-03-07 04:56:05)
> > On Fri 06 Mar 2020 at 20:33:48 (+0100), Emanuel Berg wrote:
> > > how can I normalize the audio in mp4 video files? both WRT not
> > > having to lower the volume when there's a firefight and raise it
> > > when they start talking again, _and_ WRT playing several files, e.g.
> > > music videos, and having them have basically the same volume?
> > >
> > > if need be, I can set volume modifications to each file, manually if
> > > I knew how to do it. this wouldn't work for firefight/talk
> > > movies tho.
> >
> > I use the compand and gain effects in sox,
> [...]
> > The critical lines (embedded in a load of shell) are
> >   ffmpeg -hide_banner -y -i "$1" -ar 44100 -ac 2 "$Unique0/$Filenumber.wav"
> > where the $Filenumbers are 10000+ sequence numbers so they collate,
> >   sox "$Unique0"/1*.wav -t wav -r 44100 -b 16 -c 2 "$Unique0/0.wav" compand 0.3,1 6:-70,-60,-20 -15 -90 0.2 gain -n -0.01;
> > where the companding parameters are reasonably aggressive and the
> > normalisation is "turned up to ten", and
> >   lame -b "${Fixedbitrate:-128}" "$Unique0/0.wav" "$Unique0/0.mp3"
> > is for fairly unendowed MP3 players.
> [...]
> > I would be interested if someone worked out how to do splitting, sox,
> > and recombining reliably enough to preserve the synchronisation.
> > (Automatic, but not on the fly.)
>
> ffmpeg should be able to do the whole processing, if you want peak or
> RMS normalization.  If you want EBU R128 normalization then you need
> e.g. melt (which uses ffmpeg internally and adds aditional plugins).
>
> Here is a good explanation on the difference between "peak", "RMS", and
> "EBU R-128": https://www.learndigitalaudio.com/normalize-audio
>
> Hhere are some example of using ffmpeg:
> https://superuser.com/questions/323119/how-can-i-normalize-audio-using-ffmpeg

I don't think normalisation, on its own, would be of much help to me.
Many digital recordings are mixed for perfect listening conditions,
and that's often just not possible, so some degree of dynamic range
compression is necessary *within* each track. And where the tracks
segue on a CD, that necessitates concatenation, as least with my
technique, making for longer tracks.

I don't know whether/how movies are segmented (I've seen reference
to "chapters" but don't know what they are). But it sounds as if the
OP needs similar DR compression between or even within scenes.

> I use melt because I can then handle video as well - either do various
> compression of that as well, or "just" pass-through (which still
> involves the challenge of keeping audio and video in sync - which is
> more or less reliable depending on the container format of each video).

I'm not sure what type of video compression you mean: file size or
something else? We have one TV which can darken dark scenes and
brighten bright ones. Perhaps you need the opposite for watching
movies in the back seats of a car?

Melts looks like a very professional editor, but doesn't appear
to be easy to configure for automatic processing, so it might not
suit my requirements. The only guidance my process needs is which
tracks need concatenation, and that's a very small proportion of
the just those that were ripped from CDs.

I ripped my CD collection on a desktop at home (because it's a manual
process), but companded them all on a laptop running 24/7 in a freezing
house while I was walking in the Lake District (suited its processor
that tended to run 80°C+). Then I reran the concatenated ones when
I got home.

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Jonas Smedegaard-2
Quoting David Wright (2020-03-09 04:15:41)

> On Sat 07 Mar 2020 at 12:12:18 (+0100), Jonas Smedegaard wrote:
> > Quoting David Wright (2020-03-07 04:56:05)
> > > On Fri 06 Mar 2020 at 20:33:48 (+0100), Emanuel Berg wrote:
> > > > how can I normalize the audio in mp4 video files? both WRT not
> > > > having to lower the volume when there's a firefight and raise it
> > > > when they start talking again, _and_ WRT playing several files,
> > > > e.g. music videos, and having them have basically the same
> > > > volume?
> > > >
> > > > if need be, I can set volume modifications to each file,
> > > > manually if I knew how to do it. this wouldn't work for
> > > > firefight/talk movies tho.
> > >
> > > I use the compand and gain effects in sox,
> > [...]
> > > The critical lines (embedded in a load of shell) are
> > >   ffmpeg -hide_banner -y -i "$1" -ar 44100 -ac 2 "$Unique0/$Filenumber.wav"
> > > where the $Filenumbers are 10000+ sequence numbers so they collate,
> > >   sox "$Unique0"/1*.wav -t wav -r 44100 -b 16 -c 2 "$Unique0/0.wav" compand 0.3,1 6:-70,-60,-20 -15 -90 0.2 gain -n -0.01;
> > > where the companding parameters are reasonably aggressive and the
> > > normalisation is "turned up to ten", and
> > >   lame -b "${Fixedbitrate:-128}" "$Unique0/0.wav" "$Unique0/0.mp3"
> > > is for fairly unendowed MP3 players.
> > [...]
> > > I would be interested if someone worked out how to do splitting, sox,
> > > and recombining reliably enough to preserve the synchronisation.
> > > (Automatic, but not on the fly.)
> >
> > ffmpeg should be able to do the whole processing, if you want peak
> > or RMS normalization.  If you want EBU R128 normalization then you
> > need e.g. melt (which uses ffmpeg internally and adds aditional
> > plugins).
> >
> > Here is a good explanation on the difference between "peak", "RMS",
> > and "EBU R-128": https://www.learndigitalaudio.com/normalize-audio
> >
> > Hhere are some example of using ffmpeg:
> > https://superuser.com/questions/323119/how-can-i-normalize-audio-using-ffmpeg
>
> I don't think normalisation, on its own, would be of much help to me.
> Many digital recordings are mixed for perfect listening conditions,
> and that's often just not possible, so some degree of dynamic range
> compression is necessary *within* each track. And where the tracks
> segue on a CD, that necessitates concatenation, as least with my
> technique, making for longer tracks.
Agreed, you need more than (strictly speaking) normalization alone.

When OP wrote "how can I normalize" I read it to more casually imply
possibly more parts than (striclty speaking) normalization alone.

That's why I wrote "the whole processing" above.

sox can (compress and) normalize audio.

ffmpeg can do (almost) same as sox, also embedded in video.

melt can do (almost) same as ffmpeg, and can do some parts better.


> I don't know whether/how movies are segmented (I've seen reference to
> "chapters" but don't know what they are). But it sounds as if the OP
> needs similar DR compression between or even within scenes.

Just like audio-in-music can be high dynamic range (one tune a flute
solo, another an orchestra), so can audio-in-movie (one scene the sounds
of bed sheets, another a car explosion): Audio is audio, it is dynamic.

Both audio-in-music and audio-in-movie can to change dynamic range per
tune/scene or within them.  Depends on how it was composed, performed,
recorded, and mixed.

Both audio-in-music and audio-in-movice can already be compressed.  
Depends on how it was mastered (i.e. post-processed).



The OP asked about
normalization of audio, including audio embedded in video.


> > I use melt because I can then handle video as well - either do
> > various compression of that as well, or "just" pass-through (which
> > still involves the challenge of keeping audio and video in sync -
> > which is more or less reliable depending on the container format of
> > each video).
>
> I'm not sure what type of video compression you mean: file size or
> something else? We have one TV which can darken dark scenes and
> brighten bright ones. Perhaps you need the opposite for watching
> movies in the back seats of a car?
I meant file size.  Yes, not only dynamic range of audio but also color
spaces can be compressed, but please let's limit this conversation to
_audio_ processing (I mentioned video processing only because my script
happens to handle more than audio (compression and) normalization).

I did not sugggest melt for its ability to also normalize video.

I suggested melt for its ability to...:

 a) extract+recompress compressed audio formats
 b) decouple+realign audio intertwined with video in multimedia file
 c) do professional grade _audio_ normalization (EBU R-128)


> Melts looks like a very professional editor, but doesn't appear to be
> easy to configure for automatic processing, so it might not suit my
> requirements.

If you only process uncompressed audio then sox is fine.

The OP explicitly ask about processing audio embedded in multimedia,
where sox is not suitable: You need a tool that can not only extract
audio but also stitch it back together while keeping audio and video
tracks in sync.  You therefore need ffmpeg or something based on it.

Melt is based on ffmpeg and adds a high quality audio normalizer.

Melt is indeed not as easy to use as ffmpeg, however: Ffmpeg is
optimized for scripting where the backend of melt (MLT framework) is
primarily used in GUI applications, secondly in the text-based tool melt
interactively, and only thirdly scripted with melt.

So if high-quality normalization is not important (and you don't want to
try play with stripping my script), then directly use ffmpeg, or use any
other of the many many many ffmpeg-based tools available.

...or use sox (but still use ffmpeg to extract audio part of mp4 files).


 - Jonas

--
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Greg Wooledge
In reply to this post by Emanuel Berg-4
On Sat, Mar 07, 2020 at 03:05:27AM +0100, Emanuel Berg wrote:
> get-mp3-normalized () {
>     local -a files
>     files=($@)
>
>     local dB=-10 # db/LUFS
>
>     for f in $files; do
>         ffmpeg-normalize -f -c:a libmp3lame -t $dB -ext mp3 $f
>     done

get-mp3-normalized() {
    local dB=-10 # db/LUFS
    local f

    for f; do
        ffmpeg-normalize -f -c:a libmp3lame -t "$dB" -ext mp3 "$f"
    done
}

There's no need to copy the positional parameters to an array, but
there *is* a need to quote correctly.  Otherwise, all of the filenames
with spaces in them are going to fail.

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Wright-3
In reply to this post by Jonas Smedegaard-2
On Mon 09 Mar 2020 at 12:26:53 (+0100), Jonas Smedegaard wrote:
> So if high-quality normalization is not important (and you don't want to
> try play with stripping my script), then directly use ffmpeg, or use any
> other of the many many many ffmpeg-based tools available.
>
> ...or use sox (but still use ffmpeg to extract audio part of mp4 files).

I shall take a look at your script. But, thinking about the
problem overall, I think there might be several reasons why
I haven't personally felt the need for video companding:

. I only consume videos, usually once, and don't produce any
  for distribution,

. Some companding/editing/mixing is already done during
  video production,

. Remotes are virtually ubiquitous, thank goodness,

. I don't knit (IOW when I'm watching TV, my hands are typically
  free, or have the Roku remote in one, TV in the other),

. Many of the objectionable changes in volume (think adverts)
  can only be tackled easily at the TV (some of which try to
  normalise volume) or at the remote.

That's not to criticise these useful posts.

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Jonas Smedegaard-2
Quoting David Wright (2020-03-09 19:08:26)
> On Mon 09 Mar 2020 at 12:26:53 (+0100), Jonas Smedegaard wrote:
> > So if high-quality normalization is not important (and you don't
> > want to try play with stripping my script), then directly use
> > ffmpeg, or use any other of the many many many ffmpeg-based tools
> > available.
> >
> > ...or use sox (but still use ffmpeg to extract audio part of mp4
> > files).

Please note that the subject of this conversation is mp4 (not mp3).

Please also note that above quote was a continuation of this:

> If you only process uncompressed audio then sox is fine.


> I shall take a look at your script. But, thinking about the
> problem overall, I think there might be several reasons why
> I haven't personally felt the need for video companding:

No need to explain why you don't have same/similar needs as the OP :-)

If you neither have a need for audio-in-movie nor for EBU R-128, then I
doubt you'll be excited about melt or my script (even it it also
supports modes where it bypasses melt and runs ffmpeg directly).

All that said, you are of course quite welcome to look at my script, and
even critisize it if you like (no doubt there are things in there worthy
of pointing fingers at).


 - Jonas

--
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

ghe-2
In reply to this post by Emanuel Berg-4

> Please note that the subject of this conversation is mp4 (not mp3).

It's claimed that sox will handle mp4:

https://stackoverflow.com/questions/2666425/how-to-i-configure-sox-to-work-on-mp4

(You do have to install LAME.)

> If you only process uncompressed audio then sox is fine.

It will do the mp's and flac. That I know of -- there may be others.

It normalizes things too. I do that in flac. I don't know if it
normalizes mp's.

--
Glenn English

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Jonas Smedegaard-2
Quoting ghe (2020-03-09 21:23:54)
>
> > Please note that the subject of this conversation is mp4 (not mp3).
>
> It's claimed that sox will handle mp4:
>
> https://stackoverflow.com/questions/2666425/how-to-i-configure-sox-to-work-on-mp4
>
> (You do have to install LAME.)

In Debian, install libsox-fmt-mp3 (which links to liblame).


> > If you only process uncompressed audio then sox is fine.
>
> It will do the mp's and flac. That I know of -- there may be others.

Yes, sox supports _some_ compression formats.  Far less than ffmpeg, and
only audio, not video, and ffmpeg supports all those formats and many
more.

So you only process audio and only in a format supported by sox, then
sox is fine too.

If you don't want to fiddle with figuring out if your particular format
is supported by sox, then use ffmpeg.

Shorter version of above: Use sox for uncompressed audio, ffmpeg for
compressed audio and video.

It might be that sox has some support for AAC encoded m4a streams in an
MPEG4 container.  I would however be quite surprised (even by that but
also) if sox supported leaving other streams in such MPEG4 container
alone, and supported reencoding to AAC and putting it back into the
container, with audio-video sync intact.

The OP talked about normalizing music videos.  I assume that the OP
wanted to to not only _listen_ to normalized music videos but also watch
them.

My assumption might be totally wrong, in which case sox is a fine tool
for the task.


> It normalizes things too. I do that in flac. I don't know if it
> normalizes mp's.

Sox is a nice tool, for what it can do.

I was under the impression that it was unsuitable for the needs of the
OP.


 - Jonas

--
 * Jonas Smedegaard - idealist & Internet-arkitekt
 * Tlf.: +45 40843136  Website: http://dr.jones.dk/

 [x] quote me freely  [ ] ask before reusing  [ ] keep private

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Wright-3
In reply to this post by Jonas Smedegaard-2
On Mon 09 Mar 2020 at 19:38:06 (+0100), Jonas Smedegaard wrote:

> Quoting David Wright (2020-03-09 19:08:26)
> > On Mon 09 Mar 2020 at 12:26:53 (+0100), Jonas Smedegaard wrote:
> > > So if high-quality normalization is not important (and you don't
> > > want to try play with stripping my script), then directly use
> > > ffmpeg, or use any other of the many many many ffmpeg-based tools
> > > available.
> > >
> > > ...or use sox (but still use ffmpeg to extract audio part of mp4
> > > files).
>
> Please note that the subject of this conversation is mp4 (not mp3).

I haven't mentioned MP3 since my first post, where a warning was given
in the second paragraph that my target was MP3s. The rest of my posts
have been about companding and normalising.

I'm not sure why you feel the need to circumscribe the discussion.
Earlier you wrote "I use melt because I can then handle video as well
- either do various compression of that as well".

I asked for clarification of what you meant by compression (which
has two meanings in this context) and you wrote "but please let's
limit this conversation to _audio_ processing". Odd, as only you
had mentioned processing the video; I'm only interested in preserving
it for the OP.

> Please also note that above quote was a continuation of this:
>
> > If you only process uncompressed audio then sox is fine.

The posts were getting long, so because I was only commenting on your
mention of your script, I snipped virtually the whole of the
preceding. Sorry for not removing the last line: I didn't quote you
freely, but laxly.

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

David Wright-3
In reply to this post by Jonas Smedegaard-2
On Mon 09 Mar 2020 at 19:38:06 (+0100), Jonas Smedegaard wrote:

> All that said, you are of course quite welcome to look at my script, and
> even critisize it if you like (no doubt there are things in there worthy
> of pointing fingers at).

Before I do, I thought I'd try my hand at one myself. Just to see what
happens, I downloaded https://www.youtube.com/watch?v=I_rVtFUkMus
which has plenty of synchronisation points, and a gradual decrease in
volume from start to finish.

  ffmpeg -i original.mkv -ar 44100 -ac 2 original.wav
  sox original.wav -t wav -r 44100 -b 16 -c 2 companded.wav compand 0.3,1 6:-70,-60,-20 -15 -90 0.2 gain -n -0.01
  ffmpeg -i companded.wav -i original.mkv final.mp4

I couldn't detect any loss of synchronisation (don't watch Barenboim,
of course), but the latter half had its volume raised about how
I expected. Does this qualify? It seemed too easy. OK, the original's
an MKV, as so many of my youtube videos are; perhaps they're easier
to pull apart and join together again.

I thought the last command would need   -an   somewhere, but it didn't
seem to matter where or whether I put it. The mappings show as

in:
  Stream #1:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:0 -> #0:1 (pcm_s16le (native) -> aac (native))
out:
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s

Cheers,
David.

Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

deloptes-2
In reply to this post by ghe-2
ghe wrote:

>> Please note that the subject of this conversation is mp4 (not mp3).
>
> It's claimed that sox will handle mp4:
>
>
https://stackoverflow.com/questions/2666425/how-to-i-configure-sox-to-work-on-mp4
>
> (You do have to install LAME.)
>
>> If you only process uncompressed audio then sox is fine.
>
> It will do the mp's and flac. That I know of -- there may be others.
>
> It normalizes things too. I do that in flac. I don't know if it
> normalizes mp's.

I was always thinking that the problem is the mixing of multi-channel audio
into L/R, where the special effects for some reason are very loud.
It has been some time since I last looked into that, but AFAIR (I'm using
mplayer mostly) I saw it saying mixing 5.1 to 2 on the fly or something
like this.

but my question here is - why the subject with mp4s - do only they suffer
this problem or it is just a case among others?



Reply | Threaded
Open this post in threaded view
|

Re: normalize audio in mp4s

Emanuel Berg-4
deloptes wrote:

> but my question here is - why the subject with mp4s - do only
> they suffer this problem or it is just a case among others?

It is probably a case among others, at least when I wrote it the
intention was to raise this issue in general.

Today I saw "Ford v Ferrari" from last year, an .mkv file.
When they were talking, it was impossible or very difficult to
make out more than occasional words. When they drove their cars,
I had to adjust the volume as it was just rumbling out of
the speakers.

--
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal

123