I am trying to get a '# of file processed' within my script but can't get there any only total # 'found' and also disable ffmpeg to just do the same pre-scan as an inventory or check of files with specific codecs.
The problem seems to be with the nested Disabled Delayed Expansion, but I've been learning batch for the last 3 months and searching and comparing/testing scripts for weeks each day but I can't seem to break through this.
And/or using Dbenham's Return.bat call. But I'm hessitant about return.bat as it seems such a large processing/time overhead to just accumulate a counter.
Script does the the following:
- Commented out: Logging function process which creates a directory a file for each run
- Sets destination Root drive & folder: "SET drive=T:\4k.temp"
- Sets the \bin directory and initial variables: FilesFound=0
- Runs for loop to find all mkv & mp4 files
- Inside Loop: Increments variable FilesFound+=1 and sets paths and filename
- Nested for loop analyzes each file's properties to match 'codec_name' with the variable set near the top "Codec1=dts". If matched, sets SkipCodec=1
Set EnableDelayedExpansion - For each file if it's SkipCodec matched 1 it would (needed to nest mkdir underneath DisableDelayedExpansion) create a directory that matched it's current folder tree but on the destination root, set at the top.
(call :EncoderCounts - Testing/attempted to learn how to user call function to 'carry' the variable over to the 'end results' section) - Processes the FFMpeg command or Sets FilesEncoded Counter
Endlocal - Echo's Results with variables
Is anyone able to help me break through this barrier??
setlocal
rem #######1-Destination Drive #############
SET drive=T:\4k.temp
setlocal EnableExtensions EnableDelayedExpansion
SET "Codec1=dts"
SET "FINALCOMMAND="
setlocal EnableExtensions DisableDelayedExpansion
SET "ProgramFolder=C:\FFmpeg\bin"
SET "ProbeOptions=-v quiet -select_streams a:0 -show_entries "stream^^=codec_name" -of json"
SET "FilesFound=0" & SET "FilesEncoded=0" & SET "FullFileName=" & SET "output="
for /F "delims=" %%I in ('dir *.mkv *.mp4 /A-D-H /B /S 2^>nul') do (
@ECHO ================Next File: %%I =============
SET "FullFileName=%%I" & SET "output=%drive%%%~pI%%~nxI"
SET /A FilesFound+=1 & SET "AudioCodec=" & SET "SkipCodecs="
for /F "eol={ tokens=1,2 delims=,:[ ]{} " %%B in ('""%ProgramFolder%\ffprobe.exe" %ProbeOptions% "%%I""') do (
if "%%~B" == "codec_name" (
if not defined AudioCodec (
SET "AudioCodec=%%~C"
)
if "%%~C" == "%Codec1%" (set "SkipCodecs=1"
)
)
)
setlocal EnableExtensions EnableDelayedExpansion
if !SkipCodecs! == 1 (
setlocal EnableExtensions DisableDelayedExpansion
MKDIR "%drive%%%~pI" 2>null
endlocal
SET "FINALCOMMAND=ffmpeg -n -hide_banner -loglevel quiet -stats -i "!FullFileName!" -map 0:v -map 0:a:0 -c:v copy -c:a:0 ac3 -b:a:0 640k "!output!""
!FINALCOMMAND!&SET /A FilesEncoded+=1
ECHO #####COMPLETE############
) else ( ECHO #####NOT PROCESSING ############)
ECHO[
endlocal
)
if %FilesFound% == 1 ( SET "PluralS=" ) else set "PluralS=s"
@ECHO *********************************************************
ECHO re-encoded %FilesEncoded% of %FilesFound% video file%PluralS%.
endlocal
GOTO :END
:END
endlocal
endlocal
exit /b