Page 1 of 1

Requesting a Linux script to compress mp3 files recursively.

PostPosted: Mon May 29, 2017 5:39 am
by rupeshforu3
Hi I am Rupesh from India. I have a huge directory of size 93 gb with 8500 mp3 files and 2200 sub directories.

I want to compress these mp3 recursively using script and found a Windows batch script which can run only on Windows but can't run on Linux. I am providing the code below.

Code: Select all
@echo off
setlocal EnableExtensions DisableDelayedExpansion

rem // Define constants here:
set "_SOURCE=C:\Rupesh\to convert"
set "_TARGET=E:\Rupesh\ffmpeg out"

rem // Change to source directory temporarily:
pushd "%_SOURCE%" || exit /B 1
rem // 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:
    ffmpeg -i  "%%F" -v quiet -codec:a libmp3lame -b:a 16k -ar 11025 -map_metadata 0 -id3v2_version 3 -write_id3v1 1 "%_TARGET%\%%F\..\%%~nF.mp3"
echo Completed.

exit /B

I am not an experienced Linux user and so I am requesting you to convert the above code into shell script and post it.