Urik_Kane

FFmpeg_rewrap_mkv_advanced

Sep 19th, 2020
1,036
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. SetLocal EnableDelayedExpansion
  3. title %~n0
  4.  
  5. if "%~1"=="" ( echo ERROR: NO INPUT & echo  & pause & goto :eof ) else (
  6. if NOT "%cd%\"=="%~dp1" cd /d "%~dp1"
  7. )
  8.  
  9. :: path to ffmpeg
  10. set "ffmpeg=C:\ffmpeg\bin\ffmpeg.exe"
  11.  
  12. :: default output subfolder. change to "subfolder=" to disable
  13. set "subfolder=mkv"
  14.  
  15. :: extension
  16. set "ext=mkv"
  17.  
  18. :EnterPath
  19. set p=
  20. echo.
  21. set /p p="output path (default %subfolder%) "
  22. for %%F in ("!p!") do (
  23.     set "outfolder=%%~dpnF"
  24.     set openfolder = true
  25.     goto :ConformPath
  26. )
  27.  
  28. :ConformPath
  29. if "!outfolder!"=="" (
  30.     for %%A in (%subfolder%) do (
  31.             set "outfolder=%subfolder%\"
  32.             goto :Checkoutfolder
  33.         )
  34.     ) else (
  35.     if not "!outfolder:~-1!"=="\" (
  36.         if "!outfolder:~-1!"=="/" set "outfolder=!outfolder:~0,-1!"
  37.         set "outfolder=!outfolder!\"
  38.     )
  39. )
  40.  
  41. :Checkoutfolder
  42. if not "!outfolder!"=="" ( if not exist "!outfolder!" mkdir "!outfolder!")
  43.  
  44. :CountFiles
  45. for %%F in (%*) do ( if "!total!"=="" ( set total=1) else ( set /a total=!total!+1))
  46.  
  47. :ProcessFiles
  48. for %%F in (%*) do (
  49.     set filters=
  50.    
  51.     if "!current!"=="" ( set current=1) else ( set /a current=!current!+1)
  52.     title %~n0^:  ^>  !current!/!total! "%%~nxF"
  53.     echo. & echo ^> !current!/!total! "%%~F" "%%~nF.%ext%"
  54.  
  55.     set "postfix="
  56.     if exist "!outfolder!\%%~nF.%ext%" CALL :Addpostfix "!outfolder!\%%~nF.%ext%"
  57.  
  58.     :ffmpeg
  59.     "%ffmpeg%" -i "%%~F" -c copy "!outfolder!%%~nF!postfix!.%ext%"
  60. )
  61. title %~n0^:  ^>  COMPLETED
  62. if defined openfolder explorer "!outfolder!"
  63. timeout /t 10
  64. goto :eof
  65.  
  66. :Addpostfix
  67. :: add numeric postfix to files if already exist
  68. for /L %%N in (1,1,1000) do ( if not exist "%~dpn1_%%N%~x1" ( set "postfix=_%%N" & goto :eof ))
  69. goto :eof
RAW Paste Data