Mass Batch help please

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
djjogy
Posts: 1
Joined: 28 Aug 2024 08:09

Mass Batch help please

#1 Post by djjogy » 28 Aug 2024 08:20

Hello. I don't know much about DOS batch.
I have something where you just have to mark the video files and drag them to the batch. But Windows says after 200 files it won't work anymore. But I have 50,000 files.

Code: Select all

@echo off
cls & color 0B
Mode con cols=60 lines=13

cd /d 	"%~dp0"

	set "xMkvMerge=C:\Program Files\MKVToolNix\mkvmerge.exe"
	set   "xFFmpeg=C:\ffmpeg\bin\ffmpeg.exe"


if "%~1"=="" goto :loop_end

:loop 

"%xFFmpeg%" -i "%~1" -filter_complex "[0:a]loudnorm=I=-16:TP=-1.5:LRA=11:print_format=summary" -f null x 2> "%~1.txt"

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Input Integrated" "%~1.txt" ') 	DO (set "xII=%%a")
echo %xII% is the Input Integrated

for /f "tokens=4" 	%%a 	IN ('findstr /C:"Input True Peak" "%~1.txt" ') 		DO (set "xITP=%%a")
echo %xITP% is the Input True Peak

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Input LRA" "%~1.txt" ') 		DO (set "xILRA=%%a")
echo %xILRA% is the Input LRA

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Input Threshold" "%~1.txt" ') 		DO (set "xIT=%%a")
echo %xIT% is the Input Threshold

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Output Integrated" "%~1.txt" ') 	DO (set "xOI=%%a")
echo %xOI% is the Output Integrated
::not used

for /f "tokens=4" 	%%a 	IN ('findstr /C:"Output True Peak" "%~1.txt" ') 	DO (set "xOTP=%%a")
echo %xOTP% is the Output True Peak
::not used

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Output LRA" "%~1.txt" ') 		DO (set "xOLRA=%%a")
echo %xOLRA% is the Output LRA
::not used

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Output Threshold" "%~1.txt" ') 	DO (set "xOT=%%a")
echo %xOT% is the Output Threshold
::not used

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Target Offset" "%~1.txt" ') 		DO (set "xTO=%%a")
echo %xTO% is the Target Offset

md "../%~dp1../original" "%~dp1../old"
"%xFFmpeg%" -i "%~1" -af loudnorm=linear=true:I=-16:tp=-1.5:lra=11:measured_I=%xII%:measured_LRA=%xILRA%:measured_tp=%xITP%:measured_thresh=%xIT%:offset=%xTO%:print_format=summary -b:a 128k "%~dpn1.ac3"
if exist "%~dpn1.ac3" ( "%xMkvMerge%" -o "%~dp1../original\%~n1.mkv" -a !1 "%~1" "%~dpn1.ac3" ) 	else ( "%xMkvMerge%" -o "%~dp1../original\%~n1.mkv" -a !1 "%~1" )
del "%~1.txt"
del "%~dpn1.ac3"


shift

if not "%~1"=="" goto :loop

:loop_end

but need what does it all at once but that doesn't work

Code: Select all

for %~1 in (*.mp4) do (
     
  )
EXEMPLAR

Code: Select all

@echo off
cls & color 0B
Mode con cols=60 lines=13

cd /d 	"%~dp0"

	set "xMkvMerge=C:\Program Files\MKVToolNix\mkvmerge.exe"
	set   "xFFmpeg=C:\ffmpeg\bin\ffmpeg.exe"

for %~1 in (*.mp4) do (
"%xFFmpeg%" -i "%~1" -filter_complex "[0:a]loudnorm=I=-16:TP=-1.5:LRA=11:print_format=summary" -f null x 2> "%~1.txt"

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Input Integrated" "%~1.txt" ') 	DO (set "xII=%%a")
echo %xII% is the Input Integrated

for /f "tokens=4" 	%%a 	IN ('findstr /C:"Input True Peak" "%~1.txt" ') 		DO (set "xITP=%%a")
echo %xITP% is the Input True Peak

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Input LRA" "%~1.txt" ') 		DO (set "xILRA=%%a")
echo %xILRA% is the Input LRA

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Input Threshold" "%~1.txt" ') 		DO (set "xIT=%%a")
echo %xIT% is the Input Threshold

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Output Integrated" "%~1.txt" ') 	DO (set "xOI=%%a")
echo %xOI% is the Output Integrated
::not used

for /f "tokens=4" 	%%a 	IN ('findstr /C:"Output True Peak" "%~1.txt" ') 	DO (set "xOTP=%%a")
echo %xOTP% is the Output True Peak
::not used

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Output LRA" "%~1.txt" ') 		DO (set "xOLRA=%%a")
echo %xOLRA% is the Output LRA
::not used

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Output Threshold" "%~1.txt" ') 	DO (set "xOT=%%a")
echo %xOT% is the Output Threshold
::not used

for /f "tokens=3" 	%%a 	IN ('findstr /C:"Target Offset" "%~1.txt" ') 		DO (set "xTO=%%a")
echo %xTO% is the Target Offset

md "../%~dp1../original" "%~dp1../old"
"%xFFmpeg%" -i "%~1" -af loudnorm=linear=true:I=-16:tp=-1.5:lra=11:measured_I=%xII%:measured_LRA=%xILRA%:measured_tp=%xITP%:measured_thresh=%xIT%:offset=%xTO%:print_format=summary -b:a 128k "%~dpn1.ac3"
if exist "%~dpn1.ac3" ( "%xMkvMerge%" -o "%~dp1../original\%~n1.mkv" -a !1 "%~1" "%~dpn1.ac3" ) 	else ( "%xMkvMerge%" -o "%~dp1../original\%~n1.mkv" -a !1 "%~1" )
del "%~1.txt"
del "%~dpn1.ac3"

         
  )
  
  
Please help thanks

Lucky4Me
Posts: 22
Joined: 21 Oct 2020 06:33

Re: Mass Batch help please

#2 Post by Lucky4Me » 29 Aug 2024 08:34

Code: Select all

@echo off & setlocal enableDelayedExpansion
cls & color 0B
mode con cols=120 lines=6
cd /d "%~dp0"
set "xMkvMerge=C:\Program Files\MKVToolNix\mkvmerge.exe"
set "xFFmpeg=C:\ffmpeg\bin\ffmpeg.exe"

for %%a in (*.mp4) do (
cls&echo.&echo.&echo Analyzing... %%a
"%xFFmpeg%" -i "%%a" -filter_complex "[0:a]loudnorm=I=-16:TP=-1.5:LRA=11:print_format=summary" -f null x 2> "%%a.txt"
for /f "tokens=3" %%b in ('findstr /C:"Input Integrated:" "%%a.txt"') do (set "xII=%%b")
for /f "tokens=4" %%b in ('findstr /C:"Input True Peak" "%%a.txt"') do (set "xITP=%%b")
for /f "tokens=3" %%b in ('findstr /C:"Input LRA" "%%a.txt"') do (set "xILRA=%%b")
for /f "tokens=3" %%b in ('findstr /C:"Input Threshold" "%%a.txt"') do (set "xIT=%%b")
for /f "tokens=3" %%b in ('findstr /C:"Output Integrated" "%%a.txt"') do (set "xOI=%%b")
for /f "tokens=4" %%b in ('findstr /C:"Output True Peak" "%%a.txt"') do (set "xOTP=%%b")
for /f "tokens=3" %%b in ('findstr /C:"Output LRA" "%%a.txt"') do (set "xOLRA=%%b")
for /f "tokens=3" %%b in ('findstr /C:"Output Threshold" "%%a.txt"') do (set "xOT=%%b")
for /f "tokens=3" %%b in ('findstr /C:"Target Offset" "%%a.txt"') do (set "xTO=%%b")
md "%%~na" "%%~na/original" "%%~na/new" 1>NUL 2>&1
move /y "%%a" "%%~na/original" 1>NUL 2>&1
cls&echo.&echo.&echo Creating... %%~na.ac3
"%xFFmpeg%" -i "%%~na/original/%%a" -af "loudnorm=linear=true:I=-16:tp=-1.5:lra=11:measured_I=!xII!:measured_LRA=!xILRA!:measured_tp=!xITP!:measured_thresh=!xIT!:offset=!xTO!:print_format=summary" -b:a 128k "%%~na.ac3" 1>NUL 2>&1
cls&echo.&echo.&echo Constructing... %%~na.mkv
if exist "%%~na.ac3" (
	"%xMkvMerge%" -o "%%~na/new/%%~na.mkv" --no-audio "%%~na/original/%%a" "%%~na.ac3" 1>NUL 2>&1
	) else (
	"%xMkvMerge%" -o "%%~na/new/%%~na.mkv" -a !1 "%%~na/original/%%a" 1>NUL 2>&1
	)
del "%%a.txt" 1>NUL 2>&1
del "%%~na.ac3" 1>NUL 2>&1
)
exit /b
Try this code.
Before run it on your directory, do a test.
Make a directory and copy 10, 20 or more mp4 files to that directory.
Put the batchfile in that directory and start it with admin rights.
The batchfile will run for all mp4 files and do the following
Analyzing the mp4 files to find all the variables, your are looking for
Once it has done this, it will create a directory with the name of the mp4 (without extention) and 2 more subdirectories "original and new"
It will move the mp4 file to the directory "original" and starts creating the mp4 (without extention) ac3 file
Once the ac3 file has been created it will construct the mkv file in the directory "new"
then it will delete the "mp4.txt" file and the created "ac3" file.
and starts over with the next mp4 file

I have changed something in your line that constructs the mkv file.

your line
"%xMkvMerge%" -o "%%~na/new/%%~na.mkv" -a !1 "%%~na/original/%%a" "%%~na.ac3"
this adds the ac3 audiostream to the mkv file but also keeps the original audiostream in the mkv file

my line
"%xMkvMerge%" -o "%%~na/new/%%~na.mkv" --no-audio "%%~na/original/%%a" "%%~na.ac3"
this removes the original audiostream and then adds the new ac3 audiostream to the mkv, so the mkv only contains the ac3 audiostream

When everything went ok, then you can run it on your directory that contains all your mp4.

This works only if all mp4 files are in the parent directory.

Squashman
Expert
Posts: 4483
Joined: 23 Dec 2011 13:59

Re: Mass Batch help please

#3 Post by Squashman » 29 Aug 2024 08:51

cmd.exe has a line execution limit of 8192 characters. When you drag and drop files onto a batch file you are sending in every fully qualified path to the file plus quotes if the file path has spaces. Reading the directory with a FOR command is a much better option.

Post Reply