Batch file to use BeyondTV's Archive setting to run QuickStream Fix

stevehiner

New member
This is something I've wanted to do for years and I finally took a bit of time and wrote it...

I've found that my tuners will sometimes write out invalid files. The are the right size and contain all the right data but the timecodes will be off. That totally screws up BeyondTV of course. I normally manually open VRD and run QSF on the file to fix it and then BeyondTV is happy. That's no good when my kids complain about a video being messed up and now I've gotta take some time to fix the file.

Enter QuickStreamFix.cmd
_____________________________________________________________________________________
@echo off
SETLOCAL ENABLEEXTENSIONS

rem Script to QuickstreamFix file passed in first arg. For use with BeyondTV's archive feature.

set file=%1

for %%i in (%file%) do if "%%~xi" == ".wmv" GOTO Unsupported
for %%i in (%file%) do if "%%~xi" == ".mp4" GOTO Unsupported
for %%i in (%file%) do if "%%~xi" == ".avi" GOTO Unsupported

for %%i in (%file%) do if not exist "%%~dpi%%~ni.q%%~xi" @echo "%%~dpi%%~ni%%~xi" "%%~dpi%%~ni.q%%~xi" /t1
for %%i in (%file%) do if exist "%%~dpi%%~ni%%~xi.chapters.xml" @echo "%%~dpi%%~ni.q%%~xi.chapters.xml"

for %%i in (%file%) do if not exist "%%~dpi%%~ni.q%%~xi" cscript //nologo "C:\Program Files (x86)\VideoReDoTVSuite\vp.vbs" "%%~dpi%%~ni%%~xi" "%%~dpi%%~ni.q%%~xi" /t1
for %%i in (%file%) do if exist "%%~dpi%%~ni%%~xi.chapters.xml" copy /Y "%%~dpi%%~ni%%~xi.chapters.xml" "%%~dpi%%~ni.q%%~xi.chapters.xml"

Pause
Exit

:Unsupported
@echo Unsupported file type
Pause
Exit
__________________________________________________________________________________

You put this in a .cmd file in your videoredo folder and then open BeyondTV's web admin interface and in the settings under miscellaneous settings you'll find the Archive command. Set it to the path to the cmd file. Now when you look at the details for a video in the UI there will be a new entry called Archive. When you use that BeyondTV will run this cmd file and pass the path to the video file. The cmd file will start VRD and have it QuickStream Fix the file to a new file, adding ".q" to the name so video.mpg will become video.q.mpg. It will also check for BeyondTV's chapter file and make a copy of it for the fixed version so you won't lose your smartskip data. It's possible that we don't want the smartskip data since, in my experience, if the file needs to be fixed by VRD then the commercials in the smartskip data are likely totally wrong.

I'm certainly open to ideas and improvements for this cmd file.

I made it so it rejects common BeyondTV files that VRD doesn't support (well, my version of VRD anyway). It will reject wmv, mp4 and avi files. (I'm overdue for paying to upgrade to get mp4 support)

One thing I'd need to do is improve handling of .tp files. Many of my recordings are .tp and I've noticed that VRD UI doesn't have .tp as an output type but uses .ts instead. This batch file doesn't change the extension and VRD seems to be happy enough saving it as a .tp file but it appears that BTV thinks the resulting tp file is corrupt. I suppose I'll need to make the batch file smart enough to set the output to .ts instead of just reusing the .tp extension. That will make it a fair bit more complicated so I'll save that for another time. Hopefully that will fix the output file for BTV as well.

Note that you'll need to set the correct path to the vp.vbs file in this script. In my next version I'll probably make it smart enough so it'll use the script in the same folder as the cmd file but for now it's hard coded.

Also, because this is the first version I wrote I put a Pause in there so you can see what it is doing. Remove the Pause before the exit if you trust that it does it right every time. You should be able to hit one of the number buttons on the remote to clear the pause without having to grab a keyboard.

What do you think?
 

NodNarb012

