(view source code of appendsilence.bat as plain text)
@ECHO OFF
:: Check command line arguments
IF "%~2"=="" GOTO Syntax
IF NOT "%~3"=="" GOTO Syntax
IF /I NOT "%~x1"==".mp3" GOTO Syntax
IF %2 LSS 1 GOTO Syntax
IF %2 GTR 3600 GOTO Syntax
FFMPEG.EXE -h >NUL 2>&1 || GOTO Syntax
SETLOCAL
SET RC=1
:: FFMPEG command by Davide Piras
:: https://stackoverflow.com/a/7465173
FOR /F "tokens=5-7 delims=, " %%A IN ('FFMPEG.EXE -i "%~1" 2^>^&1') DO (
IF "%%~B"=="Hz" (
SET SampleRate=%%~A
SET Channels=%%C
SET RC=0
)
)
:: Technique explained by Ilogan
:: https://superuser.com/a/579110
:: -safe 0 option discussed at
:: https://stackoverflow.com/a/38999363
FFMPEG.EXE -f lavfi -i anullsrc=channel_layout=%Channels%:sample_rate=%SampleRate% -t %~2 silence_%~2sec.mp3
IF ERRORLEVEL 1 SET RC=1
:: Note: to PREPEND the silence, swap the order of files in the next 2 lines
> %~n0.txt echo file '%~s1'
>> %~n0.txt echo file 'silence_%~2sec.mp3'
FFMPEG.EXE -f concat -safe 0 -i %~n0.txt -codec copy "%~n1_%~2sec_silence.mp3"
IF ERRORLEVEL 1 SET RC=1
:: Remove temporary files
DEL silence_%~2sec.mp3
DEL %~n0.txt
ENDLOCAL & EXIT /B %RC%
:Syntax
ECHO.
ECHO AppendSilence.bat, Version 1.02
ECHO Use FFMPEG to append silence to an existing mp3 file
ECHO.
ECHO Usage: AppendSilence.bat mp3inputfile.mp3 seconds
ECHO.
ECHO Where: mp3inputfile.mp3 is the mp3 file to which silence will be appended
ECHO seconds is the number of seconds of silence to be appended
ECHO.
ECHO Notes: The output file name will be {mp3inputfile}_{seconds}sec_silence.mp3.
ECHO Return code (ErrorLevel) will be 1 in case of errors, otherwise 0.
ECHO.
ECHO Credits: FFMPEG: https://ffmpeg.org/
ECHO Use FFMPEG to get information on input file:
ECHO Davide Piras, https://stackoverflow.com/a/7465173
ECHO Use FFMPEG to create and append silence:
ECHO Ilogan, https://superuser.com/a/579110
ECHO Avoid "concat: unsafe file name" error:
ECHO https://stackoverflow.com/a/38999363
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
EXIT /B 1
page last modified: 2024-04-16; loaded in 0.0094 seconds