I'm generating html with a batch file for personal use, and one of my sections I'm getting the width and height of all mp4 files in a folder. This "mp4 library" can have files swapped out, renamed, added to, or extracted, etc...so I don't want to manually enter in the width and height every time its gets updated.
This code below works, but it is very slow...is there any way to make it faster using a batch file?
for /f %%g in ('dir /B /S *.mp4') do (
set "g=%%g"
set "g=!g:\=/!"
for /f "tokens=1 delims=x" %%a in ('ffprobe -v error -select_streams v:0 -show_entries stream^=width^,height -of csv^=s^=x:p^=0 %%g') do set sW=%%a
for /f "tokens=2 delims=x" %%b in ('ffprobe -v error -select_streams v:0 -show_entries stream^=width^,height -of csv^=s^=x:p^=0 %%g') do set sH=%%b
echo %TAB% %TAB% ^<span^>^ ^<a style="text-decoration:none" class="image" href="file:///!g!" target="_blank"^>^ ^<video width="!sW!" height="!sH!" poster="file:///S:/_Stuff/_Data/_o/6.gif" poster="file:///S:/_Stuff/_Data/_o/6.gif" preload="auto" muted autoplay loop^>^ ^<source src="file:///!g!" type="video/mp4"^>^ ^</video^>^ ^</a^>^ ^</span^>^ >> _01.html 2>nul
)
**UPDATE: I tried this and it works, took 4 seconds vs 11seconds, but I just noticed a new answer so I will now try that suggestion out!
@echo off
setlocal EnableDelayedExpansion
>_output_test.txt (for /f %%g in ('dir /B /S *.mp4') do (
set "g=%%g"
set "g=!g:\=/!"
REM @echo !g!
for /f "tokens=1,2 delims=x" %%a in ('ffprobe -v error -select_streams v:0 -show_entries stream^=width^,height -of csv^=s^=x:p^=0 %%g') do (
set sW=%%a
set sH=%%b
)
REM @echo !sW!
REM @echo !sH!
@echo %TAB% %TAB% ^<span^>^ ^<a style="text-decoration:none" class="image" href="file:///!g!" target="_blank"^>^ ^<video width="!sW!" height="!sH!" poster="file:///S:/_DaveStuff/_Data/_o/6.gif" preload="auto" muted autoplay loop^>^ ^<source src="file:///!g!" type="video/mp4"^>^ ^</video^>^ ^</a^>^ ^</span^>^
)
)
endlocal
pause
exit