Converting MP3 to AAC

Here is a Windows command shell script I wrote to convert MP3 files to AAC for my Softbank 821SC phone. The script uses FFmpeg, which I downloaded from here.

@echo off

REM ---------------------------------------------------------------------------
REM  Set the following variable to the ffmpeg.exe path on your system.
REM ---------------------------------------------------------------------------
set FFMPEG_PATH="c:\tools\FFmpeg\ffmpeg.exe"

REM make sure the user provided an argument.
if NOT "%~1" == "" goto ARGS_OK

REM bad arguments, print error and exit.
echo.
echo    Usage examples:
echo       mp3toaac.bat file_to_convert.mp3
echo       mp3toaac.bat *.mp3
echo       mp3toaac.bat some_directory\*.mp3
exit /b 1

:ARGS_OK

REM use for/in so that we can accept individual files or wildcards.
for %%i in ("%~1") do %FFMPEG_PATH% -i "%%~i" "%%~ni.aac"

echo.
echo Done.

exit /b 0

Interesting elements of this batch file:

  • Use of for/in in order to accept both filenames and wildcards.
  • Use of %~X to strip parentheses from a filename variable.
  • Use of %~nX to strip the extension from a filename variable (i.e. retrieve the basename).

About Jeff Fitzsimons

Jeff Fitzsimons is a software engineer in the California Bay Area. Technical specialties include C++, Win32, and multithreading. Personal interests include rock climbing, cycling, motorcycles, and photography.
This entry was posted in Scripting, Technology, Windows. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *