@echo off
set ztmp_enccommon=D:\bin\foobar2000\encoders
set ztmp_ffmpeg=%ztmp_enccommon%\ffmpeg.exe
set ztmp_ffprobe=%ztmp_enccommon%\ffprobe.exe
set ztmp_aac=%ztmp_enccommon%\x86\neroAacEnc.exe
set ztmp_vorbis=%ztmp_enccommon%\oggenc2.exe
set ztmp_opus=%ztmp_enccommon%\opusenc.exe
set ztmp_lame=%ztmp_enccommon%\lame.exe
set ztmp_flac=%ztmp_enccommon%\flac.exe
setlocal EnableExtensions
setlocal EnableDelayedExpansion
set ztmp_file=%~n1
shift
if not exist "%ztmp_file%.wav" (
echo Could not find "%ztmp_file%.wav"
goto :failed
)
if exist "out\%ztmp_file%.opus" (
del "out\%ztmp_file%.opus"
)
if exist "out\%ztmp_file%.ogg" (
del "out\%ztmp_file%.ogg"
)
if exist "out\%ztmp_file%.m4a" (
del "out\%ztmp_file%.m4a"
)
if exist "out\%ztmp_file%.webm" (
del "out\%ztmp_file%.webm"
)
if exist "out\%ztmp_file%.flac" (
del "out\%ztmp_file%.flac"
)
if exist "out\%ztmp_file%.mp3" (
del "out\%ztmp_file%.mp3"
)
if exist "out\%ztmp_file%.wav" (
del "out\%ztmp_file%.wav"
)
echo Converting %ztmp_file%.wav ...
rem SAMPLE RATE CHECK AND CONVERT
echo Checking sample rate...
%ztmp_ffprobe% -loglevel 8 -show_streams "%ztmp_file%.wav" | grep sample_rate | cut -d"=" -f2 > tmp.txt
if errorlevel 1 goto failed
set /p ztmp_samplerate=<tmp.txt && del tmp.txt
if "!ztmp_samplerate!" NEQ "44100" (
echo Sample rate ^(!ztmp_samplerate!Hz^) is not 44100Hz, resampling...
%ztmp_ffmpeg% -loglevel 8 -i "%ztmp_file%.wav" -c:a pcm_s16le -ac 2 -ar 44100 -f wav "%ztmp_file%_tmp.wav" 1>nul
if errorlevel 1 goto failed
del "%ztmp_file%.wav"
if errorlevel 1 goto failed
move "%ztmp_file%_tmp.wav" "%ztmp_file%.wav"
if errorlevel 1 goto failed
echo Resampled to 44100Hz...
) else (
echo Sample rate ^(!ztmp_samplerate!Hz^) is acceptable...
)
rem ENCODE AAC
echo Encoding %ztmp_file%.m4a (LC-AAC)
%ztmp_aac% -cbr 163840 -if "%ztmp_file%.wav" -of "out\%ztmp_file%.m4a" 1>nul 2>nul
if errorlevel 1 goto failed
rem ENCODE OPUS
echo Encoding %ztmp_file%.opus (OPUS)
%ztmp_opus% --bitrate 192 "%ztmp_file%.wav" "out\%ztmp_file%.opus" 1>nul 2>nul
if errorlevel 1 goto failed
rem ENCODE VORBIS
echo Encoding %ztmp_file%.webm (Vorbis)
%ztmp_vorbis% -q6 -o "%ztmp_file%.ogg" "%ztmp_file%.wav" 1>nul 2>nul
if errorlevel 1 goto failed
%ztmp_ffmpeg% -loglevel 8 -i "%ztmp_file%.ogg" -c:a copy -c:v null -f webm "out\%ztmp_file%.webm" 1>nul
if errorlevel 1 goto failed
del "%ztmp_file%.ogg"
if errorlevel 1 goto failed
rem ENCODE MP3
echo Encoding %ztmp_file%.mp3 (LAME)
%ztmp_lame% --quiet -V1 "%ztmp_file%.wav" "out\%ztmp_file%.mp3" 1>nul
if errorlevel 1 goto failed
rem ENCODE FLAC
echo Encoding %ztmp_file%.flac (FLAC)
%ztmp_flac% --best -o "out\%ztmp_file%.flac" "%ztmp_file%.wav" 1>nul 2>nul
if errorlevel 1 goto failed
rem COPY WAV
echo Copying %ztmp_file%.wav (WAVE)
copy "%ztmp_file%.wav" "out\%ztmp_file%.wav"
if exist "out\%ztmp_file%.wav" (
rem Only delete input file if it was successfully copied
del "%ztmp_file%.wav"
)
if errorlevel 1 goto failed
goto cleanup
:cleanup
set "ztmp_file="
set "ztmp_ffmpeg="
set "ztmp_aac="
set "ztmp_opus="
set "ztmp_vorbis="
set "ztmp_lame="
set "ztmp_flac="
set "ztmp_samplerate="
goto :eof
:failed
echo This stage of the encoding has failed...
goto cleanup
:eof