slyfox1186

FFmpeg: Convert x264 to x265 Batch Script

Oct 28th, 2018 (edited)
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.57 KB | None | 0 0
  1. @ECHO on &SETLOCAL
  2.  
  3. REM Change the working directory to your .mp4 files root folder.
  4. CD %OneDrive%\Desktop\Vids
  5.  
  6. REM This scripts will recursively grab all mp4 files using a batch process and convert them into x265 using FFmpeg's command line (program used is ffmpeg.exe). If you don't have that you must obtain it. A good place to download and build ffmpeg.exe is with media autobuild suite on GitHub: https://github.com/jb-alvarado/media-autobuild_suite
  7. REM Make sure to set ffmpeg.exe's folder path as an environmental variable in windows before running this script.
  8.  
  9. REM Set the below line to your root folder to recursively search for mp4 files.
  10. SET "mp4PATH=%OneDrive%\Desktop\Vids\"
  11.  
  12. REM Create empty convert file.
  13. COPY NUL "convert_movies.bat" >NUL 2>&1
  14.  
  15. REM Add ECHO off.
  16. ECHO @ECHO off >>"convert_movies.bat"
  17.  
  18. REM Set counter.
  19. SET /A COUNT=1
  20.  
  21. FOR /R "%mp4PATH%" %%G IN (*.mp4) DO (
  22.     SET "fpath=%%~fG"
  23.     SET "fname=%%~nG"
  24.     SETLOCAL enabledelayedexpansion
  25.  
  26.     IF "!fname!"=="!fname:*(x265)=!" (
  27.         CALL :DOFFmpegCLI "!fpath!"
  28.  
  29. REM Add line break space.
  30. ECHO( >>"convert_movies.bat"
  31.  
  32.     ) ELSE ENDLOCAL
  33. )
  34. GOTO:EOF
  35.  
  36. :DOFFmpegCLI
  37. REM Skip if the parameter is empty.
  38. IF "%~1"=="" GOTO:EOF
  39.     FOR %%A IN ("%~1") DO (
  40.         SET "Folder=%%~dpA"
  41.         SET "Name=%%~nxA"
  42.     )
  43.  
  44. REM Run FFmpeg.exe in the cmd.exe window.
  45. ECHO ffmpeg -ss 00:10:00 -t 1 -y -i "%~1" -c:v libx265 -preset slow -crf 18 -c:a aac "%Folder%%~n1(x265).mp4">>"convert_movies.bat" && ffmpeg | ffmpeg -ss 00:10:00 -t 1 -y -i "%~1" -c:v libx265 -preset slow -crf 18 -c:a aac "%Folder%%~n1(x265).mp4"
  46. EXIT /B
  47. PAUSE
Add Comment
Please, Sign In to add comment