Advertisement
slyfox1186

FFmpeg batch script: Ignore certain file names

Oct 28th, 2018
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.09 KB | None | 0 0
  1. :: created by slyfox1186
  2. :: stackoverflow.com https://stackoverflow.com/users/10572786/slyfox1186
  3. :: pastebin.com https://pastebin.com/u/slyfox1186/1/0/1/?o=h1
  4.  
  5. @ECHO
  6. SETLOCAL
  7. TITLE FFMPEG CONVERT X264 TO X265
  8. PROMPT $G
  9. COLOR 0A
  10.  
  11. REM This script was inspired by Endoro's expanded script (https://stackoverflow.com/a/16891696/10572786).
  12.  
  13. REM This batch script will recursively search for all .mp4 files that don't have (x265) in the file name. Any valid results will be encoded with x265 using FFmpeg. The original .mp4 file will remain unchanged in it's original folder with the new x265 version.
  14.  
  15. REM Example: %PATH%\A.mp4 > %PATH%\A(x265).mp4
  16.  
  17. REM If you don't have ffmpeg.exe on your PC you must download or build it with Microsoft Visual Studios. I recommend you download and run media autobuild suite on GitHub: (https://github.com/jb-alvarado/media-autobuild_suite).
  18.  
  19. REM Once ffmpeg is compiled/downloaded make sure to set it's folder path as an environmental variable in Windows before running the script or include the full path and make changes below as necessary. Change the working directory to your .mp4 files root folder.
  20.  
  21. REM !!BEGIN SCRIPT!!
  22.  
  23. REM Replace USER with your username.
  24. pushd C:\Users\%USER%\OneDrive\Desktop\Vids\
  25.  
  26. REM Set mp4PATH to the root folder you wish to recursively search.
  27. SET "mp4PATH=C:\Users\%USER%\OneDrive\Desktop\Vids\"
  28.  
  29. REM Create empty convert file.
  30. COPY NUL "convert_movies.bat" >NUL 2>&1
  31.  
  32. REM Add ECHO off.
  33. ECHO @ECHO off >>"convert_movies.bat"
  34.  
  35. REM Recursively search root folder.
  36. FOR /R "%mp4PATH%" %%G IN (*.mp4) DO (
  37.     SET "fpath=%%~fG"
  38.     SET "fname=%%~nG"
  39.     SETLOCAL enabledelayedexpansion
  40.  
  41. REM Ignore all files that have "(x265)" in the file name.
  42. IF "!fname!"=="!fname:*(x265)=!" (
  43.     CALL :DO_FFmpeg_CLI "!fpath!"
  44.     ECHO(>>"convert_movies.bat"
  45.     ) ELSE ENDLOCAL
  46. )
  47. GOTO:EOF
  48.  
  49. REM CALL variables for use in FFmpeg's command line.
  50. :DO_FFmpeg_CLI
  51. IF "%~1"=="" GOTO:EOF
  52. FOR %%A IN ("%~1") DO (
  53.     SET "Folder=%%~dpA"
  54.     SET "Name=%%~nxA"
  55. )
  56.  
  57. REM Export info to "convert_movies.bat and run ffmpeg.exe's command line in the cmd.exe window.
  58. ECHO ffmpeg -y -i "%~1" -c:v libx265 -preset slow -crf 18 -c:a aac "%Folder%%~n1(x265).mp4">>"convert_movies.bat" && ffmpeg | ffmpeg -y -i "%~1" -c:v libx265 -preset slow -crf 18 -c:a aac "%Folder%%~n1(x265).mp4"
  59.  
  60. PAUSE
  61. ENDLOCAL
  62. EXIT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement