Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal
- chcp 65001>nul
- if "%1" == "restart" goto :convert
- :: Path to ffmpeg and sourcedir
- set "ffmpeg=c:\ffmpeg.exe"
- set "sourcedir=%~dp0"
- set /p "mapfiles=Total mp4 files in each map: "
- :: Check if there are mp4-files
- if not exist "*.mp4" (
- echo No mp4 files found. Exiting...
- pause
- exit /b
- )
- :: Initialising variable
- set /a mapnum=1
- :process
- :: Make folders
- set "targetdir=%sourcedir%mp4_aac_m4a_%mapnum%"
- if not exist "%targetdir%" mkdir "%targetdir%"
- if not exist "%targetdir%\aac" mkdir "%targetdir%\aac"
- if not exist "%targetdir%\m4a" mkdir "%targetdir%\m4a"
- :: Move files to new folder
- set /a moved=0
- for /f "delims=" %%f in ('dir /b "*.mp4"') do (
- call :moving "%%f"
- )
- if %errorlevel% equ 5 (call :restart_script)
- if not exist "*.mp4" (call :restart_script)
- exit
- :convert
- :: Convert .mp4 to .aac and .m4a
- for /l %%g in (1,1,%mapnum%) do (
- for /f "delims=" %%a in ('dir /b "%sourcedir%mp4_aac_m4a_%%g\*.mp4"') do (
- echo Extracting to %%~na.aac
- "%ffmpeg%" -i "%sourcedir%mp4_aac_m4a_%%g\%%a" -vn -sn -c:a aac -b:a 320k "%sourcedir%mp4_aac_m4a_%%g\aac\%%~na.aac" 1>NUL 2>&1
- )
- for /f "delims=" %%a in ('dir /b "%sourcedir%mp4_aac_m4a_%%g\aac\*.aac"') do (
- echo Converting to %%~na.m4a
- "%ffmpeg%" -i "%sourcedir%mp4_aac_m4a_%%g\aac\%%a" -bsf:a aac_adtstoasc -codec copy "%sourcedir%mp4_aac_m4a_%%g\m4a\%%~na.m4a" 1>NUL 2>&1
- )
- )
- echo All files processed.
- pause
- exit
- :moving
- set "file=%~1"
- set "escapedfile=%file:&=^&%"
- if not exist "%file%" (exit /b 5)
- echo Moving... %escapedfile%
- move "%file%" "%targetdir%" >nul
- set /a moved+=1
- if %moved% equ %mapfiles% set /a mapnum+=1 & goto :process
- exit /b 5
- :restart_script
- :: Restarting script...
- endlocal
- call "%~f0" restart
- exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement