Selur's Little Message Board

Full Version: How do you use the external call on queue finished feature?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to execute a .bat file after the queue completes.  I tried to just supply the path to the .bat file, but that did not work.
Sounds right to me, but I have not tried this for ages,...
Debug output should show whether Hybrid tried to execute the bat file,...

Cu Selur
Quote:I would like to execute a .bat file after the queue completes.
Did set "On queue finished:" to "call external at queue finished external call" ? Or did you just set the file?

Cu Selur
Yes.  I just tried it again, and I get this message in the log when it fails:

Job 2025-12-29@11_48_24_9210 finished!
An error occurred while calling: F:\SBP\RESIZE\Ladder - x265 SBP Tuned - CRF22 Slow - Full Color 10bit BT709 - Encode Aud.bat

I will try putting the path in quotes next.

I tried again and put the path in quotes since it had spaces.  This time it said it was successfully called, but the .bat file was not kicked off. 

Job 2025-12-29@11_48_24_9210 finished!
Successfully called: "F:\SBP\RESIZE\Ladder - x265 SBP Tuned - CRF22 Slow - Full Color 10bit BT709 - Encode Aud.bat"
Ah, okay, that is to be expected. Hybrid simply calls the call you entered. Smile
I am trying to get that feature to kick off a windows .bat file once the queue finishes.  Any idea how I might accomplish that?  I just tried calling cmd.exe to run it and that did not kick off the .bat file either.

Job 2025-12-29@11_48_24_9210 finished!
Successfully called: C:\Windows\System32\cmd.exe /c ""F:\SBP\RESIZE\Ladder - x265 SBP Tuned - CRF22 Slow - Full Color 10bit BT709 - Encode Aud.bat""
Just "F:\SBP\RESIZE\Ladder - x265 SBP Tuned - CRF22 Slow - Full Color 10bit BT709 - Encode Aud.bat" should be enough, the cmd part should not matter.

I created "c:\Users\Selur\Desktop\test.bat" with :
Code:
@echo off
echo Hello World!>F:\test.txt
as content.
log shows:
Code:
Successfully called: "c:\Users\Selur\Desktop\test.bat"
and 'F:\test.txt' was created with "Hello World!" as content.
=> seems to work fine here

Maybe try something similar simple to test and then get more complex to see where the problem is.

Cu Selur
I did end up getting this to work as I wanted.  I ended up using this for the external call:
"C:\Windows\System32\cmd.exe" /d /s /c start "Hybrid post-queue" cmd.exe /k ""F:\SBP\SCRIPTS\queue_done.cmd""

And this is the contents of queue_done.cmd:

Code:
@echo off
setlocal EnableExtensions EnableDelayedExpansion

set "WORKDIR=F:\SBP\RESIZE"
set "LOG=F:\SBP\SCRIPTS\hybrid_queue_done.log"
set "LOCKDIR=%TEMP%\hybrid_queue_done.lockdir"

REM Prevent overlapping runs
mkdir "%LOCKDIR%" 2>nul
if errorlevel 1 (
  echo Another run is already active. Exiting.
  >>"%LOG%" echo [%date% %time%] Another run already active; exiting.
  exit /b 0
)

REM Log header (this does NOT hide console output)
>>"%LOG%" echo.
>>"%LOG%" echo ===== %date% %time% =====
>>"%LOG%" echo User=%USERNAME%
>>"%LOG%" echo WorkingDir=%CD%

pushd "%WORKDIR%" || (
  echo ERROR: cannot cd to "%WORKDIR%"
  >>"%LOG%" echo ERROR: cannot cd to "%WORKDIR%"
  rmdir "%LOCKDIR%" 2>nul
  exit /b 1
)

echo Running post-queue script in: %CD%
echo (This window will show ffmpeg progress. Closing it will stop the encode.)

REM IMPORTANT: no redirection here, so you see live progress
call "F:\SBP\RESIZE\PostQ - Ladder - x265 SBP Tuned - CRF22 Slow - Full Color 10bit BT709 - Encode Aud.bat" nopause

set "EC=%errorlevel%"
echo Encode finished. ExitCode=%EC%
>>"%LOG%" echo ExitCode=%EC%

popd
rmdir "%LOCKDIR%" 2>nul
exit /b %EC%


Then the encode .bat file is:

