[solved] ffmpeg batch renormalisation

Everything about X, Gnome, KDE, ... and everything running on it

Re: ffmpeg help

Postby dilberts_left_nut » 2018-11-30 23:35

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
dilberts_left_nut
 
Posts: 4913
Joined: 2009-10-05 07:54
Location: enzed

Re: ffmpeg help

Postby Soapm » 2018-12-01 01:25

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
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby dilberts_left_nut » 2018-12-01 01:58

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
dilberts_left_nut
 
Posts: 4913
Joined: 2009-10-05 07:54
Location: enzed

Re: ffmpeg help

Postby Soapm » 2018-12-01 02:35

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: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby Soapm » 2018-12-01 05:34

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
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby dilberts_left_nut » 2018-12-01 06:09

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
dilberts_left_nut
 
Posts: 4913
Joined: 2009-10-05 07:54
Location: enzed

Re: ffmpeg help

Postby Head_on_a_Stick » 2018-12-01 11:49

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
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8324
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: ffmpeg help

Postby Soapm » 2018-12-01 16:57

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
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby Head_on_a_Stick » 2018-12-01 17:05

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.
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8324
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: ffmpeg help

Postby Soapm » 2018-12-01 18:20

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: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby Soapm » 2018-12-01 18:48

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
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby Head_on_a_Stick » 2018-12-01 19:11

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}'
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8324
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: ffmpeg help

Postby Soapm » 2018-12-01 20:29

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: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby Soapm » 2018-12-01 20:48

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
Soapm
 
Posts: 541
Joined: 2012-05-22 04:23

Re: ffmpeg help

Postby Head_on_a_Stick » 2018-12-01 20:52

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:
dbruce wrote:Ubuntu forums try to be like a coffee shop in Seattle. Debian forums strive for the charm and ambience of a skinhead bar in Bacau. We intend to keep it that way.
User avatar
Head_on_a_Stick
 
Posts: 8324
Joined: 2014-06-01 17:46
Location: /dev/chair

PreviousNext

Return to Desktop & Multimedia

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable