Script to bulk-lower volume of flac files using ffmpeg doesn't work (Solved)

interpretive language scripts


Moderator: Forum moderators

Post Reply
User avatar
gychang
Posts: 584
Joined: Fri Aug 28, 2020 4:51 pm
Location: San Diego, CA
Has thanked: 205 times
Been thanked: 63 times

Script to bulk-lower volume of flac files using ffmpeg doesn't work (Solved)

Post by gychang »

Several of my flac album folders are too loud. I like to lower the volume but maintain the same file name and extension. FFmeg command that lowers the volume is "ffmpeg -i input.flac -filter:a "volume=0.5" output.flac". I am thinking the find command may work with -exec option. Within a folder following gives an error.

find . -type f -iname "*.flac" -exec ffmpeg -i -filter:a "volume=0.5" {} \;

gives an error " -filter-a: protocol not found..."
can someone suggest a solution?, the above ffmpeg command works fine in a single .flac file.

Last edited by gychang on Fri May 21, 2021 1:04 pm, edited 1 time in total.

======

Puppy Bytes, utube videos
https://www.youtube.com/channel/UCg-DUU ... u62_iqR-MA

======

User avatar
fredx181
Posts: 2997
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 364 times
Been thanked: 1272 times
Contact:

Re: bulk flac files to lower volume using ffmpeg

Post by fredx181 »

Hi gychang, this should do it:

Code: Select all

find . -type f -iname "*.flac" -exec ffmpeg -i "{}" -filter:a "volume=0.5" -sample_fmt s16 -f flac "{}".tmp \; -exec mv -f "{}".tmp "{}" \;

(ffmpeg cannot edit files in place, so convert first to .tmp, then use mv -f to rename to original name)
I added "-sample_fmt s16" to make it bit depth 16, without it, it will become 24 bits (so leave it out if you prefer that).

Fred

User avatar
gychang
Posts: 584
Joined: Fri Aug 28, 2020 4:51 pm
Location: San Diego, CA
Has thanked: 205 times
Been thanked: 63 times

Re: bulk flac files to lower volume using ffmpeg

Post by gychang »

fredx181 wrote: Fri May 21, 2021 6:13 am

Hi gychang, this should do it:

Code: Select all

find . -type f -iname "*.flac" -exec ffmpeg -i "{}" -filter:a "volume=0.5" -sample_fmt s16 -f flac "{}".tmp \; -exec mv -f "{}".tmp "{}" \;

(ffmpeg cannot edit files in place, so convert first to .tmp, then use mv -f to rename to original name)
I added "-sample_fmt s16" to make it bit depth 16, without it, it will become 24 bits (so leave it out if you prefer that).

Fred

works perfect!, thanks.

======

Puppy Bytes, utube videos
https://www.youtube.com/channel/UCg-DUU ... u62_iqR-MA

======

williams2
Posts: 1061
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 304 times

Re: Script to bulk lower flac files volume using ffmpeg doesn't work (Solved)

Post by williams2 »

You can use replaygain to normalize audio files, so that when played back on a replaygain capable player, the volume of each audio file is adjusted individually as they are played. The volume level for each file is stored in the meta data of each file. The audio files are not re-encoded.

For example: https://xiph.org/flac/documentation_tools_metaflac.html

--add-replay-gain Calculates the title and album gains/peaks of the given FLAC files as if all the files were part of one album, then stores them as FLAC tags. The tags are the same as those used by vorbisgain

https://xiph.org/flac/documentation_tools_metaflac.html
https://www.bobulous.org.uk/misc/Replay ... Linux.html
https://en.wikipedia.org/wiki/Replay_Gain

Another alternative to re-encoding is to use audio compression. For example, in Audacious, Effects, Dynamic Range Compressor. Audio compression could be useful in certain situations.

User avatar
gychang
Posts: 584
Joined: Fri Aug 28, 2020 4:51 pm
Location: San Diego, CA
Has thanked: 205 times
Been thanked: 63 times

Re: Script to bulk lower flac files volume using ffmpeg doesn't work (Solved)

Post by gychang »

williams2 wrote: Fri May 21, 2021 6:43 pm

For example: https://xiph.org/flac/documentation_tools_metaflac.html

--add-replay-gain Calculates the title and album gains/peaks of the given FLAC files as if all the files were part of one album, then stores them as FLAC tags. The tags are the same as those used by vorbisgain

I use mpv to listen to my flac files in puppy. Automatic on-the-fly normalization would be ideal for each flac file. Using the command find . -type f -iname "*.flac" -exec metaflac --add-replay-gain {} \; from the flac folder terminal seems to be the answer! :thumbup2:

======

Puppy Bytes, utube videos
https://www.youtube.com/channel/UCg-DUU ... u62_iqR-MA

======

Post Reply

Return to “Scripts”