Code:
@echo off
setlocal EnableExtensions EnableDelayedExpansion

REM Run from your working folder
pushd "F:\SBP\RESIZE" || exit /b 1

REM Prevent overlapping runs (Hybrid hook can fire twice)
set "LOCK=%TEMP%\hybrid_encode.lock"
if exist "%LOCK%" exit /b 0
> "%LOCK%" echo %DATE% %TIME%

REM Ensure output folder exists
if not exist "F:\SBP\NAME" mkdir "F:\SBP\NAME" >nul 2>&1

for %%f in (*.mp4 *.mov *.mxf *.mkv) do (
  if exist "%%f" call :processOne "%%f"
)

del "%LOCK%" 2>nul
popd

REM Only pause when run manually (no args)
if "%~1"=="" pause
exit /b 0

:processOne
set "source_file=%~1"
set "source_name=%~n1"
set "source_height="
set "acodec="
set "AOPTS=-c:a copy"

REM ---- Get source height ----
for /f "usebackq delims=" %%h in (`
  ffprobe -v error -select_streams v:0 -show_entries stream^=height -of default^=noprint_wrappers^=1:nokey^=1 "%source_file%"
`) do set "source_height=%%h"

REM Validate numeric height; skip if ffprobe failed
for /f "delims=0123456789" %%x in ("!source_height!") do set "source_height="
if not defined source_height exit /b 0

REM ---- Get audio codec (if any) ----
for /f "usebackq delims=" %%a in (`
  ffprobe -v error -select_streams a:0 -show_entries stream^=codec_name -of default^=noprint_wrappers^=1:nokey^=1 "%source_file%"
`) do set "acodec=%%a"

REM If PCM audio, encode to AAC 192k; otherwise copy
if defined acodec (
  if /i "!acodec:~0,4!"=="pcm_" set "AOPTS=-c:a aac -b:a 192k"
)

REM ---- Encode ladder (only rungs <= source height) ----
for %%r in (2160 1440 1080 720) do (
  if !source_height! GEQ %%r (
    set "OUT=F:\SBP\NAME\!source_name! - %%r.mp4"

    ffmpeg -y -nostdin -flush_packets 1 -i "%source_file%" ^
      -map 0:v:0 -map 0:a:0? ^
      -vf "scale=w=-1:h=%%r:flags=lanczos+accurate_rnd+full_chroma_int,zscale=matrix=709:transfer=709:primaries=709:range=full,format=yuv420p10le" ^
      -c:v libx265 -profile:v main10 -preset slow -crf 22 ^
      -x265-params "asm=avx512:pme=0:pmode=0:aq-strength=1.1:psy-rdoq=1.7:psy-rd=3.00:rd=4:ssim-rd=1:wpp=1:crqpoffs=-3:rect=0:ctu=32:rc-lookahead=60:subme=4:merange=32:min-cu-size=8:max-tu-size=32:tu-inter-depth=2:tu-intra-depth=2:qcomp=0.65:selective-sao=0:no-sao=1:early-skip=0:fast-intra=1:bframes=5:strong-intra-smoothing=0:keyint=300:min-keyint=28:aq-mode=3:rskip=2:deblock=-2,-2" ^
      !AOPTS! ^
      -movflags +faststart "!OUT!"

    if errorlevel 1 del /q "!OUT!" 2>nul
  )
)

exit /b 0

This kicks off a ladder encode of all files recently processed from the Hybrid queue in a new window, titled for the process, that shows the progress of the encode as if kicked off manually.  The source file is encoded to 2160p, 1440p, 1080p, and 720p for each resolution that the source file supports.  Ie a 1600p video gets encoded to 1440p, 1080p, and 720p, while preserving aspect ratio.  It also encodes to BT709, full range color, which is specific to my workflow.  Also PCM audio is converted to AAC 192KB, and all other audio formats are copied (again, specific to my flow). You can always tweak as needed for anyone interested in using it.

The x265 encode command I literally spent a couple weeks testing to find the command that preserved original details the best.  The result of this command even looks good when pixel peeping frame by frame.  I have not tested it on animated content, but I expect it would require tweaks for that type of content.
Happy you got it working the way you like it. Not really sure why you use Hybrid at all with this, but that's probably because I don't really know what you are doing. Smile

Cu Selur