This is my first post so I do apologize if I'm not explaining it well. Please let me know if I should re-phrase things or clarify something! I am also not exactly great with titles, so please let me know if I should change it.
To help myself explain the situation a little more, I'd like to clarify what the purpose of this is. As one of my hobbies, I help on an image archive. One of it's issues is that the only video format it supports is webm. This can sometimes result in badly converted low-quality videos by users whom have no idea how to convert, which then needs to be fixed later.
Because of this, I've been working on a bunch of batch files that could both speed up and potentially lower the amount of badly converted video, by minimizing the required user-input. You can check it out here if you'd like to: https://www.nicklo6649.com/Public%20files/index.php?dir=Batchfiles/
One of the staff members mentioned how they'd like a way to start multiple conversion at the same time and let it convert an entire folder, as their CPU is powerful enough to do so. Which is then what I've been working on now for a few days.
My current problem with the script is the fact that I cannot seem to reliably pass the FOR loop to the new command prompts that it starts in the GOTO loop, in any way.
I don't mind having to rewrite the current script, as long as it's still able to start multiple instances of ffmpeg with the FOR loop and it's specified values.
The solution would be preferred to be in form of a batch or PowerShell script, although any other language is also fine, as long as it can work alongside the batch file.
I've tried the following:
starting cmd with the FOR loop In the GOTO loop with:
start cmd.exe <FOR loop>
saving the FOR loop in a text file before the GOTO loop, starting a new batch file named command2.bat in the GOTO loop that then takes the FOR loop in the text file and saves it to a variable, and then calls the variable:
Echo "<FOR loop>"> command.txt
command2.bat script:
setlocal EnableDelayedExpansion
set /p command=<command.txt
set command="%command%"
%command%
endlocal
pause
Saving the the FOR loop in another batch file before the GOTO loop, and then starting the batch file with the GOTO loop:
Echo "<FOR loop>"> command.bat
And this is the script itself.
:next1
rem used to specify the input folder which the FOR loop should look in
set /p input=Input:
rem used to specify the output folder which the FOR loop should look in
set /p output=output:
rem used to specify how many time the GOTO loop should loop and start a new command prompt
set /p amount=:
if "%amount%"=="0" echo fatal error, please retry && goto :next1
rem this creates a folder for the temporary files ffmpeg needs to store while doing the first pass in two-pass
mkdir "temp files"
@echo on
setlocal EnableDelayedExpansion
set loop=0
:loop
echo.
start cmd.exe for %%f in ("%input%\*.*") do ffmpeg -n -i "%%f" -c:v vp9 -c:a libopus -crf 20 -b:v 192 -pix_fmt yuv420p -pass 1 -f webm "temp files\!random!" && ffmpeg -n -i "%%f" -c:v vp9 -c:a libopus -crf 20 -b:v 192 -an -pix_fmt yuv420p -pass 2 %output%\%%~nf.webm
echo.
set /a loop=%loop%+1
if "%loop%"=="%amount%" goto :next
if "%loop%"==11 goto :next
goto loop
:next
endlocal
del /q /f ffmpeg2pass*
del /q /f "temp files\*.*"
:end
choice /c EC /n /m "(E)xit or (C)ontinue"
if errorlevel 1 set exit=Quit
if errorlevel 2 set exit=Continue
if "%exit%"=="Quit" goto :exit
if "%exit%"=="Continue" goto :skip
:exit
exit
The expected output is that the script starts x amount of new command prompts, each using the same FOR loop that was defined in the script and uses the specified input, output and future selections, such as codecs.