tsrein

paste for check

Jun 26th, 2023
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.62 KB | None | 0 0
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. :: Author: Rein Laaneser, 2023, CC: BY-SA
  4.  
  5.  
  6. REM ---------------------------------------------------
  7. REM
  8. REM PREREQUIEMENTS
  9. REM
  10. REM ---------------------------------------------------
  11.  
  12.  
  13. :: FOLDERS AND FILES
  14. :: Zoom files are downloaded to root/folder/subfolder,
  15. :: download from zoom to subfolder is provided with separate sript/automation.
  16. :: Folder name includes 6 character course code and 2 character lang code
  17. :: like this "RRT301 ET".
  18. :: Subfolder name includes zoom recoding date
  19. :: like this "2023-01-21".
  20.  
  21.  
  22. :: changes to ver5
  23. :: Function Func_MoveToEdit is updated
  24.  
  25.  
  26. :: changes to ver6
  27. :: created functions Func_LogFile and Func_EncodeFFmpeg
  28.  
  29. :: changes to ver7
  30. :: 2 translation files Check
  31.  
  32. :: changes to ver8
  33. :: with two translations if one is same woks
  34. :: this means there is 2 different Language
  35. :: todo: 3 different language with 1 wihtout translaton and 2 with translation
  36.  
  37. :: ver 9
  38. :: With two translations testing works.
  39. :: Needs to be correted tested
  40. :: Needs to be optimize code, as original works twice same procedure.
  41.  
  42. :: ver 10
  43. :: testing with three translations
  44.  
  45. :: ver 11
  46. :: clean ver 10
  47. :: other same
  48.  
  49. :: ver 12
  50. :: video helpers, like sharpen
  51.  
  52. :: ver 13
  53. :: audio volume
  54.  
  55. :: ver 14, 15
  56. :: audio compressor and limitter
  57.  
  58. :: video quality higher a bit
  59.  
  60.  
  61.  
  62. REM ---------------------------------------------------
  63. REM
  64. REM INITIAL VARIABLES
  65. REM
  66. REM ---------------------------------------------------
  67.  
  68. REM Source folders
  69. set root=I:\_2_DoCompose
  70.  
  71. REM Encoded source folders
  72. set composed=I:\_3_Composed
  73.  
  74. REM Encoded videos
  75. set editfolder=I:\_4_Edit
  76.  
  77. REM Images
  78. set images=I:\_Images
  79.  
  80.  
  81. REM ---------------------------------------------------
  82. REM
  83. REM FOLDERS processing start
  84. REM
  85. REM ---------------------------------------------------
  86.  
  87. for /d %%a in ("%root%\*") do (
  88. echo Processing folder %%a...
  89.  
  90. REM folder name for arcival purpuse
  91. set "folder=%%~nxa"
  92.  
  93. REM strip folder name space
  94. set "foldername=%%~nxa"
  95.  
  96. set "foldername=!foldername: =!"
  97.  
  98. REM set folder path
  99. set folderpath=!root!\!folder!
  100.  
  101. REM Course code
  102. set "coursecode=!foldername:~0,6!"
  103. echo Folder name stripted is: !foldername!
  104.  
  105. REM Define course Language from folder
  106. if "!foldername:~6,2!"=="ET" (
  107. set "courselanguage=ET"
  108.  
  109. ) else if "!foldername:~6,2!"=="EN" (
  110. set "courselanguage=EN"
  111.  
  112. ) else if "!foldername:~6,2!"=="RU" (
  113. set "courselanguage=RU"
  114.  
  115. ) else (
  116. echo.
  117. )
  118.  
  119.  
  120. REM --IMAGE --
  121. REM Set video top and bottom image variables
  122.  
  123. REM Top image
  124. if exist "%images%\!coursecode!_top.png" (
  125. set "top_image=%images%\!coursecode!_top.png"
  126. ) else (
  127. set "top_image=%images%\Default_top.png"
  128. )
  129.  
  130. REM Bottom image
  131. if exist "%images%\!coursecode!_bottom.png" (
  132. set "bottom_image=%images%\!coursecode!_bottom.png"
  133. ) else (
  134. set "bottom_image=%images%\Default_bottom.png"
  135. )
  136.  
  137.  
  138. REM -- TRANSATIONS LIST & COUNT --
  139. REM Define Translations list based on folder name
  140.  
  141. REM Extract translations list
  142. set foldersting=%%~nxa
  143. for /f "tokens=2 delims=-" %%1 in ("!foldersting!") do (
  144. set translations_list=%%1
  145. )
  146.  
  147. REM Count translations
  148. set /A translations_count=0
  149. for %%i in (!translations_list!) do (
  150. set /A translations_count+=1
  151. )
  152.  
  153. REM ---------------------------------------------------
  154. REM
  155. REM Sub-Folders processing start
  156. REM
  157. REM ---------------------------------------------------
  158.  
  159. for /d %%b in ("%%a\*") do (
  160. echo Processing subfolder %%b...
  161.  
  162. set "subfoldername=%%~nxb"
  163.  
  164. set subfolderpath=!root!\!folder!\!subfoldername!
  165.  
  166. REM -----------------
  167. REM log file creation
  168. REM -----------------
  169.  
  170. REM set filelist txt file name
  171. set "logfile=!subfoldername! logfile.txt"
  172.  
  173. if exist "!folderpath!\!logfile!" del "!folderpath!\!logfile!"
  174.  
  175. echo _________________________________________________ >> "!folderpath!\!logfile!"
  176. echo Processing start >> "!folderpath!\!logfile!"
  177. echo %date:/=-%_%time::=-% >> "!folderpath!\!logfile!"
  178. echo _________________________________________________ >> "!folderpath!\!logfile!"
  179. echo. >> "!folderpath!\!logfile!"
  180. echo Files list: >> "!folderpath!\!logfile!"
  181. echo. >> "!folderpath!\!logfile!"
  182.  
  183. REM ---------------------------------------------------
  184. REM
  185. REM File processing start
  186. REM
  187. REM ---------------------------------------------------
  188.  
  189. REM is this file ET, RU, EN set variables
  190.  
  191. for %%c in ("%%b\*") do (
  192. echo Processing file %%c...
  193. set "filename=%%~nxc"
  194.  
  195. REM Presentar
  196. if "!filename:_avo_=!" neq "!filename!" (
  197. set "presenter=%%~nxc"
  198. )
  199.  
  200. REM Presentation
  201. if "!filename:_as_=!" neq "!filename!" (
  202. set "presentation=%%~nxc"
  203. )
  204.  
  205. REM NR 1 translation
  206. if "!filename:_interpret_separate1=!" neq "!filename!" (
  207. set "translation_1=%%~nxc"
  208. )
  209.  
  210. REM NR 2 translation
  211. if "!filename:_interpret_separate2=!" neq "!filename!" (
  212. set "translation_2=%%~nxc"
  213. )
  214.  
  215. REM NR 3 translation
  216. if "!filename:_interpret_separate3=!" neq "!filename!" (
  217. set "translation_3=%%~nxc"
  218. )
  219.  
  220. REM Original audio
  221. if "!filename:_Recording.m4a=!" neq "!filename!" (
  222. set "originalaudio=%%~nxc"
  223. echo Original audio is !originalaudio!
  224. )
  225.  
  226. REM Add the file name to the file list
  227. echo %%~nxc >> "!folderpath!\!logfile!"
  228.  
  229. )
  230. REM File processing ends
  231.  
  232. REM ------------------------------------------------------------
  233. REM
  234. REM ENCONDIG Audio-video START
  235. REM
  236. REM -----------------------------------------------------------
  237.  
  238. REM ---------------------------------------
  239. REM When 0 TRANSLATIONS in Course title
  240. REM ---------------------------------------
  241.  
  242. if !translations_count!==0 (
  243.  
  244. set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
  245.  
  246. REM Encode with original audio
  247. call :Func_EncodeFFmpeg "original"
  248. call :Func_LogFile "run"
  249. call :Func_MoveToEdit "run"
  250.  
  251.  
  252. REM --------------------------------------
  253. REM 1
  254. REM When 1 TRANSLATIONS in Course title
  255. REM --------------------------------------
  256.  
  257. REM If zoom with 1 translation
  258. ) else if !translations_count!==1 (
  259.  
  260.  
  261. set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
  262.  
  263. REM Encode with original audio
  264. call :Func_EncodeFFmpeg "original"
  265. call :Func_LogFile "run"
  266. call :Func_MoveToEdit "run"
  267.  
  268. REM Loop translation list
  269. REM ----------------------------------
  270. for %%1 in (!translations_list!) do (
  271.  
  272. REM current translation audio
  273. set currenttranslation=%%1
  274. set translationaudio=!translation_1!
  275. REM Volume
  276. set originalavolume=volume=0.1
  277.  
  278. REM output filename
  279. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  280.  
  281. REM Encode video with mixed original and translation audio
  282. call :Func_EncodeFFmpeg "translation"
  283. call :Func_LogFile "run"
  284. call :Func_MoveToEdit "run"
  285. )
  286. REM end for translation list
  287.  
  288. REM Move files after encoding
  289. REM call :Func_MoveToEdit "run"
  290.  
  291.  
  292. REM ----------------------------------
  293. REM 2
  294. REM When REM en 2 TRANSLATIONS in Course title
  295. REM ----------------------------------
  296.  
  297. ) else if !translations_count!==2 (
  298.  
  299. REM Loop translation list
  300. REM -------------------------------------
  301. for %%1 in (!translations_list!) do (
  302. set currenttranslation=%%1
  303.  
  304. REM IF course main language = tranlation langeuge
  305. REM ------------------------------------------------
  306. if "!currenttranslation!"=="!courselanguage!" (
  307.  
  308. REM With current situation, set translation file
  309. REM -----------------------------------------------
  310.  
  311. REM set translation file, if course ET, translation ET
  312. if "!courselanguage!"=="ET" (
  313. set translationaudio=!translation_2!
  314.  
  315. REM set translation file, if course RU, translation RU
  316. ) else if "!courselanguage!"=="RU" (
  317. set translationaudio=!translation_1!
  318.  
  319. REM set translation file, if course EN, translation EN
  320. ) else if "!courselanguage!"=="EN" (
  321. set translationaudio=!translation_1!
  322.  
  323. ) else (
  324. echo.
  325. )
  326.  
  327. REM set ffmpgeg variables: original volume and outputfile
  328. set originalavolume=volume=1
  329. set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
  330.  
  331. REM Call enconding, loging, moving functions
  332. call :Func_EncodeFFmpeg "translation"
  333. call :Func_LogFile "run"
  334. call :Func_MoveToEdit "run"
  335.  
  336.  
  337. REM IF course main language is not tranlation langeuge
  338. REM ---------------------------------------------------
  339. ) else (
  340.  
  341. REM Course lang ET
  342. REM -----------------
  343. if "!courselanguage!"=="ET" (
  344.  
  345. REM original audio only
  346. REM ------------------------
  347. set originalavolume=volume=1
  348. set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
  349.  
  350. call :Func_EncodeFFmpeg "original"
  351. call :Func_LogFile "run"
  352. call :Func_MoveToEdit "run"
  353.  
  354.  
  355. REM With current translation, set translation file
  356. REM -----------------------------------------------
  357. REM current translation is RU
  358. if "!currenttranslation!"=="RU" (
  359.  
  360. set translationaudio=!translation_2!
  361. set originalavolume=volume=0.1
  362. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  363.  
  364. call :Func_EncodeFFmpeg "translation"
  365. call :Func_LogFile "run"
  366. call :Func_MoveToEdit "run"
  367.  
  368.  
  369. REM current translation is EN
  370. ) else if "!currenttranslation!"=="EN" (
  371.  
  372. set translationaudio=!translation_1!
  373. set originalavolume=volume=0.1
  374. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  375.  
  376. call :Func_EncodeFFmpeg "translation"
  377. call :Func_LogFile "run"
  378. call :Func_MoveToEdit "run"
  379.  
  380. ) else (
  381. echo.
  382. )
  383. )
  384. REM end ET Courselanguage
  385.  
  386.  
  387. REM Course lang RU
  388. REM -----------------
  389. if "!courselanguage!"=="RU" (
  390.  
  391. REM original audio only
  392. REM ------------------------
  393. set originalavolume=volume=1
  394. set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
  395.  
  396. call :Func_EncodeFFmpeg "original"
  397. call :Func_LogFile "run"
  398. call :Func_MoveToEdit "run"
  399.  
  400. if "!currenttranslation!"=="ET" (
  401.  
  402. set translationaudio=!translation_2!
  403. set originalavolume=volume=0.1
  404. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  405.  
  406. call :Func_EncodeFFmpeg "translation"
  407. call :Func_LogFile "run"
  408. call :Func_MoveToEdit "run"
  409.  
  410.  
  411. REM current translation is EN
  412. ) else if "!currenttranslation!"=="EN" (
  413.  
  414. set translationaudio=!translation_1!
  415. set originalavolume=volume=0.1
  416. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  417.  
  418. call :Func_EncodeFFmpeg "translation"
  419. call :Func_LogFile "run"
  420. call :Func_MoveToEdit "run"
  421.  
  422. ) else (
  423. echo.
  424. )
  425. )
  426. REM end RU
  427.  
  428.  
  429. REM IF Course lang EN
  430. REM -----------------
  431. if "!courselanguage!"=="EN" (
  432.  
  433. REM original audio only
  434. REM ------------------------
  435. set originalavolume=volume=1
  436. set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
  437.  
  438. call :Func_EncodeFFmpeg "original"
  439. call :Func_LogFile "run"
  440. call :Func_MoveToEdit "run"
  441.  
  442. if "!currenttranslation!"=="ET" (
  443.  
  444. set translationaudio=!translation_2!
  445. set originalavolume=volume=0.1
  446. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  447.  
  448. call :Func_EncodeFFmpeg "translation"
  449. call :Func_LogFile "run"
  450. call :Func_MoveToEdit "run"
  451.  
  452. REM current translation RU
  453. ) else if "!currenttranslation!"=="RU" (
  454.  
  455. set translationaudio=!translation_1!
  456. set originalavolume=volume=0.1
  457. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  458.  
  459. call :Func_EncodeFFmpeg "translation"
  460. call :Func_LogFile "run"
  461. call :Func_MoveToEdit "run"
  462.  
  463. ) else (
  464. echo.
  465. )
  466. )
  467. REM end EN
  468.  
  469. )
  470. REM IF course main language is or is not tranlation language
  471.  
  472. )
  473. REM END: Translation list loop
  474.  
  475. REM END: with translations_count = 2
  476.  
  477.  
  478. REM -------------------------------------------
  479. REM
  480. REM When 3 TRANSLATIONS in Course title
  481. REM
  482. REM -------------------------------------------
  483. ) else if !translations_count! == 3 (
  484.  
  485. REM Loop all 3 translations
  486. REM minus same as course - so 2 translations
  487. REM -------------------------------------
  488. for %%1 in (!translations_list!) do (
  489. set currenttranslation=%%1
  490.  
  491. REM With currenttranslation, set translation file
  492. REM -----------------------------------------------
  493. if "!currenttranslation!"=="ET" (
  494. set translationaudio=!translation_3!
  495.  
  496. ) else if "!currenttranslation!"=="RU" (
  497. set translationaudio=!translation_2!
  498.  
  499. ) else if "!currenttranslation!"=="EN" (
  500. set translationaudio=!translation_1!
  501.  
  502. ) else (
  503. echo.
  504. )
  505.  
  506. REM IF course main language = tranlation langeuge
  507. REM ------------------------------------------------
  508. if "!currenttranslation!"=="!courselanguage!" (
  509.  
  510. set originalavolume=volume=1
  511. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  512.  
  513. REM Encode video viwth course lang=translation lang
  514. call :Func_EncodeFFmpeg "translation"
  515. call :Func_LogFile "run"
  516. call :Func_MoveToEdit "run"
  517.  
  518. REM if translation is not course main language
  519. ) else (
  520.  
  521. REM set ffmpeg
  522. set originalavolume=volume=0.1
  523. set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
  524.  
  525. call :Func_EncodeFFmpeg "translation"
  526. call :Func_LogFile "run"
  527. call :Func_MoveToEdit "run"
  528.  
  529. )
  530. REM end current translation = course translation
  531.  
  532. )
  533. REM end translations list
  534.  
  535. )
  536. REM END: translations_count == 3
  537.  
  538. )
  539. REM subfolder end
  540. REM echo subfolder end
  541.  
  542.  
  543. REM move foldes composed folder
  544. REM ------------------------------
  545. REM Call function for moving folders with argument "run"
  546.  
  547.  
  548. call :Func_MoveComposedFolders "run"
  549.  
  550. )
  551. REM folder end
  552.  
  553.  
  554.  
  555. REM ---------------------------------------------------------------
  556. REM
  557. REM FUNCTION: Encode width ffmpeg
  558. REM
  559. REM ---------------------------------------------------------------
  560.  
  561. :Func_EncodeFFmpeg
  562.  
  563. REM todo move file only if it exists
  564. REM todo not if exist but if not exists, then make folder
  565.  
  566. REM IF argument in calling fuction is not empty then run this fuction
  567. if not "%1"=="" (
  568.  
  569. if "%~1"=="original" (
  570.  
  571. REM Encode with originalaudio, side-by-side with top and bottom image
  572. ffmpeg -i "!top_image!" -i "!subfolderpath!\!presentation!" -i "!subfolderpath!\!presenter!" -i "!bottom_image!" -i "!subfolderpath!\!originalaudio!" -filter_complex "[0:v]scale=1920:270[top]; [1:v]scale=960:540,setsar=1/1[pre]; [2:v]scale=960:540,setsar=1/1,unsharp=luma_msize_x=5:luma_msize_y=5:luma_amount=2.2:chroma_msize_x=5:chroma_msize_y=5:chroma_amount=1.8,eq=brightness=0.05:contrast=1.05[prs]; [pre][prs]hstack=inputs=2[middle]; [3:v]scale=1920:270[bottom]; [top][middle][bottom]vstack=inputs=3[video]; [4:a]volume=1,acompressor=threshold=-12dB:ratio=9:attack=200:release=1000,alimiter=limit=-4dB[audio]" -map "[video]" -map "[audio]" -c:v libx264 -preset medium -b:v 8000k -c:a aac -b:a 192k -ac 2 -q:a 0 -ar 48000 -shortest -y "!folderpath!\!outputfile!"
  573.  
  574.  
  575. ) else if "%~1"=="translation" (
  576.  
  577. REM Encode with originalaudio and translationaudio, side-by-side with top and bottom image
  578. ffmpeg -i "!top_image!" -i "!subfolderpath!\!presentation!" -i "!subfolderpath!\!presenter!" -i "!bottom_image!" -i "!subfolderpath!\!originalaudio!" -i "!subfolderpath!\!translationaudio!" -filter_complex "[0:v]scale=1920:270[top]; [1:v]scale=960:540,setsar=1/1[pre]; [2:v]scale=960:540,setsar=1/1,unsharp=luma_msize_x=5:luma_msize_y=5:luma_amount=2.2:chroma_msize_x=5:chroma_msize_y=5:chroma_amount=1.8,eq=brightness=0.05:contrast=1.05[prs]; [pre][prs]hstack=inputs=2[middle]; [3:v]scale=1920:270[bottom]; [top][middle][bottom]vstack=inputs=3[video]; [4:a]!originalavolume!,acompressor=threshold=-12dB:ratio=9:attack=200:release=1000,alimiter=limit=-4dB[a1]; [5:a]volume=1,acompressor=threshold=-12dB:ratio=9:attack=200:release=1000,alimiter=limit=-4dB[a2]; [a1][a2]amix=inputs=2[audio]" -map "[video]" -map "[audio]" -c:v libx264 -preset medium -b:v 8000k -c:a aac -b:a 192k -ac 2 -q:a 0 -ar 48000 -shortest -y "!folderpath!\!outputfile!"
  579.  
  580. ) else (
  581.  
  582. echo.
  583.  
  584. )
  585.  
  586. )
  587.  
  588. goto :eof
  589.  
  590. REM ------------------------------------------------------------
  591.  
  592.  
  593.  
  594.  
  595.  
  596. REM ---------------------------------------------------------------
  597. REM
  598. REM FUNCTION: Log file
  599. REM
  600. REM ---------------------------------------------------------------
  601.  
  602. :Func_LogFile
  603.  
  604. REM todo move file only if it exists
  605. REM todo not if exist but if not exists, then make folder
  606.  
  607. REM IF argument in calling fuction is not empty then run this fuction
  608. if not "%1"=="" (
  609.  
  610. echo ------------------------------- >> "!folderpath!\!logfile!"
  611. echo. >> "!folderpath!\!logfile!"
  612. echo encoded time: %date:/=-%_%time::=-% >> "!folderpath!\!logfile!"
  613. echo encoded file: !coursecode! !subfoldername! !currenttranslation! >> "!folderpath!\!logfile!"
  614. echo. >> "!folderpath!\!logfile!"
  615.  
  616. )
  617.  
  618. goto :eof
  619.  
  620. REM ------------------------------------------------------------
  621.  
  622.  
  623.  
  624. REM ---------------------------------------------------------------
  625. REM
  626. REM FUNCTION: Arhvice (move) composed file
  627. REM
  628. REM ---------------------------------------------------------------
  629. :Func_MoveToEdit
  630.  
  631. REM todo move file only if it exists
  632. REM todo not if exist but if not exists, then make folder
  633.  
  634. REM IF argument in calling fuction is not empty then run this fuction
  635. if not "%1"=="" (
  636.  
  637. REM If the target folder dones not exists, create this folder
  638. if not exist "!editfolder!\!coursecode!" (
  639. mkdir "!editfolder!\!coursecode!"
  640. )
  641.  
  642. REM move composed file from the source folder to the target folder
  643. REM robocopy C:\source C:\target File /mov
  644. robocopy "!root!/!folder!" "!editfolder!\!coursecode!" "!outputfile!" /mov
  645. )
  646.  
  647. goto :eof
  648. REM ------------------------------------------------------------
  649.  
  650.  
  651.  
  652.  
  653. REM ---------------------------------------------------------------
  654. REM
  655. REM FUNCTION: Arhvice (move) composed folders with result files
  656. REM
  657. REM ---------------------------------------------------------------
  658. :Func_MoveComposedFolders
  659.  
  660. REM IF argument in calling fuction is not empty then run this fuction
  661. if not "%1"=="" (
  662.  
  663. REM Check if the target folder already exists
  664. if exist "!composed!\!folder!" (
  665.  
  666. REM If it exists, move all files from the source folder to the target folder
  667. robocopy "!root!/!folder!" "!composed!\!folder!" /move /e /np /s
  668.  
  669. ) else (
  670. REM If it doesn't exist, move the entire subfolder to the target folder
  671. move "!root!/!folder!" "!composed!"
  672.  
  673. )
  674.  
  675. )
  676. goto :eof
  677. REM ------------------------------------------------------------
  678.  
  679.  
  680.  
  681.  
  682. REM END Local
  683. endlocal
Advertisement
Add Comment
Please, Sign In to add comment