Created
June 20, 2023 14:15
-
-
Save benlesh/6c09ebbe81d4091d76941fa8927dc3aa to your computer and use it in GitHub Desktop.
Convert all WAV files in a directory to MP3 files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM NOTE that this does NOT uninstall ffmpeg when done | |
@echo off | |
setlocal enabledelayedexpansion | |
echo Current directory: %cd% | |
REM Set the download URL for FFmpeg | |
set "ffmpeg_url=https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip" | |
REM Set the temporary directory for downloading and extracting FFmpeg | |
set "temp_dir=temp" | |
REM Check if FFmpeg is already installed | |
if exist "%temp_dir%\ffmpeg-master-latest-win64-gpl\bin\ffmpeg.exe" ( | |
echo FFmpeg is already installed. | |
) else ( | |
echo Downloading FFmpeg... | |
curl -L -o "%temp_dir%\ffmpeg-master-latest-win64-gpl.zip" "%ffmpeg_url%" | |
if errorlevel 1 ( | |
echo FFmpeg download failed, please check your internet connection and the ffmpeg_url. | |
exit /b | |
) | |
echo Extracting FFmpeg... | |
powershell -Command "Expand-Archive -Path '%temp_dir%\ffmpeg-master-latest-win64-gpl.zip' -DestinationPath '%temp_dir%'" | |
if errorlevel 1 ( | |
echo Failed to extract FFmpeg. | |
exit /b | |
) | |
echo FFmpeg installation complete. | |
) | |
REM Set the path to the FFmpeg executable | |
set "ffmpeg=%temp_dir%\ffmpeg-master-latest-win64-gpl\bin\ffmpeg.exe" | |
REM Check if FFmpeg executable exists at the specified path | |
if not exist "%ffmpeg%" ( | |
echo FFmpeg executable not found at the specified path: "%ffmpeg%" | |
exit /b | |
) | |
echo Found FFmpeg executable at: "%ffmpeg%" | |
REM Convert .wav files to .mp3 | |
for %%A in ("%~dp0*.wav") do ( | |
set "input_file=%%~fA" | |
set "output_file=%%~dpnA.mp3" | |
echo Converting file: "!input_file!" to "!output_file!" | |
"%ffmpeg%" -i "!input_file!" -vn -ar 44100 -ac 2 -b:a 192k "!output_file!" | |
if errorlevel 1 ( | |
echo Failed to convert "!input_file!". | |
exit /b | |
) | |
) | |
echo Conversion complete. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment