Last active
July 28, 2025 19:10
-
-
Save AbduEhab/4a3f21b35bd006e893f1aee48cdcd06a to your computer and use it in GitHub Desktop.
This is a bat file that transcodes all audio files in a directory into `.opus` files. I use this neat script to sync my `.flac` library with my mobile library.
This file contains hidden or 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
| @echo off | |
| rem Copies the original directory structure from F:\Music to D:\Music | |
| rem xcopy /T %1 %2 | |
| Robocopy %1 %2 /E /XF *.flac *.mp3 *.mp4 | |
| for /R %1 %%i in (*.flac;*.mp3;*.mp4) do ( | |
| rem check if file exists | |
| if exist "%~d2%%~pni.opus" ( | |
| echo "%~d2%%~pni.opus" already exists | |
| ) else ( | |
| echo Converting "%%~fi" | |
| rem convert to opus | |
| ffmpeg -v quiet -i "%%~fi" -map 0:a:0 -map_metadata 0 -c:a libopus -b:a 128k -frame_duration 20 "%~d2%%~pni.opus" | |
| ) | |
| ) | |
| echo Done | |
| pause | |
| @echo off | |
| setlocal EnableDelayedExpansion | |
| :: Ask for source and destination directories | |
| set /p SRC="Enter the source directory (e.g., F:\Music): " | |
| set /p DEST="Enter the destination directory (e.g., D:\Music): " | |
| :: Copy directory structure (excluding files) | |
| robocopy "%SRC%" "%DEST%" /E /XF *.flac *.mp3 *.mp4 *.opus /CREATE | |
| :: Loop through all audio files | |
| for /R "%SRC%" %%i in (*.flac *.mp3 *.mp4) do ( | |
| set "srcfile=%%i" | |
| set "relpath=%%~pi" | |
| set "filename=%%~ni" | |
| set "outfile=%DEST%!relpath!!filename!.opus" | |
| if exist "!outfile!" ( | |
| echo "!outfile!" already exists | |
| ) else ( | |
| echo Converting "%%i" | |
| ffmpeg -v quiet -i "%%i" -map 0:a:0 -map_metadata 0 -c:a libopus -b:a 128k -frame_duration 20 "!outfile!" | |
| ) | |
| ) | |
| echo Done | |
| pause | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment