# Hydrogenaudio Forums

## Lossy Audio Compression => MP3 => Topic started by: rupeshforu3 on 2017-05-29 09:05:09

Title: Requesting Linux script for lame to compress mp3 files recursively.
Post by: rupeshforu3 on 2017-05-29 09:05:09
Hi I am Rupesh from India. I have a huge directory of size 93.5 gb with 8500 mp3 files and 2000 sub directories.

All these mp3s are speeches recorded by someone at 64 kbps. I want to compress these files recursively using lame with 16 kbps bit rate and 11050 sample rate.

I have found some guis or front end for lame like lamexp,razorlame,lamefrontend none has options to compress mp3 files recursively at 16 kbps. On searching net I found a script for ffmpeg to compress recursively. I have deleted ffmpeg code and substituted lame code instead of which I am providing below

Code: [Select]
.@echo offsetlocal EnableExtensions DisableDelayedExpansionrem // Define constants here:set "_SOURCE=I:\to convert3"set "_TARGET=H:\converted\lame4"rem // Change to source directory temporarily:pushd "%_SOURCE%" || exit /B 1rem // Enumerate source files, return paths relative to the source directory:for /F "delims=" %%F in ('xcopy /L /S /I ".\*.mp3" "%_TARGET%" ^| find ".\"') do (    echo Currently converting "%%F"...    rem // Create destination directory, suppress error if it aready exists:    mkdir "%_TARGET%\%%F\.." 2> nul    rem // Perform actual file conversion, using paths relative to target directory:    lame    --abr 16 -m j -q 0 --resample 22.05 --priority 4   "%%F" "%_TARGET%\%%F\..\%%~nF.mp3")echo Completed.popdendlocal

The above script runs only on Windows but can't run on Linux and it is better to run the script on Linux.

Please try to convert the above Windows batch script to Linux shell script and post it.

Please try to suggest if you know a front end for lame which can compress mp3 files recursively at 16 kbps.

Regards,
Rupesh.
Title: Re: Requesting Linux script for lame to compress mp3 files recursively.
Post by: smok3 on 2017-05-29 09:26:45
There is an outline of the  two-step process to avoid overcomplicated scripting
Debate somewhere on this very forums (can't find right now).
Title: Re: Requesting Linux script for lame to compress mp3 files recursively.
Post by: johnb on 2017-05-29 17:04:15
I am positive foobar2000 can do this.
Title: Re: Requesting Linux script for lame to compress mp3 files recursively.
Post by: Thad E Ginathom on 2017-05-29 19:29:54
There is a tool called pacpl which I have used to convert FLAC/whatever files to mp3s for portable use. It is recursive, and replicates the directory tree --- but I don't think it can be be used to convert and  overwrite in place.

It is quite powerful and option-rich

pacpl home (http://vorzox.wixsite.com/pacpl)

man pacpl (http://manpages.ubuntu.com/manpages/zesty/man1/pacpl.1.html)

There is almost certainly a possible single-line "find" command which would do what you want. See the -exec option of find. You'd better have a good backup before experimenting, though!

man find (http://manpages.ubuntu.com/manpages/precise/man1/find.1.html)

find searches recursively and does whatever you tell it to do with the results. Be careful: it does what you tell it, whether it was what you wanted or something you absolutely did not want.

That's the nature of command-line Unix/Linux. If you are working with Linux already, then you probably know that already. It is an awful lot safer to copy/convert the directory tree somewhere else, deleting the original files only when you  are sure the conversion has given you what you want. And pacpl should do that for you without scripting or intricate find-command stuff.

EDIT: looks like the script in the video above is using find, but it really hurts my head to watch text stuff on youtube.