Advertisement
Day_Tripper

recode_video.bat

Jan 6th, 2024
2,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 20.35 KB | Software | 0 0
  1. @echo off
  2. cls
  3. title Encode Video
  4. rem "C:\Users\<Your Username>\OneDrive\System Tools\InPath\cmdow" @ /MOV 22 15 /SIZ 823 644
  5. rem https://gist.github.com/nico-lab/c2d192cbb793dfd241c1eafeb52a21c3
  6. mode con: cols=100 lines=35
  7. SETLOCAL ENABLEEXTENSIONS
  8. IF NOT [%2]==[] SET 2=%2
  9. IF NOT [%3]==[] SET 3=%3
  10. IF NOT [%4]==[] SET 4=%4
  11. IF NOT [%5]==[] SET 5=%5
  12. IF NOT [%6]==[] SET 6=%6
  13. rem To add an embedded cover/thumbnail:
  14. rem ffmpeg -i in.mkv -i IMAGE -map 0 -map 1 -c copy -c:v:1 png -disposition:v:1 attached_pic out.mkv
  15.  
  16. IF [%1]==[] ( GOTO EOF )
  17.  
  18. IF /I [%1]==[false] ( SET "DEF_COICE=(Y/n)" & SET "ANSWER=n" & SHIFT ) ELSE ( SET "DEF_COICE=(y/N)"  & SET "ANSWER=y" )
  19. SET /P "VIEWVLC=View in VLC? %DEF_COICE% : "
  20. IF [%DEF_COICE%]==[y] START "" "C:\Program Files\VideoLAN\VLC\vlc.exe" "%~f1" & pause
  21. IF [%ANSWER%]==[n] ( IF /I "%VIEWVLC%" NEQ "n" START "" "C:\Program Files\VideoLAN\VLC\vlc.exe" "%~f1" & pause )
  22.  
  23. rem SHIFT & SET /P "VIEWVLC=View in VLC? (y/N) : " & IF [%VIEWVLC%]==[y] START "" "C:\Program Files\VideoLAN\VLC\vlc.exe" "%~f1" & pause
  24. rem SET /P "VIEWVLC=View in VLC? (Y/n) : & IF /I "%VIEWVLC%" NEQ "n" (START "" "C:\Program Files\VideoLAN\VLC\vlc.exe" "%~f1" & pause
  25. rem :NOCHOICE
  26.  
  27. SET "THREADS=4"
  28. c:
  29. cd C:\vc\autobuild\local64\bin-video
  30. title %~n1 in Recoding Que
  31. echo ...............................................................................
  32. echo %1
  33. ffprobe -v error -pretty -select_streams v:0 -show_entries stream=width,height,duration,bit_rate -of default=noprint_wrappers=1 %1
  34. rem reprobe -v error -pretty -select_streams v:0 -show_entries stream=r_frame_rate  -of default=noprint_wrappers=1 %1 > frate.txt
  35. ffprobe -v error -pretty -select_streams v:0 -show_entries stream=width,height,duration,bit_rate -of default=noprint_wrappers=1 %1 > probe.txt
  36. findstr /B height probe.txt > probefind.txt
  37. SET /P height=<probefind.txt
  38. SET /P duration=<probefind.txt
  39. SET %height%
  40. SET %duration%
  41. echo ...............................................................................
  42. rem ----------------------------------------------------------------------------------------------------------------> Quick Picks ---- todo BATCH
  43. SET /P QUICKP=Quick Picks? (Y/n) :
  44. IF /I "%QUICKP%" EQU "n" (GOTO FULLCHOICE) ELSE ( echo..... )
  45. :QUICKPICK
  46.  
  47. IF NOT [%height%]==[2160] ( echo  69 - SBS 2160 20k )
  48. IF NOT [%height%]==[2160] ( echo  68 - SBS 2160 15k )
  49. IF NOT [%height%]==[2160] ( echo   0 - SBS 2160 10k )
  50. IF NOT [%height%]==[2160] ( echo   1 - SBS 2160 9k )
  51. IF NOT [%height%]==[2160] ( echo   2 - SBS 2160 8k* )
  52. IF NOT [%height%]==[1440] ( echo  25 - SBS 1440 8k )
  53. IF NOT [%height%]==[1440] ( echo   3 - SBS 1440 7k )
  54. IF NOT [%height%]==[1440] ( echo   4 - SBS 1440 6k* )
  55. IF NOT [%height%]==[1440] ( echo   5 - SBS 1440 5k )
  56. IF NOT [%height%]==[1440] ( echo   6 - SBS 1440 xk )
  57. echo ..................
  58. echo  67 - Same Size 30k
  59. echo  66 - Same Size 25k
  60. echo  65 - Same Size 20k
  61. echo  64 - Same Size 15k
  62. echo   7 - Same Size 10k
  63. echo   8 - Same Size 9k
  64. echo   9 - Same Size 8k*
  65. echo  10 - Same Size 7k
  66. echo  11 - Same Size 6k*
  67. echo  12 - Same Size 5k
  68. echo  ..................
  69. echo  13 - Remux to MP4
  70. echo  14 - Official FFMPEG
  71. echo  15 - scale_cuda
  72. echo  ..................
  73. echo  16 - Give me the Choices
  74. echo  ..................
  75.  
  76. SET /P QUICKP=Choice :
  77.  
  78. IF %QUICKP%==69 (SET "Y=2160" & SET "K=20000" & SET "M=7")
  79. IF %QUICKP%==68 (SET "Y=2160" & SET "K=15000" & SET "M=7")
  80. IF %QUICKP%==0 (SET "Y=2160" & SET "K=10000" & SET "M=7")
  81. IF %QUICKP%==1 (SET "Y=2160" & SET "K=9000" & SET "M=7")
  82. IF %QUICKP%==2 (SET "Y=2160" & SET "K=8000" & SET "M=7")
  83. IF %QUICKP%==25 (SET "Y=1440" & SET "K=8000" & SET "M=7")
  84. IF %QUICKP%==3 (SET "Y=1440" & SET "K=7000" & SET "M=7")
  85. IF %QUICKP%==4 (SET "Y=1440" & SET "K=6000" & SET "M=7")
  86. IF %QUICKP%==5 (SET "Y=1440" & SET "K=5000" & SET "M=7")
  87. IF %QUICKP%==6 (SET "Y=1440"
  88.                 SET /P K=k:
  89.                 SET /A K*=1000
  90.                 SET "M=7")
  91. IF %QUICKP%==67 (SET "K=30000" & SET "M=8" & GOTO JUMP_SCALE)
  92. IF %QUICKP%==66 (SET "K=25000" & SET "M=8" & GOTO JUMP_SCALE)
  93. IF %QUICKP%==65 (SET "K=20000" & SET "M=8" & GOTO JUMP_SCALE)
  94. IF %QUICKP%==64 (SET "K=15000" & SET "M=8" & GOTO JUMP_SCALE)
  95. IF %QUICKP%==7 (SET "K=10000" & SET "M=8" & GOTO JUMP_SCALE)
  96. IF %QUICKP%==8 (SET "K=9000" & SET "M=8" & GOTO JUMP_SCALE)
  97. IF %QUICKP%==9 (SET "K=8000" & SET "M=8" & GOTO JUMP_SCALE)
  98. IF %QUICKP%==10 (SET "K=7000" & SET "M=8" & GOTO JUMP_SCALE)
  99. IF %QUICKP%==11 (SET "K=6000" & SET "M=8" & GOTO JUMP_SCALE)
  100. IF %QUICKP%==12 (SET "K=5000" & SET "M=8" & GOTO JUMP_SCALE)
  101. IF %QUICKP%==13 (SET "M=13" & GOTO JUMP_SCALE)
  102. IF %QUICKP%==14 (echo "Set to retail ffmpeg" & cd "C:\Users\<Your Username>\OneDrive\System Tools\Utils\ffmpeg\bin" & SET "SCALE=scale" & SET "RFILTER= " & GOTO QUICKPICK )
  103. IF %QUICKP%==15 (echo "Set to Scale CUDA" & SET "SCALE=scale_cuda" & GOTO QUICKPICK)
  104. IF %QUICKP%==16 (GOTO FULLCHOICE)
  105.  
  106. IF [%Y%]==[%height%] ( echo Can't encode to same height as source use Same Size & GOTO QUICKPICK )
  107.  
  108. echo.....
  109.  
  110. IF NOT DEFINED SCALE ( IF [%Y%] LSS [%height%] ( SET "DOWNFILTER=:interp_algo=super" ) ELSE ( SET "DOWNFILTER=" ) ) ELSE ( SET "DOWNFILTER=" )
  111. IF NOT DEFINED SCALE SET "SCALE=scale_npp"
  112.  
  113. :JUMP_SCALE
  114. IF DEFINED Y (echo "%DATE%%TIME% %~n1 size:%Y% K:%K%" >> G:\Temp\jobs.log) ELSE (echo "%DATE%%TIME% %~n1 Same Size K:%K%" >> G:\Temp\jobs.log)
  115. rem sendkeys to desktop manager to resize all encoding windows
  116. "C:\Users\<Your Username>\OneDrive\System Tools\Batches\send-keys.vbs" "" "^+M"
  117.  
  118. SET FORMAT=mp4
  119. SET AUDIO=n
  120. SET SUBTITLE=n
  121. SET APPEND_FN=y
  122. SET SECTION=N
  123. GOTO SETK
  124.  
  125. IF [%2]==[] GOTO FULLCHOICE
  126. SET BATCH=FALSE
  127. IF DEFINED 2 IF %2 GTR 0 IF %2 LSS 15 (SET BATCH=TRUE)
  128. rem echo 1=%1 2=%2 3=%3 4=%4 5=%5 6=%6 Batch=%BATCH%
  129. rem pause
  130. IF [%BATCH%]==[TRUE] SET "M=%2" & SET "K=%3" & SET "AUDIO=%4" & SET "APPEND_FN=%5" & SET "NO_LOOP=TRUE" & SET "SUBTITLE=n" & GOTO SETK
  131.  
  132. :FULLCHOICE
  133. echo .
  134. SET /P FORMAT=Choose Format (mkv/MP4)
  135. IF /I "%FORMAT%" NEQ "mkv" ( SET "FORMAT=mp4" ) ELSE ( SET "SUBTITLE=mkv" )
  136. echo .
  137. echo Recode using h265 NVENC %FORMAT%
  138.  
  139. echo ....
  140. echo  1 - Video Wall (640x540  500k to 2000k)
  141. echo  2 - Home Video       (Same Size, 1800k)
  142. echo  3 - Low        (800x600 1000k to 2000k)
  143. echo  4 - Med        (960x540 1500k to 3000k)
  144. echo  5 - High      (1280×720 2000k to 4000k)
  145. echo  6 - HD       (1920x1080 3???k to ????k)
  146. echo  7 - VR SBS    (1440/2160) (5000k to ?k)
  147. echo  8 - Recode. Same size.  (5??k to ????k)
  148. echo  9 - Recode. Different Size.    ?(2300k)
  149. echo 10 - Add MP3 Audio, Copy Video.
  150. echo 11 - Convert Audio to MP3, Copy Video.
  151. echo 12 - Add Subtitles to Video.
  152. echo 13 - ReMux to mp4
  153. echo 14 - Recode GIF.
  154. echo 15 - GameTripe Cutscene.
  155. echo 16 - H264 recode.
  156. echo 17 - Video test for Vegas.
  157. echo 18 - Blank Audio Stream.
  158. echo 19 - Try Fix Corrupt Film.
  159. echo 20 - Use FFMPEG Official Release.
  160. echo ....
  161.  
  162. SET /P M=Type 1 to 19:
  163. IF %M%==1 SET /P K=Enter bitrate in k:
  164. IF %M%==3 SET /P K=Enter bitrate in k:
  165. IF %M%==4 SET /P K=Enter bitrate in k:
  166. IF %M%==5 SET /P K=Enter bitrate in k:
  167. IF %M%==6 SET /P K=Enter bitrate in k:
  168. IF %M%==7 (echo ... & SET /P Y=Enter [1440 or 2160] 1440p 6000k is default: )
  169. IF %M%==7 (IF /I "%Y%" NEQ "2160" (IF /I "%Y%" NEQ "1440" ( SET "Y=1440" )))
  170. IF %M%==7 SET /P K=Enter Bitrate [5 to ?]000k:
  171. IF %M%==7 IF /I "%K%" EQU "" SET "K=6"
  172. IF %M%==7 SET /A "K=K*1000"
  173. IF %M%==8 SET /P K=Enter bitrate in k:
  174. IF %M%==9 SET /P K=Enter bitrate in k: & SET /P X=Width in Pixels: & SET /P Y=Height in Pixels:
  175. IF %M%==10 GOTO ADDMP3
  176. IF %M%==12 GOTO SUBTITLE
  177. IF %M%==13 GOTO REMUX
  178. IF %M%==14 GOTO RECODE_GIF
  179. IF %M%==19 GOTO FIXFILM
  180. IF %M%==20 ( cd "C:\Users\<Your Username>\OneDrive\System Tools\Utils\ffmpeg\bin" & SET "SCALE=scale" & SET "RFILTER= " & GOTO FULLCHOICE )
  181. IF %M% GTR 9 (SET AUDIO=Y) & (SET TWOPASS=N) & GOTO JUMP_K
  182.  
  183. :SETK
  184. SET /A "VBUFF = K * 2"
  185. SET /A "MAXRATE = K + 10000
  186. IF NOT DEFINED AUDIO SET /P AUDIO=Recode Audio? (y/N):
  187.  
  188. :JUMP_K
  189. IF /I "%AUDIO%" EQU "y" (SET AUDIO_STRING=a libmp3lame -ar 48000 -ab 192k -ac 2) ELSE ( SET "AUDIO_STRING=a copy" )
  190. IF NOT DEFINED SUBTITLE SET /P SUBTITLE=Copy Subtitle? (y/N):
  191. IF /I "%SUBTITLE%" EQU "y" ( SET "SUBTITLE=-c:s mov_text" ) ELSE ( SET "SUBTITLE=" )
  192. IF NOT DEFINED APPEND_FN SET /P APPEND_FN=Append to Filename? (Y/n):
  193. IF /I "%APPEND_FN%" EQU "n" ( SET "APPEND_FILENAME=" ) ELSE ( SET "APPEND_FILENAME=_ffmeg" )
  194. IF NOT DEFINED SECTION SET /P SECTION=Only Encode a Section? (y/N)
  195. IF [%SECTION%]==[y] (
  196.     echo Media Duration: %duration%
  197.     SET /P SEC_START=Start @:
  198.     SET /P SEC_END=End @:
  199.     SET SECTION = -ss %SEC_START% -to %SEC_END%
  200.     ) ELSE ( SET "SECTION=" )
  201. mode con: cols=110 lines=8
  202.  
  203. :LOOP
  204. echo File = %1
  205. echo Waiting for encoding to complete...
  206.  
  207. :CHECKFORFILE
  208. echo | SET /p=.
  209. IF DEFINED LOOPING ( GOTO SKIPTEST )
  210. IF NOT EXIST "%~dp1Encoding.txt" (GOTO NOTTHERE)
  211. TIMEOUT /T 60 > nul
  212. GOTO CHECKFORFILE
  213.  
  214. :NOTTHERE
  215. echo %~n1 > "%~dp1Encoding.txt"
  216. IF [%M%]==[13] GOTO JUMP_SLEEP
  217. SET /A "SLEEP_RND=%RANDOM% * 10 / 32768 + 1"
  218. echo Sleeping for %SLEEP_RND%
  219. TIMEOUT /T %SLEEP_RND%
  220. :JUMP_SLEEP
  221. SET /p FILE_TEST=<"%~dp1Encoding.txt"
  222. rem echo Testing "%~n1 " equals "%FILE_TEST%" not going back to check file
  223. IF "%~n1 " NEQ "%FILE_TEST%" (del "%~dp1Encoding.txt" GOTO CHECKFORFILE)
  224.  
  225. :SKIPTEST
  226. title %~n1 - Encoding
  227. "C:\Users\<Your Username>\OneDrive\System Tools\InPath\cmdow" @ /TOP
  228. "C:\Users\<Your Username>\OneDrive\System Tools\InPath\cmdow" @ /NOT
  229.  
  230. IF %M%==1 GOTO VIDEOWALL
  231. IF %M%==2 GOTO HOMEVIDEO
  232. IF %M%==3 GOTO LOW
  233. IF %M%==4 GOTO MED
  234. IF %M%==5 GOTO HIGH
  235. IF %M%==6 GOTO HD
  236. IF %M%==7 GOTO VRSBS
  237. IF %M%==8 GOTO RECODE
  238. IF %M%==9 GOTO RECODE_RESIZE
  239. IF %M%==10 GOTO ADDMP3
  240. IF %M%==11 GOTO MP3
  241. IF %M%==12 GOTO SUBTITLE
  242. IF %M%==13 GOTO REMUX
  243. IF %M%==14 GOTO RECODE_GIF
  244. IF %M%==15 GOTO WITCHERCS
  245. IF %M%==16 GOTO H264
  246. IF %M%==17 GOTO VEGAS
  247. IF %M%==18 GOTO BLANKAUDIO
  248. IF %M%==19 GOTO FIXFILM
  249. GOTO EOF
  250.  
  251. rem ---------------------------------------------------------------------------------------------------------------------------------> Work Items
  252.  
  253. :VIDEOWALL
  254. echo VideoWall
  255. ffmpeg -i %1 -vcodec hevc_nvenc -vf scale=w=640:h=540:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  256. GOTO NEXT
  257.  
  258. :HOMEVIDEO
  259. echo Home Video
  260. ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1 -map_metadata 0 -c:v hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 15 -qmax:v 52 -b:v 1800k -bufsize:v 3600k -maxrate:v 2800k -spatial_aq:v 1 -aq-strength:v 15 -c:a libmp3lame -ar 48000 -ab 192k -ac 2 "%~dpn1_enc.mp4"
  261. if errorlevel 1 goto ERRORNEXT
  262. Recycle -f %1
  263. move "%~dpn1_enc.mp4" "%~dpn1.mp4"
  264. echo .
  265. echo ** Success **
  266. echo .
  267. rem @echo %1>> "C:\Users\<Your Username>\OneDrive\System Tools\Utils\ffmpeg\bin\homevideo_log.txt"
  268. :ERRORNEXT
  269. if exist "%~dpn1_enc.mp4" del "%~dpn1_enc.mp4"
  270. GOTO NEXT
  271.  
  272. :LOW
  273. echo Quality Low
  274. ffmpeg -i %1 -vcodec hevc_nvenc -vf scale=w=800:h=600:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  275. GOTO NEXT
  276.  
  277. :MED
  278. echo Quality Medium
  279. ffmpeg -i %1 -vcodec hevc_nvenc -vf scale=w=960:h=540:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  280. GOTO NEXT
  281.  
  282. :HIGH
  283. echo Quality High
  284. ffmpeg -i %1 -vcodec hevc_nvenc -vf scale=w=1280:h=720:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  285. GOTO NEXT
  286.  
  287. :HD
  288. echo Quality High Defination
  289. ffmpeg -i %1 -vcodec hevc_nvenc -vf scale=w=1920:h=1080:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  290. GOTO NEXT
  291.  
  292. :VRSBS
  293. rem 2 VR Standards so far ****************************************************************************************VR ENCODE
  294. echo .........................................................................
  295. echo Quality VR Film High Def Varable Bitrate
  296. IF [%Y%]==[1080] SET "X=2160" ELSE IF [%Y%]==[1440] SET "X=2880" & SET "Y=%Y% ELSE IF [%Y%]==[2160] SET "X=4320"
  297. echo K=%K% X=%X% Y=%Y% VBUFF=%VBUFF% MAXRATE=%MAXRATE%
  298. echo .........................................................................
  299. IF NOT DEFINED SCALE ( SET "SCALE=scale_npp" )
  300. IF NOT DEFINED RFILTER ( SET "RFILTER=hwupload_cuda," )
  301. IF NOT DEFINED DOWNFILTER ( SET "DOWNFILTER=" )
  302. SET "RESIZE=%SCALE%=w=-1:h=%Y%%DOWNFILTER%"
  303. REM NVIDIA BUG WORKAROUND -extra_sei 0 (placed before SUBTITLE)
  304. echo ffmpeg -hwaccel_output_format cuda -vsync 0 -y %SECTION% -i %1 -threads %THREADS% -vf "%RFILTER%%RESIZE%" -vcodec hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead 1024 -qmin:v 15 -qmax:v 52 -bf 3 -b_ref_mode middle -temporal-aq 1 -vsync 0 -refs:v 16 -b:v %K%k -bufsize %VBUFF%k -maxrate %MAXRATE%k -extra_sei 0 %SUBTITLE% -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  305. echo .........................................................................
  306. ffmpeg -hwaccel_output_format cuda -vsync 0 -y %SECTION% -i %1 -threads %THREADS% -vf "%RFILTER%%RESIZE%" -vcodec hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead 1024 -qmin:v 15 -qmax:v 52 -bf 3 -b_ref_mode middle -temporal-aq 1 -vsync 0 -refs:v 16 -b:v %K%k -bufsize %VBUFF%k -maxrate %MAXRATE%k -extra_sei 0 %SUBTITLE% -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  307. SET ERR_PAUSE=%ERRORLEVEL%
  308.  
  309. set filename="path\to\file.txt"
  310. set file_size=""
  311. for /F %%A in (%filename%) do set "file_size=%%~zA"
  312.  
  313. GOTO NEXT
  314.  
  315. :RECODE
  316. rem recode no size
  317. echo Recode,Same Size. Varable Bitrate. k=%k% maxrate=%MAXRATE% buffer=%VBUFF%
  318. echo .........................................................................
  319.  
  320. echo ffmpeg -threads %THREADS% -hwaccel_output_format cuda %SECTION% -i %1 -map_metadata 0 -c:v hevc_nvenc -preset slow -profile:v main -rc vbr -tune 1 -rc-lookahead 1024 -qmin 15 -qmax 52 -bf 3 -b_ref_mode middle -temporal-aq 1 -vsync 0 -refs 16 -b:v %K%k -bufsize:v %VBUFF%k -maxrate:v %MAXRATE%k %SUBTITLE% -c:%AUDIO_STRING% "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  321. ffmpeg -threads %THREADS% -hwaccel_output_format cuda %SECTION% -i %1 -map_metadata 0 -c:v hevc_nvenc -preset slow -profile:v main -rc vbr -tune 1 -rc-lookahead 1024 -qmin 15 -qmax 52 -bf 3 -b_ref_mode middle -temporal-aq 1 -vsync 0 -refs 16 -b:v %K%k -bufsize:v %VBUFF%k -maxrate:v %MAXRATE%k %SUBTITLE% -c:%AUDIO_STRING% "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  322. SET ERR_PAUSE=%ERRORLEVEL%
  323. IF [%ERR_PAUSE%]==[1] (del "%~dpn1%APPEND_FILENAME%.%FORMAT%")
  324.  
  325. :RECODE_RESIZE
  326. rem recode with size
  327. IF NOT DEFINED SCALE ( SET "SCALE=scale_npp" )
  328. echo Recode,Different Size. Varable Bitrate.
  329. echo ffmpeg -threads %THREADS% -hwaccel_output_format cuda %SECTION% -i %1 -map_metadata 0 -vcodec hevc_nvenc -vf %SCALE%=w=%X%:h=%Y%:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 15 -qmax:v 52 -b:v %K%k -bufsize:v %VBUFF%k -maxrate:v %MAXRATE%k -spatial_aq:v 1 -aq-strength:v 15 -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  330. ffmpeg -threads %THREADS% -hwaccel_output_format cuda %SECTION% -i %1 -map_metadata 0 -vcodec hevc_nvenc -vf %SCALE%=w=%X%:h=%Y%:force_original_aspect_ratio=decrease -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 15 -qmax:v 52 -b:v %K%k -bufsize:v %VBUFF%k -maxrate:v %MAXRATE%k -spatial_aq:v 1 -aq-strength:v 15 -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  331. SET ERR_PAUSE=%ERRORLEVEL%
  332. IF [%ERR_PAUSE%]==[1] (del "%~dpn1%APPEND_FILENAME%.%FORMAT%")
  333. GOTO NEXT
  334.  
  335. :DEBLOCK
  336. rem recode & deblock
  337. echo Recode with Deblock.
  338. echo ffmpeg -threads %THREADS% -hwaccel_output_format cuda %SECTION% -i %1 -map_metadata 0 -vcodec hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -vf deblock=filter=weak:block=4 -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  339. ffmpeg -threads %THREADS% -hwaccel_output_format cuda %SECTION% -i %1 -map_metadata 0 -vcodec hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v %K%k -vf deblock=filter=weak:block=4 -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  340. GOTO NEXT
  341.  
  342. :ADDMP3
  343. echo ReMux with MP3 audio track stream 2, preserving existing audio stream.
  344. ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1 -b:a libmp3lame -ar 48000 -ab 192k -ac 2 -vn "%~dpn1.audio.mp3"
  345. ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1 -map_metadata 0 -i "%~dpn1.audio.mp3" -map 0:0 -c copy -map 1:0 -c copy -map 0:1 -c copy -map 0:2? -c copy -map 0:3? -c copy "%~dpn1.edit.%FORMAT%"
  346. del "%~dpn1.audio.mp3"
  347. GOTO NEXT
  348.  
  349. :MP3
  350. echo Same Video, Recode audio to MP3
  351. ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1  -map_metadata 0 -c:v copy -c:%AUDIO_STRING% "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  352. GOTO NEXT
  353.  
  354. :SUBTITLE
  355. echo Add subtitle to Video
  356. SET /P SUB_FILE=Drag Drop Subtitle File:
  357. echo ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1  -i %SUB_FILE% -map 0 -map 1:0 -c:s mov_text "%~dpn1.subtitle.%FORMAT%"
  358. ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1  -i %SUB_FILE% -map 0 -map 1:0 -c:s mov_text "%~dpn1.subtitle.%FORMAT%"
  359. SET "SUB_FILE="
  360. GOTO NEXT
  361.  
  362. :REMUX
  363. IF NOT DEFINED DESTINATION ( CHOICE /T 3 /C sr /CS /D s /M "Destination - Same Folder (S) or Ram Disk (r) (S/r): " )
  364. IF [%ERRORLEVEL%]==[2] ( SET "DESTINATION=R:\%~n1.mp4" ) ELSE ( SET "DESTINATION=%~dpn1.remux.mp4" )
  365. SET "ERRORLEVEL="
  366. rem TODO: Following does not work, crashes batch file with no error
  367. rem IF EXIST %DESTINATION% ( SET "DESTINATION=%DESTINATION%~dpn1.dup.mp4" )
  368. echo ffmpeg -threads %THREADS% -i %1 -sn -map 0 -c copy "%DESTINATION%"
  369. ffmpeg -threads %THREADS% -i %1 -sn -map 0 -c copy "%DESTINATION%"
  370. SET ERR_PAUSE=%ERRORLEVEL%
  371. GOTO NEXT
  372.  
  373. :RECODE_GIF
  374. echo ffmpeg -strict -1 -i %1 -vcodec hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 15 -qmax:v 50 -b:v 2000k -bufsize:v 4000k -maxrate:v 4000k -c:a aac -shortest 0 "%~dpn1_enc.mp4"
  375. ffmpeg -strict -1 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i %1 -vcodec hevc_nvenc -preset:v slow -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 15 -qmax:v 50 -b:v 2000k -bufsize:v 4000k -maxrate:v 4000k -c:a aac -shortest 0 "%~dpn1_enc.mp4"
  376. GOTO NEXT
  377.  
  378. :WITCHERCS
  379. echo Super Compressed for Witcher Shortlist
  380. ffmpeg -i %1 -vcodec hevc_nvenc -vf scale=w=640:h=480:force_original_aspect_ratio=decrease -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v 400k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1_e%APPEND_FILENAME%.%FORMAT%"
  381. del %1
  382. GOTO NEXT
  383.  
  384. :H264
  385. echo Recoding into H264
  386. ffmpeg -i %1 -vcodec libx264 -preset slow -crf 22 -c:%AUDIO_STRING% "%~dpn1%APPEND_FILENAME%.%FORMAT%"
  387. GOTO NEXT
  388.  
  389. :VEGAS
  390. echo Video for VEGAS.
  391. ffmpeg -threads %THREADS% -hwaccel_output_format cuda -i %1 -vcodec libx264 -vf scale=w=640:h=480:force_original_aspect_ratio=decrease -profile:v main -rc vbr -tune 1 -rc-lookahead:v 256 -qmin:v 1 -qmax:v 50 -b:v 400k -c:%AUDIO_STRING% -map_metadata 0:s:0 "%~dpn1_v%APPEND_FILENAME%.%FORMAT%"
  392. GOTO NEXT
  393.  
  394. :BLANKAUDIO
  395. echo Add a black Audio track to Video.
  396. ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i %1 -c:v copy -c:a aac -shortest -map_metadata 0:s:0 "%~dpn1_v.blank-audio.%FORMAT%"
  397. GOTO NEXT
  398.  
  399. :FIXFILM
  400. echo attempt fix video
  401. echo ffmpeg -i %1 -c:v copy -c:a copy "%~dpn1_v.fixed.%FORMAT%"
  402. ffmpeg -i %1 -c:v copy -c:a copy "%~dpn1_v.fixed.%FORMAT%"
  403. GOTO NEXT
  404.  
  405. rem --------------------------------------------------------------------------------------------------------------------------------> END OR LOOP
  406.  
  407. :NEXT
  408. del  "%~dp1Encoding.txt"
  409.  
  410. IF DEFINED NO_LOOP GOTO EOF
  411. echo Encoded %1 >> "C:\Users\<Your Username>\OneDrive\System Tools\Utils\ffmpeg\bin\log.txt"
  412. SHIFT
  413. IF NOT [%1]==[] ( SET "LOOPING=true" & GOTO LOOP )
  414.  
  415. :EOF
  416. IF DEFINED SLEEP (IF [%SLEEP%] == [y] (START "" "C:/Users/<Your Username>/OneDrive/System Tools/System/SysInternals/psshutdown.exe" -d -t 0))
  417. IF [%ERR_PAUSE%]==[1] (PAUSE) ELSE (ECHO Complete)
  418. rem PAUSE
  419.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement