Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

[solved] ffmpeg batch renormalisation

Graphical Environments, Managers, Multimedia & Desktop questions.
Message
Author
User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5346
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 13 times
Been thanked: 66 times

Re: ffmpeg help

#16 Post by dilberts_left_nut »

You can just run this part to see what the 'volume' variable is being set to

Code: Select all

ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null
AdrianTM wrote:There's no hacker in my grandma...

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#17 Post by Soapm »

dilberts_left_nut wrote:You can just run this part to see what the 'volume' variable is being set to

Code: Select all

ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null
Where will I see it at, see below, I get an output that ends with a big read, ": No such file or directory"
root@lenny:/video/Music/Jazz# ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null
ffmpeg version 3.2.12-1~deb9u1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
configuration: --prefix=/usr --extra-version='1~deb9u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
: No such file or directory
But if your saying I can rerun the command on the file to see where it was set, that's true but I wanted to know what the script used to normalized the file.

User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5346
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 13 times
Been thanked: 66 times

Re: ffmpeg help

#18 Post by dilberts_left_nut »

Well, yeah, $song isn't set so you'll need to give a real filename.

My point is, you are trying to get your input value of whatever db into the volume variable.
The ouput of that piece of code is what "volume" is being set to.
Play with it so it gives you what you want.
AdrianTM wrote:There's no hacker in my grandma...

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#19 Post by Soapm »

dilberts_left_nut wrote:Well, yeah, $song isn't set so you'll need to give a real filename.

My point is, you are trying to get your input value of whatever db into the volume variable.
The ouput of that piece of code is what "volume" is being set to.
Play with it so it gives you what you want.
Ok, so volume represents the output of the first command. That makes sense except as you've seen posted, it outputs several screens of stuff.

And I'm trying to pick one variable out of those several screens of stuff. So I guess I need a filter of some sort that will look through and narrow down the output to the max_volume variable. I've tried using;

max_volume
max_volume:
"volume=`echo $sDBLevel`dB" = (from the other sites script)

Am I in the ballpark? I assume that's where "cut" comes into play but I'm clueless after reading that man page most of the night.

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#20 Post by Soapm »

I stared at this, flipping and flopping it all night and I think I know what you're saying. This isn't working because the command is defining volume as the inclusive output of this command; Volume = everything inside ( )

Code: Select all

do volume=$(ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null)
so what I have to do is define volume by picking out just the max_volume variable...

The other command used "echo" as the means of picking out a variable, what that variable is I don't know but I think it's the clue to my success...

Code: Select all

"volume=`echo $sDBLevel`dB"

User avatar
dilberts_left_nut
Administrator
Administrator
Posts: 5346
Joined: 2009-10-05 07:54
Location: enzed
Has thanked: 13 times
Been thanked: 66 times

Re: ffmpeg help

#21 Post by dilberts_left_nut »

The 'sDBLevel' variable is something peculiar to that other script you posted a bit of, but you didn't show the line where it was defined. It's really just the equivalent of 'volume' in your script.

Try trimming down the output to just what you want, by piping it ( with a | ) to some other commands, namely grep and cut.

Code: Select all

command -param1 -param2 blah | grep something | cut -d" " -f2
or such
AdrianTM wrote:There's no hacker in my grandma...

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: ffmpeg help

#22 Post by Head_on_a_Stick »

Soapm wrote:I had to add quotes around $song variable to account for files with spaces in their names.
Ah yes, very well done for spotting my, er, deliberate mistake there, you learn fast! :oops:

https://mywiki.wooledge.org/Quotes
soapm wrote:the full output of the command
Oh dear, how `awk`ward :D

Let's try:

Code: Select all

#!/bin/sh
for song in *.mp3
do volume=$(ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null | awk '/max_volume/{gsub("-","");print $5}')
   ffmpeg -i "$song" -af "volume=${volume}dB" Jazz2/"$song"
done
deadbang

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#23 Post by Soapm »

Head_on_a_Stick wrote:Let's try:

Code: Select all

#!/bin/sh
for song in *.mp3
do volume=$(ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null | awk '/max_volume/{gsub("-","");print $5}')
   ffmpeg -i "$song" -af "volume=${volume}dB" Jazz2/"$song"
done
Thanks again, I forgot to tell you that I'm getting the below error with the second line. I have to remove dB to make the error go away so the command will complete. It seems to run but I don't know what value it's using for "volume=xxdB", only that it isn't normalized to the max_volume of 0.

It would be nice if I knew what value it was using for volume in the second line so I at least know what value it's picking. Anyway to make it log or output the value it's using for volume?

Code: Select all

[Parsed_volume_0 @ 0x560265e9b900] [Eval @ 0x7ffed564d720] Undefined constant or missing '(' in 'dB'
[Parsed_volume_0 @ 0x560265e9b900] Error when evaluating the volume expression 'dB'
[AVFilterGraph @ 0x560265e75a60] Error initializing filter 'volume' with args 'dB'
Error opening filters!
You did give me a lot more studying to do, that awk line will take me a year to decipher ROFL...

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: ffmpeg help

#24 Post by Head_on_a_Stick »

Soapm wrote:It would be nice if I knew what value it was using for volume in the second line so I at least know what value it's picking. Anyway to make it log or output the value it's using for volume?
Just run the command contained within $( and ), that is what is being stored as $volume

So

Code: Select all

ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null | awk '/max_volume/{gsub("-","");print $5}'
will show the output that will be stored as $volume for $song, if that makes sense.
Soapm wrote:that awk line will take me a year to decipher ROFL...
Yes, sorry, terribly bad form on my part that, the urge to show off is always bubbling up...

In brief, the /max_volume/ bit searches for all lines containing that expression then gsub swaps all minus signs for nothing ("") and print spews out the fifth column. Hth.
deadbang

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#25 Post by Soapm »

Head_on_a_Stick wrote:So

Code: Select all

ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null | awk '/max_volume/{gsub("-","");print $5}'
will show the output that will be stored as $volume for $song, if that makes sense.
I pasted that line onto the CLI, of course with the name of a song in the $song field. It seemed to run like normal??? Where will I see the output?
Head_on_a_Stick wrote:
Soapm wrote:that awk line will take me a year to decipher ROFL...
Yes, sorry, terribly bad form on my part that, the urge to show off is always bubbling up...

In brief, the /max_volume/ bit searches for all lines containing that expression then gsub swaps all minus signs for nothing ("") and print spews out the fifth column. Hth.
Keep showing off, I love out of the box thinking and learning new things... It's just when I went to the man page, my eyes crossed and my mind drifted because it was all Hebrew after the third word.

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#26 Post by Soapm »

Code: Select all

null /dev/null
Been reading and it seems dev/null is how you discard an output. Could that be causing the problem, the output is discarded before awk has a chance to read it?

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: ffmpeg help

#27 Post by Head_on_a_Stick »

Turns out that ffmpeg outputs to stderr rather than stdout so try:

Code: Select all

ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null 2>&1 | awk '/max_volume/{gsub("-","");print $5}'
deadbang

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#28 Post by Soapm »

Head_on_a_Stick wrote:Turns out that ffmpeg outputs to stderr rather than stdout so try:

Code: Select all

ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null 2>&1 | awk '/max_volume/{gsub("-","");print $5}'
Perfect, it came back with 6.6 which was the max_volume of the file I was testing. Let me give it a try in the script...

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: ffmpeg help

#29 Post by Soapm »

Works like a charm :D, in case anyone needs it down the road;

Code: Select all

#!/bin/sh
for song in *.mp3
do volume=$(ffmpeg -i "$song" -af "volumedetect" -vn -sn -dn -f null /dev/null 2>&1 | awk '/max_volume/{gsub("-","");print $5}')
ffmpeg -i "$song" -af "volume=${volume}dB" Jazz2/"$song"
done
The offer is still good for my first born, he's fat, lazy, a huge grocery bill and a chip off the ole block... But say the word and he can be yours...

I'll even buy the one way ticket. :D

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: ffmpeg help

#30 Post by Head_on_a_Stick »

Woot! Victory is sweet :)
Soapm wrote:The offer is still good for my first born, he's fat, lazy, a huge grocery bill and a chip off the ole block...
Ah, thank you for the very kind offer but we already have a feckless proto-teen in the household so I think the position is taken :mrgreen:
deadbang

kevinthefixer
Posts: 190
Joined: 2018-05-05 22:30

Re: ffmpeg help

#31 Post by kevinthefixer »

sunrat wrote:Do you realise using ffmpeg-normalize will destroy some quality of your music? It has to decode the file first and then re-encode after normalization.
This is true to a limited extent. The audio editor I've been using for almost 20 years (Cool Edit 2000), in its help files, recommends not expanding/recompressing music files more than three times (IIRC). And unless you are young and have very good and well-trained hearing, I doubt you'll hear the artifacts generated this way. Since the OP indicated the whole process was intended for listening in a car, it's inconcievable the degradation would be heard at all. Maybe in my home office/sound studio, but I doubt it, certainly not by my 60+ year-old ears. It's more of a good-standard-practice sort of a thing, like shutting down all your running programs before hitting the power switch.

User avatar
Head_on_a_Stick
Posts: 14114
Joined: 2014-06-01 17:46
Location: London, England
Has thanked: 81 times
Been thanked: 133 times

Re: ffmpeg help

#32 Post by Head_on_a_Stick »

kevinthefixer wrote:Since the OP indicated the whole process was intended for listening in a car, it's inconcievable the degradation would be heard at all
Perhaps the OP has a decent car with a decent audio system, for example:

https://www.naimaudio.com/naim-for-bentley

^ I wouldn't be playing anything less than 24-bit@192kHz on that system, flac ftw! :mrgreen:

@OP: please add [SOLVED] to the thread title to help others; it may be best to change the title to something more descriptive that will show up in search engines — "ffmpeg batch renormalisation", for example.
deadbang

User avatar
Soapm
Posts: 603
Joined: 2012-05-22 04:23
Has thanked: 1 time

Re: [solved] ffmpeg batch renormalisation

#33 Post by Soapm »

Done...

With my hearing, well, I now wear bluetooth headphones to watch TV in the bed at night. I was waking the wife up.

What I don't like about mp3 is that it remove a lot of the bass, not sure if I just like bass or if that's all I can hear there days but mp3 sure makes songs sound dreary... I'm sticking with flac whenever I can find them but I got most of my tunes from Amazon.

kevinthefixer
Posts: 190
Joined: 2018-05-05 22:30

Re: [solved] ffmpeg batch renormalisation

#34 Post by kevinthefixer »

mp3 format does not remove bass, not in and of itself. Amazon may well remove some just by using substandard equipment. My hearing is not bad, just not as acute as it once was, I can no longer hear the difference between uncompressed .wav files and .mp3s, but when I could it was all in the upper registers.

Post Reply