New member
Currently, if you somehow managed to pass a .jpg or something (besides wmv, mp4, and avi), your batch file would try to process it. I think you would be better off checking and accepting only files that VRD can handle. I would have done my version that way, but I'm using a different VRD than you; I don't even have BeyondTV. I like batch files, though, so I streamlined yours a bit.

Code:
@ECHO OFF

IF %~x1==.wmv GOTO Unsupported
IF %~x1==.mp4 GOTO Unsupported
IF %~x1==.avi GOTO Unsupported

IF %PROCESSOR_ARCHITECTURE%==x86 SET ProgDir=%ProgramFiles%
IF %PROCESSOR_ARCHITECTURE%==AMD64 SET ProgDir=%ProgramFiles(x86)%

IF EXIST "%ProgDir%\VideoReDoTVSuite\vp.vbs" SET vpPath=%ProgDir%\VideoReDoTVSuite\vp.vbs
IF NOT DEFINED vpPath ECHO Unable to find VideoReDo script & PAUSE & GOTO END

IF NOT EXIST "%~dpn1.q%~x1" CSCRIPT /B "%vpPath%" %1 "%~dpn1.q%~x1" /t1
IF EXIST "%~1.chapters.xml" COPY /Y "%~1.chapters.xml" "%dpn1.q%~x1.chapters.xml"

:END
EXIT

:Unsupported
ECHO Unsupported file type
PAUSE
EXIT
I also added some lines to detect the path of the vp.vbs file. I would have added more, but I don't know the path for VideoReDo Plus, and TVSuite H.264 requires that you pass a "/p:profile" argument instead of "/t1". I might revisit that tomorrow if I'm bored.
 

stevehiner

New member
Nice. I like your changes. I already modified the version I'm using so it autodetects the vp.vbs file location but your way is more elegant. I just had it check for the expected locations (including the folder containing the batch file) rather than checking the processor architecture to make an educated guess.

Yeah, I thought about making it check for the expected file extensions rather than the way I did it but since BeyondTV only handles certain extensions and I never intended this to be run from a command line I figured my way was safe enough. Maybe I'll switch it over at some point.

I did change it so it handles tp to ts conversions properly but for some reason the resulting ts file is not usable in BeyondTV. That's weird since I can do a QuickStream Fix in the VRD UI and convert a tp to a ts and it still works fine in BeyondTV, including copying the metadata. I need to do some more experimentation and then file a bug if I can confirm that the vp.vbs version results in a different file than running it from the UI.

I guess I didn't realize the %~ method of peeling apart file paths worked outside of a for loop. That syntax is listed in the help under for loops and I never tried it elsewhere. That part felt dirty to me when I wrote it, thanks for showing me the right way. I wrote a lot of batch files back when that's all I had available to automate things but my skills are a bit out of date compared to what you can do now. Actually now I typically use powershell far more than batch files but for BeyondTV my only option was a batch file or a batch file that started powershell and the idea of running a batch file to start powershell to start a vb script to start an exe felt a bit too dirty to me.

Thanks for the tips. Here's my current version, I'll incorporate other mods when I get a chance.

@echo off
SETLOCAL ENABLEEXTENSIONS

rem Script to QuickstreamFix file passed in first arg. For use with BeyondTV's archive feature.

set HERE=%~dp0.
set script="%HERE%\vp.vbs"
if not exist %script% set script="C:\Program Files (x86)\VideoReDoTVSuite\vp.vbs"
if not exist %script% set script="C:\Program Files\VideoReDoTVSuite\vp.vbs"

if not exist %script% GOTO NoScript

set file=%1

for %%i in (%file%) do set ext=%%~xi
if "%ext%" == ".wmv" GOTO Unsupported
if "%ext%" == ".mp4" GOTO Unsupported
if "%ext%" == ".avi" GOTO Unsupported
if "%ext%" == ".tp" set ext=".ts"

for %%i in (%file%) do if exist "%%~dpi%%~ni.q%%~xi" GOTO Duplicate

for %%i in (%file%) do if not exist "%%~dpi%%~ni.q%%~xi" @echo QuickStream Fix "%%~dpi%%~ni%%~xi" to "%%~dpi%%~ni.q%ext%"
for %%i in (%file%) do if not exist "%%~dpi%%~ni.q%%~xi" cscript //nologo %script% "%%~dpi%%~ni%%~xi" "%%~dpi%%~ni.q%ext%" /t1

for %%i in (%file%) do if exist "%%~dpi%%~ni%%~xi.chapters.xml" @echo Copying SmartSkip file to "%%~dpi%%~ni.q%%~xi.chapters.xml"
for %%i in (%file%) do if exist "%%~dpi%%~ni%%~xi.chapters.xml" copy /Y "%%~dpi%%~ni%%~xi.chapters.xml" "%%~dpi%%~ni.q%ext%.chapters.xml"

GOTO TheEnd

:Duplicate
@echo Target file already exists
GOTO TheEnd

:Unsupported
@echo Unsupported file type
GOTO TheEnd

:NoScript
@echo Can't find script file at %script%
GOTO TheEnd

:TheEnd
Pause
Exit
 

NodNarb012

New member
I think your .tp/.ts conversions aren't working properly because you're using the "/t1" argument with the vp.vbs file to specify the output as a program stream. Try changing that to "/t4" to output as a transport stream; simply changing the file extension isn't enough.

I would setup your batch file to convert everything to .ts. That way you don't have to worry about using the /t1 argument for some files and /t4 for others.
 

stevehiner

New member
Oh, thanks for letting me know about /t4. I guess I didn't notice that when I was reviewing the documentation. I falsely assumed that VRD would choose the right format for the output based on the file extension. The UI seems to handle it that way.

Considering that most of the files I'll process with this batch file are standard-def MPEG files I don't think I'd want to default to /t4 all the time, would I? I've never been clear on the difference between program stream and transport stream but I thought it was only relevant with high-def files.
 

stevehiner

New member
I had the args incorrect. This is my final version of a working script for mpg and tp files.

Code:
@echo off

rem Script to QuickstreamFix file passed in first arg. For use with BeyondTV's archive feature.

set HERE=%~dp0.
set script="%HERE%\vp.vbs"
if not exist %script% set script="C:\Program Files (x86)\VideoReDoTVSuite\vp.vbs"
if not exist %script% set script="C:\Program Files\VideoReDoTVSuite\vp.vbs"

if not exist %script% GOTO NoScript

set ext=%~x1
if "%ext%" == ".wmv" GOTO Unsupported
if "%ext%" == ".mp4" GOTO Unsupported
if "%ext%" == ".avi" GOTO Unsupported
if "%ext%" == ".tp" set ext=.ts

set arg=/t1
if "%ext%" == ".ts" set arg=/t4 /d

if exist "%%~dp1%%~n1.q%%~x1" GOTO Duplicate

if not exist "%~dp1%~n1.q%ext%" @echo QuickStream Fix "%~dp1%~n1%~x1" to "%~dp1%~n1.q%ext%" %arg%
if not exist "%~dp1%~n1.q%ext%" cscript //nologo %script% "%~dp1%~n1%~x1" "%~dp1%~n1.q%ext%" %arg%

if exist "%~dp1%~n1%~x1.chapters.xml" @echo Copying SmartSkip file to "%~dp1%~n1.q%ext%.chapters.xml"
if exist "%~dp1%~n1%~x1.chapters.xml" copy /Y "%~dp1%~n1%~x1.chapters.xml" "%~dp1%~n1.q%ext%.chapters.xml"

GOTO TheEnd

:Duplicate
@echo Target file already exists
GOTO TheEnd

:Unsupported
@echo Unsupported file type
GOTO TheEnd

:NoScript
@echo Can't find script file at %script%
GOTO TheEnd

:TheEnd
Pause
Exit
While researching the problem I found this: http://forums.snapstream.com/vb/archive/index.php/t-38840.html
It's a post about how to automate quickstream fix, commercial detection and cutting using VideoReDo and batch files. It's a bit of an old post but everything in it should still work, I think.
 
Top Bottom