Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- setlocal EnableDelayedExpansion
- :: Author: Rein Laaneser, 2023, CC: BY-SA
- REM ---------------------------------------------------
- REM
- REM PREREQUIEMENTS
- REM
- REM ---------------------------------------------------
- :: FOLDERS AND FILES
- :: Zoom files are downloaded to root/folder/subfolder,
- :: download from zoom to subfolder is provided with separate sript/automation.
- :: Folder name includes 6 character course code and 2 character lang code
- :: like this "RRT301 ET".
- :: Subfolder name includes zoom recoding date
- :: like this "2023-01-21".
- :: changes to ver5
- :: Function Func_MoveToEdit is updated
- :: changes to ver6
- :: created functions Func_LogFile and Func_EncodeFFmpeg
- :: changes to ver7
- :: 2 translation files Check
- :: changes to ver8
- :: with two translations if one is same woks
- :: this means there is 2 different Language
- :: todo: 3 different language with 1 wihtout translaton and 2 with translation
- :: ver 9
- :: With two translations testing works.
- :: Needs to be correted tested
- :: Needs to be optimize code, as original works twice same procedure.
- :: ver 10
- :: testing with three translations
- :: ver 11
- :: clean ver 10
- :: other same
- REM ---------------------------------------------------
- REM
- REM INITIAL VARIABLES
- REM
- REM ---------------------------------------------------
- REM Source folders
- set root=I:\_2_DoCompose2
- REM Encoded source folders
- set composed=I:\_3_Composed2
- REM Encoded videos
- set editfolder=I:\_4_Edit
- REM Images
- set images=I:\_Images
- REM ---------------------------------------------------
- REM
- REM FOLDERS processing start
- REM
- REM ---------------------------------------------------
- for /d %%a in ("%root%\*") do (
- echo Processing folder %%a...
- REM folder name for arcival purpuse
- set "folder=%%~nxa"
- REM strip folder name space
- set "foldername=%%~nxa"
- set "foldername=!foldername: =!"
- REM set folder path
- set folderpath=!root!\!folder!
- REM Course code
- set "coursecode=!foldername:~0,6!"
- echo Folder name stripted is: !foldername!
- REM Define course Language from folder
- if "!foldername:~6,2!"=="ET" (
- set "courselanguage=ET"
- ) else if "!foldername:~6,2!"=="EN" (
- set "courselanguage=EN"
- ) else if "!foldername:~6,2!"=="RU" (
- set "courselanguage=RU"
- ) else (
- echo.
- )
- REM --IMAGE --
- REM Set video top and bottom image variables
- REM Top image
- if exist "%images%\!coursecode!_top.png" (
- set "top_image=%images%\!coursecode!_top.png"
- ) else (
- set "top_image=%images%\Default_top.png"
- )
- REM Bottom image
- if exist "%images%\!coursecode!_bottom.png" (
- set "bottom_image=%images%\!coursecode!_bottom.png"
- ) else (
- set "bottom_image=%images%\Default_bottom.png"
- )
- REM -- TRANSATIONS LIST & COUNT --
- REM Define Translations list based on folder name
- REM Extract translations list
- set foldersting=%%~nxa
- for /f "tokens=2 delims=-" %%1 in ("!foldersting!") do (
- set translations_list=%%1
- )
- REM Count translations
- set /A translations_count=0
- for %%i in (!translations_list!) do (
- set /A translations_count+=1
- )
- REM ---------------------------------------------------
- REM
- REM Sub-Folders processing start
- REM
- REM ---------------------------------------------------
- for /d %%b in ("%%a\*") do (
- echo Processing subfolder %%b...
- set "subfoldername=%%~nxb"
- set subfolderpath=!root!\!folder!\!subfoldername!
- REM -----------------
- REM log file creation
- REM -----------------
- REM set filelist txt file name
- set "logfile=!subfoldername! logfile.txt"
- if exist "!folderpath!\!logfile!" del "!folderpath!\!logfile!"
- echo _________________________________________________ >> "!folderpath!\!logfile!"
- echo Processing start >> "!folderpath!\!logfile!"
- echo %date:/=-%_%time::=-% >> "!folderpath!\!logfile!"
- echo _________________________________________________ >> "!folderpath!\!logfile!"
- echo. >> "!folderpath!\!logfile!"
- echo Files list: >> "!folderpath!\!logfile!"
- echo. >> "!folderpath!\!logfile!"
- REM ---------------------------------------------------
- REM
- REM File processing start
- REM
- REM ---------------------------------------------------
- REM is this file ET, RU, EN set variables
- for %%c in ("%%b\*") do (
- echo Processing file %%c...
- set "filename=%%~nxc"
- REM Presentar
- if "!filename:_avo_=!" neq "!filename!" (
- set "presenter=%%~nxc"
- )
- REM Presentation
- if "!filename:_as_=!" neq "!filename!" (
- set "presentation=%%~nxc"
- )
- REM NR 1 translation
- if "!filename:_interpret_separate1=!" neq "!filename!" (
- set "translation_1=%%~nxc"
- )
- REM NR 2 translation
- if "!filename:_interpret_separate2=!" neq "!filename!" (
- set "translation_2=%%~nxc"
- )
- REM NR 3 translation
- if "!filename:_interpret_separate3=!" neq "!filename!" (
- set "translation_3=%%~nxc"
- )
- REM Original audio
- if "!filename:_Recording.m4a=!" neq "!filename!" (
- set "originalaudio=%%~nxc"
- echo Original audio is !originalaudio!
- )
- REM Add the file name to the file list
- echo %%~nxc >> "!folderpath!\!logfile!"
- )
- REM File processing ends
- REM ------------------------------------------------------------
- REM
- REM ENCONDIG Audio-video START
- REM
- REM -----------------------------------------------------------
- REM ---------------------------------------
- REM When 0 TRANSLATIONS in Course title
- REM ---------------------------------------
- if !translations_count!==0 (
- set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
- REM Encode with original audio
- call :Func_EncodeFFmpeg "original"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM --------------------------------------
- REM 1
- REM When 1 TRANSLATIONS in Course title
- REM --------------------------------------
- REM If zoom with 1 translation
- ) else if !translations_count!==1 (
- set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
- REM Encode with original audio
- call :Func_EncodeFFmpeg "original"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM Loop translation list
- REM ----------------------------------
- for %%1 in (!translations_list!) do (
- REM current translation audio
- set currenttranslation=%%1
- set translationaudio=!translation_1!
- REM Volume
- set originalavolume=volume=0.1
- REM output filename
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- REM Encode video with mixed original and translation audio
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- )
- REM end for translation list
- REM Move files after encoding
- REM call :Func_MoveToEdit "run"
- REM ----------------------------------
- REM 2
- REM When REM en 2 TRANSLATIONS in Course title
- REM ----------------------------------
- ) else if !translations_count!==2 (
- REM Loop translation list
- REM -------------------------------------
- for %%1 in (!translations_list!) do (
- set currenttranslation=%%1
- REM IF course main language = tranlation langeuge
- REM ------------------------------------------------
- if "!currenttranslation!"=="!courselanguage!" (
- REM With current situation, set translation file
- REM -----------------------------------------------
- REM set translation file, if course ET, translation ET
- if "!courselanguage!"=="ET" (
- set translationaudio=!translation_2!
- REM set translation file, if course RU, translation RU
- ) else if "!courselanguage!"=="RU" (
- set translationaudio=!translation_1!
- REM set translation file, if course EN, translation EN
- ) else if "!courselanguage!"=="EN" (
- set translationaudio=!translation_1!
- ) else (
- echo.
- )
- REM set ffmpgeg variables: original volume and outputfile
- set originalavolume=volume=1
- set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
- REM Call enconding, loging, moving functions
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM IF course main language is not tranlation langeuge
- REM ---------------------------------------------------
- ) else (
- REM Course lang ET
- REM -----------------
- if "!courselanguage!"=="ET" (
- REM original audio only
- REM ------------------------
- set originalavolume=volume=1
- set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
- call :Func_EncodeFFmpeg "original"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM With current translation, set translation file
- REM -----------------------------------------------
- REM current translation is RU
- if "!currenttranslation!"=="RU" (
- set translationaudio=!translation_2!
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM current translation is EN
- ) else if "!currenttranslation!"=="EN" (
- set translationaudio=!translation_1!
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- ) else (
- echo.
- )
- )
- REM end ET Courselanguage
- REM Course lang RU
- REM -----------------
- if "!courselanguage!"=="RU" (
- REM original audio only
- REM ------------------------
- set originalavolume=volume=1
- set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
- call :Func_EncodeFFmpeg "original"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- if "!currenttranslation!"=="ET" (
- set translationaudio=!translation_2!
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM current translation is EN
- ) else if "!currenttranslation!"=="EN" (
- set translationaudio=!translation_1!
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- ) else (
- echo.
- )
- )
- REM end RU
- REM IF Course lang EN
- REM -----------------
- if "!courselanguage!"=="EN" (
- REM original audio only
- REM ------------------------
- set originalavolume=volume=1
- set outputfile=!coursecode! !subfoldername! !courselanguage!.mp4
- call :Func_EncodeFFmpeg "original"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- if "!currenttranslation!"=="ET" (
- set translationaudio=!translation_2!
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- REM current translation RU
- ) else if "!currenttranslation!"=="RU" (
- set translationaudio=!translation_1!
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- ) else (
- echo.
- )
- )
- REM end EN
- )
- REM IF course main language is or is not tranlation language
- )
- REM END: Translation list loop
- REM END: with translations_count = 2
- REM -------------------------------------------
- REM 3
- REM When 3 TRANSLATIONS in Course title
- REM -------------------------------------------
- ) else if !translations_count! == 3 (
- echo arvan et translations count == 3
- REM Loop translation list
- REM -------------------------------------
- for %%1 in (!translations_list!) do (
- set currenttranslation=%%1
- REM With currenttranslation, set translation file
- REM -----------------------------------------------
- if "!currenttranslation!"=="ET" (
- set translationaudio=!translation_3!
- ) else if "!currenttranslation!"=="RU" (
- set translationaudio=!translation_2!
- ) else if "!currenttranslation!"=="EN" (
- set translationaudio=!translation_1!
- ) else (
- echo.
- )
- REM IF course main language = tranlation langeuge
- REM ------------------------------------------------
- if "!currenttranslation!"=="!courselanguage!" (
- set originalavolume=volume=1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- REM Encode video viwth course lang=translation lang
- echo current translation = course language
- echo ennne encondigut
- REM siin veel ok
- pause
- call :Func_EncodeFFmpeg "translation"
- echo parast encodingut
- pause
- REM ---------------------------------------------------------------------
- REM Siin probleem !!!!!
- REM ---------------------------------------------------------------------
- echo enne logfile
- call :Func_LogFile "run"
- echo parast logfile
- pause
- echo enne moving FILES
- call :Func_MoveToEdit "run"
- echo parast moving files
- pause
- REM if translation is not course main language
- ) else (
- REM set ffmpeg
- set originalavolume=volume=0.1
- set outputfile=!coursecode! !subfoldername! !currenttranslation!.mp4
- call :Func_EncodeFFmpeg "translation"
- call :Func_LogFile "run"
- call :Func_MoveToEdit "run"
- )
- REM end current translation = course translation
- )
- REM end translations list
- )
- REM END: translations_count == 3
- )
- REM subfolder end
- REM echo subfolder end
- REM move foldes composed folder
- REM ------------------------------
- REM Call function for moving folders with argument "run"
- call :Func_MoveComposedFolders "run"
- )
- REM folder end
- REM ---------------------------------------------------------------
- REM
- REM FUNCTION: Encode width ffmpeg
- REM
- REM ---------------------------------------------------------------
- :Func_EncodeFFmpeg
- REM todo move file only if it exists
- REM todo not if exist but if not exists, then make folder
- REM IF argument in calling fuction is not empty then run this fuction
- if not "%1"=="" (
- if "%~1"=="original" (
- REM Encode with originalaudio, side-by-side with top and bottom image
- echo encode original
- pause
- 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[prs]; [pre][prs]hstack=inputs=2[middle]; [3:v]scale=1920:270[bottom]; [top][middle][bottom]vstack=inputs=3[video]; [4:a]volume=1[audio]" -map "[video]" -map "[audio]" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 192k -ac 2 -ar 44100 -shortest -y "!folderpath!\!outputfile!"
- ) else if "%~1"=="translation" (
- REM Encode with originalaudio and translationaudio, side-by-side with top and bottom image
- echo encode translation
- pause
- 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[prs]; [pre][prs]hstack=inputs=2[middle]; [3:v]scale=1920:270[bottom]; [top][middle][bottom]vstack=inputs=3[video]; [4:a]!originalavolume![a1]; [5:a]volume=1[a2]; [a1][a2]amix=inputs=2[audio]" -map "[video]" -map "[audio]" -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 192k -ac 2 -ar 44100 -shortest -y "!folderpath!\!outputfile!"
- ) else (
- echo !!! seems that Fucntion "EncodeFFmpeg" argument not working
- pause
- )
- )
- goto :eof
- REM ------------------------------------------------------------
- REM ---------------------------------------------------------------
- REM
- REM FUNCTION: Log file
- REM
- REM ---------------------------------------------------------------
- :Func_LogFile
- REM todo move file only if it exists
- REM todo not if exist but if not exists, then make folder
- REM IF argument in calling fuction is not empty then run this fuction
- if not "%1"=="" (
- echo ------------------------------- >> "!folderpath!\!logfile!"
- echo. >> "!folderpath!\!logfile!"
- echo encoded time: %date:/=-%_%time::=-% >> "!folderpath!\!logfile!"
- echo encoded file: !coursecode! !subfoldername! !currenttranslation! >> "!folderpath!\!logfile!"
- echo. >> "!folderpath!\!logfile!"
- )
- goto :eof
- REM ------------------------------------------------------------
- REM ---------------------------------------------------------------
- REM
- REM FUNCTION: Arhvice (move) composed file
- REM
- REM ---------------------------------------------------------------
- :Func_MoveToEdit
- REM todo move file only if it exists
- REM todo not if exist but if not exists, then make folder
- REM IF argument in calling fuction is not empty then run this fuction
- if not "%1"=="" (
- REM If the target folder dones not exists, create this folder
- if not exist "!editfolder!\!coursecode!" (
- mkdir "!editfolder!\!coursecode!"
- )
- REM move composed file from the source folder to the target folder
- REM robocopy C:\source C:\target File /mov
- robocopy "!root!/!folder!" "!editfolder!\!coursecode!" "!outputfile!" /mov
- )
- goto :eof
- REM ------------------------------------------------------------
- REM ---------------------------------------------------------------
- REM
- REM FUNCTION: Arhvice (move) composed folders with result files
- REM
- REM ---------------------------------------------------------------
- :Func_MoveComposedFolders
- REM IF argument in calling fuction is not empty then run this fuction
- if not "%1"=="" (
- REM Check if the target folder already exists
- if exist "!composed!\!folder!" (
- REM If it exists, move all files from the source folder to the target folder
- robocopy "!root!/!folder!" "!composed!\!folder!" /move /e /np /s
- ) else (
- REM If it doesn't exist, move the entire subfolder to the target folder
- move "!root!/!folder!" "!composed!"
- )
- )
- goto :eof
- REM ------------------------------------------------------------
- REM END Local
- endlocal
Advertisement
Add Comment
Please, Sign In to add comment