Batch Audio File Conversion
Friday, December 19th, 2008I had to make some audio available via the world wide web. But, it had to be protected, in so far as that is possible through basic HTTP streaming. I figured I would place the audio in Flash Video format (FLV), to which I then appended a bogus file extension ending, to complicate the life of anyone who went diving into his or her browser’s cache for the downloaded media. So, I converted the WAV and MP3 files to FLV files (Flash Video Format files).
Again, I used batch scripting, but I also used two additional programs: FFMPEG and FLVMDI. The first, FFMPEG, is a command line audio/video conversion program. It’s used to convert the WAV or MP3 file to FLV. The second, FLVMDI, grabs some information about the FLV file, such as creation time and duration, etc., and, in this case, saves the information to an XML file. Here is an example. I needed the metadata for two reasons: preservation purposes (so I could see something about the file when it was stored in the system) and the duration element was necessary when playing the audio.
Two batch scripts: wavs2flvs and mp3s2flvs.
wavs2flvs
echo.
echo This file converts WAV files to FLV files.
echo FFMPEG and FLVMDI are required programs.
echo This file presumes there are files in the wavs_todo subdirectory.
echo The output (sub)directory, /flvs, should already exist.
echo The converted WAV file will be moved to /wavs, which also should exist.
echo Sample Rate set at 192.
echo Bitrate set at 192.
echo.
SET CURRDIR=%CD%
SET FFMPEG=C:/av_conversion/ffmpeg/ffmpeg
SET FLVMDI=C:/av_conversion/flvmdi/flvmdi
IF EXIST wavs_todo GOTO FLVSOUT
echo wavs_todo subdirectory does not exist. Exiting.
GOTO END
:FLVSOUT
IF EXIST flvs GOTO WAVSOUT
echo flvs output subdirectory does not exist. Exiting.
GOTO END
:WAVSOUT
IF EXIST wavs GOTO CONVERT
echo wavs output subdirectory does not exist. Exiting.
GOTO END
:CONVERT
cd wavs_todo
dir *.wav /b > output.txt
for /f "delims=" %%i in (output.txt) do "%FFMPEG%" -i "%%i" -ab 192 -ar 44100 -f flv "%CURRDIR%/flvs/%%~ni.flv"
for /f "delims=" %%i in (output.txt) do "%FLVMDI%" "%CURRDIR%/flvs/%%~ni.flv" /x
for /f "delims=" %%i in (output.txt) do copy "%%i" "%CURRDIR%/wavs/%%i"
del *.wav
del output.txt
echo.
echo Files converted.
cd %CURRDIR%
GOTO END
:END
echo.
mp3s2flvs
echo.
echo This file converts MP3 files to FLV files.
echo FFMPEG and FLVMDI are required programs.
echo This file presumes there are files in the mp3s_todo subdirectory.
echo The output (sub)directory, /flvs, should already exist.
echo The converted MP3 file will be moved to /mp3s, which also should exist.
echo Sample Rate set at 192.
echo Bitrate set at 192.
echo.
SET CURRDIR=%CD%
SET FFMPEG=C:/av_conversion/ffmpeg/ffmpeg
SET FLVMDI=C:/av_conversion/flvmdi/flvmdi
IF EXIST mp3s_todo GOTO FLVSOUT
echo mp3s_todo subdirectory does not exist. Exiting.
GOTO END
:FLVSOUT
IF EXIST flvs GOTO MP3SOUT
echo flvs output subdirectory does not exist. Exiting.
GOTO END
:MP3SOUT
IF EXIST mp3s GOTO CONVERT
echo mp3s output subdirectory does not exist. Exiting.
GOTO END
:CONVERT
cd mp3s_todo
dir *.mp3 /b > output.txt
for /f "delims=" %%i in (output.txt) do "%FFMPEG%" -i "%%i" -ab 192 -ar 44100 -f flv "%CURRDIR%/flvs/%%~ni.flv"
for /f "delims=" %%i in (output.txt) do "%FLVMDI%" "%CURRDIR%/flvs/%%~ni.flv" /x
for /f "delims=" %%i in (output.txt) do copy "%%i" "%CURRDIR%/mp3s/%%i"
del *.mp3
del output.txt
echo.
echo Files converted.
cd %CURRDIR%
GOTO END
:END
echo.
Download the scripts:
Audio Conversion Scripts