Clicky

20201031

Convert all FLAC files in a folder to MP3s

The next script takes a folder path as imput, checks all the FLAC files in that folder, and creates MP3 files for each FLAC file found. There is only one prerequisite: FFMPEG should be installed. Save the script as "ConvertFlacToMp3.bat"

Usage:

C:\> ConvertFlacToMp3.bat {path to FLAC files}

or:

Create a shortcut to this script on the desktop and you can drag folders (from Windows Explorer) to the icon.


There are couple of tricks in the script:

- Normalization of the passed folder (e.g. removal of qoutes, required for drag-and-drop)

- Enumeration of FLAC files in the folder

- Filename contruct of the MP3 filename 


You play around with the script and find out yourself. One improvement could be that the MP3 files are stored in a (new) seperate folder. 

 

 ---8< ---------------------------------------------------------------

@echo off

setlocal ENABLEDELAYEDEXPANSION

echo.
echo *** Usage:
echo        C:\^> %0 {path to folder with *.FLAC files}
echo        Or drag the folder with FLAC files to a shortcut of this script.

if %1.==. goto :EOF
if not exist %1 goto :EOF

set cmdParam=%1
set firstChar=%cmdParam:~0,1%
if ^%firstChar% EQU ^"  (
    for /f "tokens=*" %%i in (%1) do set sourceFolder=%%~i
) ELSE (
    set sourceFolder=%1
)   
set SRC=!sourceFolder!

set t=%time%
set ffmpeg=c:\scripts\ffmpeg\bin\ffmpeg.exe

echo.
echo *** Processing folder: "%SRC%"...

for %%i in ("%SRC%\*.flac") do (
    
    set fPath=%%~dpi
    set fName=%%~ni
    
    for %%j in ("!fName!") do set nam=!fPath!!fName!.mp3
    
    echo *** %%i
    %ffmpeg% -y -loglevel panic -i "%%i" -vsync 0 -codec:a libmp3lame -qscale:a 2 "!nam!"

)

echo *** Start: %t%
echo *** End  : %time%

start /separate explorer "%SRC%"

ping -n 60 localhost >nul

---8< ---------------------------------------------------------------

 

Script invocation:


 After the script finishes, Explorer shows the folder with FLAC and MP3 files:



 

 

No comments :

Post a Comment

Real Time Web Analytics