Advertisement
Lucky4Me

MP4_AAC_M4A

Feb 11th, 2025 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.75 KB | Source Code | 0 0
  1. @echo off
  2. setlocal
  3. chcp 65001>nul
  4. if "%1" == "restart" goto :convert
  5. :: Path to ffmpeg and sourcedir
  6. set "ffmpeg=c:\ffmpeg.exe"
  7. set "sourcedir=%~dp0"
  8. set /p "mapfiles=Total mp4 files in each map: "
  9.  
  10. :: Check if there are mp4-files
  11. if not exist "*.mp4" (
  12.     echo No mp4 files found. Exiting...
  13.     pause
  14.     exit /b
  15. )
  16.  
  17. :: Initialising variable
  18. set /a mapnum=1
  19.  
  20. :process
  21. :: Make folders
  22. set "targetdir=%sourcedir%mp4_aac_m4a_%mapnum%"
  23. if not exist "%targetdir%" mkdir "%targetdir%"
  24. if not exist "%targetdir%\aac" mkdir "%targetdir%\aac"
  25. if not exist "%targetdir%\m4a" mkdir "%targetdir%\m4a"
  26.  
  27. :: Move files to new folder
  28. set /a moved=0
  29. for /f "delims=" %%f in ('dir /b "*.mp4"') do (
  30.     call :moving "%%f"
  31. )
  32. if %errorlevel% equ 5 (call :restart_script)
  33. if not exist "*.mp4" (call :restart_script)
  34. exit
  35.  
  36. :convert
  37. :: Convert .mp4 to .aac and .m4a
  38. for /l %%g in (1,1,%mapnum%) do (
  39.     for /f "delims=" %%a in ('dir /b "%sourcedir%mp4_aac_m4a_%%g\*.mp4"') do (
  40.         echo Extracting to %%~na.aac
  41.         "%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
  42.     )
  43.     for /f "delims=" %%a in ('dir /b "%sourcedir%mp4_aac_m4a_%%g\aac\*.aac"') do (
  44.         echo Converting to %%~na.m4a
  45.         "%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
  46.     )
  47. )
  48. echo All files processed.
  49. pause
  50. exit
  51.  
  52. :moving
  53. set "file=%~1"
  54. set "escapedfile=%file:&=^&%"
  55. if not exist "%file%" (exit /b 5)
  56. echo Moving... %escapedfile%
  57. move "%file%" "%targetdir%" >nul
  58. set /a moved+=1
  59. if %moved% equ %mapfiles% set /a mapnum+=1 & goto :process
  60. exit /b 5
  61.  
  62. :restart_script
  63. :: Restarting script...
  64. endlocal
  65. call "%~f0" restart
  66. exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement