@echo off
Rem PostProcessing.bat
Rem This script will be run automatically by GBPVR (when found) after a recording is finished
Rem To enable it put this file inside your GBPVR default program directory (C:\Program Files\devnz\gbpvr\)
Rem The script is called with two parameters
Rem %1 is the fully qualified name of the recorded mpeg file.
Rem %2 is the channel number of the recording
REM Cancel any Shutdown session
psshutdown -a
set gbpvr_dir=%ProgramFiles%\devnz\gbpvr
set logfile="%gbpvr_dir%\logs\postproc.log"
SET checkfile="%gbpvr_dir%\progress.txt"
rem flags to be used for standby decision
set recording_pending=no
set time_to_recording=30
set transcoding_now=yes
echo finished recording... channel %2, file %1... checking if we need to sleep... >> %logfile%
date /t >> %logfile%
time /t >> %logfile%
REM clean up temporary files
del %checkfile%
rem decide how to handle recordings based on chan rez and possibly name or other things like that
rem make sure HD recordings that you want to keep as HD do NOT go to conversion!
echo %2 %1
rem fox2 == 80
if "%2" == "80" call :s_720p2sd %1
rem cw50 == 87
if "%2" == "87" call :s_1080i2sd %1
rem cbs62 == 91
if "%2" == "91" call :s_1080i2sd %1
rem dont standby if file no_sleep.txt exists - just exit - computer will run until user decides
if exist "no_sleep.txt" goto nosleep
rem wait for another consecutive recording to start (assuming we didnt transcode)
ping -n 5 127.0.0.1
REM Check for recording in progress
echo checking if another recording in progress...
"%gbpvr_dir%\gbpvrcli.exe" /inprogress 1 /mes "{Status}\n{Title}\n{DescriptionNoWrap}\n\n" > %checkfile%
rem wait for gbpvrcli.exe to finish... maybe add start /wait to upper option?
ping -n 5 127.0.0.1
rem see if anything is being recorded now (file of non zero length)
rem echo before running progress
rem we have "progress" so do nothing
find /c "progress" %checkfile% && goto data
rem echo after running progress
rem echo before running pslist
rem make sure other ffmpeg tasks NOT running before shutting down
pslist ffmpeg > "%~dpn1running.txt"
find /c "not found" "%~dpn1running.txt" && set transcoding_now=no
rem echo after running pslist
rem del "%~dpn1running.txt"
rem check if any recording pending soon
for /F "tokens=1,2,3,4,5 delims=#" %%a in ('gbpvrcli.exe /pending 1 /message "{MinutesToStartWithPadding}#{MinutesToEndWithPadd ing}#{RecordingLengthWithPadding}#{StartTimeWithPa dding}#{Title}"') do (
rem Setlocal EnableDelayedExpansion needed to get the current values inside for-loop
Setlocal EnableDelayedExpansion
if %%a LSS %time_to_recording% (
echo %%e pending recording in %%a minutes at %%d
echo %%e pending recording in %%a minutes at %%d >> %logfile%
rem Endlocal needs to be set inside the for-loop to preserve the pending_recording value beyond for-loop
Endlocal
set recording_pending=yes
)
)
if %transcoding_now%==no if %recording_pending%==no (
rem nothing happening now - sleep!
goto empty
)
rem any other case means its recording/transcoding/pending recording soon
GOTO data
:empty
echo not recording...
echo nothing is currently recording or transcoding... standby in 5 minutes... >> %logfile%
date /t >> %logfile%
time /t >> %logfile%
del "%~dpn1running.txt"
del %checkfile%
rem make sure we dont get double shutdown!
psshutdown -a
rem standby interactive 5 minutes
psshutdown -d -c -t 300
goto end
:data
echo recording or transcoding... do nothing
echo still recording or transcoding... no standby yet... >> %logfile%
type "%~dpn1running.txt" >> %logfile%
del "%~dpn1running.txt"
type %checkfile% >> %logfile%
del %checkfile%
date /t >> %logfile%
time /t >> %logfile%
goto end
rem sub for converting 720p to sd (remove side pillars)
:s_720p2sd
echo transcode 720p %1
echo transcode 720p %1 >> %logfile%
psshutdown -a
rem convert low priority to allow normal use of windows
rem this does not work --- start /low /wait /b /d".\Third Party\FFmpeg\"
".\Third Party\FFmpeg\ffmpeg.exe" -y -i %1 -b 4000k -ab 128k -r 29.97 -s 1024x490 -f svcd -cropleft 160 -cropright 160 -croptop 10 -aspect 4:3 -async 15 -threads 8 "%~dpn1temp.mpg" >> "logs\%~n1ffmpeg.log" 2>&1
rem this keeps recording
ren %1 "x%~nx1"
rem use same name to avoid need for database updates
ren "%~dpn1temp.mpg" "%~nx1"
goto end
rem sub for converting 1080i to sd (remove side pillars)
:s_1080i2sd
echo transcode 1080i %1
echo transcode 1080i %1 >> %logfile%
psshutdown -a
rem convert low priority to allow normal use of windows
rem this does not work --- start /low /wait /b /d".\Third Party\FFmpeg\"
".\Third Party\FFmpeg\ffmpeg.exe" -y -i %1 -b 4000k -ab 128k -r 29.97 -s 1184x500 -f svcd -cropleft 240 -cropright 240 -croptop 20 -aspect 4:3 -async 15 -threads 8 "%~dpn1temp.mpg" >> "logs\%~n1ffmpeg.log" 2>&1
rem this keeps recording
ren %1 "x%~nx1"
rem use same name to avoid need for database updates
ren "%~dpn1temp.mpg" "%~nx1"
goto end
:nosleep
echo sleep disabled (found no_sleep.txt)... do nothing
echo sleep disabled (found no_sleep.txt)... do nothing >> %logfile%
date /t >> %logfile%
time /t >> %logfile%
del "%~dpn1running.txt"
del %checkfile%
goto end
:end