Comskip Support Forum

Comskip is a free commercial detector, browse the forum for more information
It is currently Sun Apr 21, 2019 7:06 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Sat May 06, 2006 11:41 am 
Offline

Joined: Mon Jan 23, 2006 4:02 pm
Posts: 8
[Update 4 - July 18 2006:
Thanks to Charlie for info on the Panasonic DMR-EH50. New line in Section 3 for recorders that show
the correct number of programs in vstrip.
Added a log file for program output and error data.

[Update 3 - June 14 2006:
Thanks to mimwdv for his suggestions. The improvements are as follows:
1) Autodetection of ntsc and pal
2) Allow for a custom menu background
3) Fixed bug found by mimwdv
4) Main menu text is now anti-aliased
5) Better support for AC3 recordings
6) Uses a dummy button so that no menu selection is highlighted by default (this follows from number 4 above).

[Update 2 - June 1 2006 12:47: IMPORTANT NOTE:
When copying and pasting the text below, watch out for trailing spaces at the ends of the lines. The trailing spaces will break the batch file.]

[Update 1- May 6 2006 10:23: Correct font usage]

Hello everyone,

I don't know if anyone is interested, but I created a batch file for a friend with a standalone DVD recorder. He records one or more programs onto DVD rewritables and then runs this batch file to create a new DVD (with crude menus and chapter cuts) with the commercials removed by Comskip and Cuttermaran. Instructions for making any changes are in the comments of the file. Here it is:

Code:
@ECHO OFF

::USER INSTRUCTIONS

::This Batch File is designed to take a DVD home recording from a standalone home recorder
::with one or more recordings on it, remove the commercials from it and record it onto a new DVD with menus.

::PLEASE NOTE - MAY NOT BE COMPATIBLE WITH AC3 SOUND RECORDINGS

::Requirements:
::    OS:
::       Windows XP
::    Programs:
::       Comskip
::       DVDDecrypter
::       Cuttermaran
::       ImageMagick
::       DVDAuthor
::       MKISOFS
::       vStrip

::The programs are all available from http://www.videohelp.com

::The batch file is divided into sections.  There are two sections where the user may need to make
::some changes.  The first is the Declaratations section.  In that section you will see a number of
::programs that need to be installed.  Do a Google search or search on Videohelp.com to find them.
::Change the declarations section if your programs are in a different location.  As well, you need to
::change the location on the hard drive that the movies will be processed on and your DVD drive.

::The second section to be modified is Section 3.  This section has been written for use in Cyberhome 1600 DVD home
::recorders.  This unit records X programs under VTS01 and shows 2(X+1) PGC entries under VTS01.  Your
::unit may be different.  If you have trouble getting the correct number of programs with this batch
::file, run the following command at a command prompt:

::"C:\program files\vstrip\vstrip.exe Z:\video_ts\vts_01_1.vob -iZ:\video_ts\vts_01_0.ifo -w1 > vstrip_out.txt

::(Replace Z: with your dvd drive in the command and the correct location of vstrip.)
::Send a PM to "peliopoulos" at the comskip forum (http://mk.kaashoek.com/comskip/index.php) with the following
::information:

::A) Your make and model of DVD recorder
::B) The information in vstrip_out.txt
::C) The number of programs that were recorded on the DVD.

::I will try to customize the results to match your standalone recorder.

::----------
::Update July 18 2006  An optional line has been included for other recorders that show the correct number of shows.
::Please see section 3 for details.
::----------

::Optionally, you can also make changes to the look of the menu and the buttons on it.  However, that will
::be left as an exercise for the reader.  You can start with changing the declarations for font color, background color etc.

::Finally, run Cuttermaran once with an mpg file, make some cuts, go to Edit; Cut Audio/Video and change the
::folders under the Common and Muxing tabs to the same folder as the WORKINGDIR variable below.




::---------------------
::Start Declarations Section
::Set locations of local files and initialize variables
::---------------------

setlocal
set WORKINGDIR="X:\Recording\"
set DVDDRIVE=Z:
::Change this block to the desired drives and folders.

set DVDDECRYPTER="C:\Program Files\DVD Decrypter\DVDDecrypter.exe"
set COMSKIP="C:\Program Files\Comskip\Comskip.exe"
set CUTTERMARAN="C:\Program Files\Cuttermaran\Cuttermaran.exe"
set DVDAUTHORDIR="C:\Program Files\dvdauthor"
set MKISOFS="C:\Program Files\mkisofs\mkisofs.exe"
set VSTRIP="C:\Program Files\vStrip\vStrip.exe"
set IMAGEMAGICKDIR="C:\Program Files\ImageMagick"
set FONTDIR="C:\Windows\Fonts"
set MENUBACKGROUND="C:\Pictures\DVD Menu Background.jpg"
set LOGFILE="\dvdcomskip.log"
::Change this block as required; keep all quotation marks

set MPLEX="%DVDAUTHORDIR:~1,-1%\mplex.exe"
set DVDAUTHOR="%DVDAUTHORDIR:~1,-1%\dvdauthor.exe"
set JPEG2YUV="%DVDAUTHORDIR:~1,-1%\jpeg2yuv.exe"
set PNG2YUV="%DVDAUTHORDIR:~1,-1%\png2yuv.exe"
set MPEG2ENC="%DVDAUTHORDIR:~1,-1%\mpeg2enc.exe"
set SPUMUX="%DVDAUTHORDIR:~1,-1%\spumux.exe"
set CONVERT="%IMAGEMAGICKDIR:~1,-1%\convert.exe"
set MONTAGE="%IMAGEMAGICKDIR:~1,-1%\montage.exe"
set COMPOSITE="%IMAGEMAGICKDIR:~1,-1%\composite.exe"
::Do not change this block unless you really know what you are doing

set MAINFONTCOLOR=PaleTurquoise1
set ACTIONFONTCOLOR=green1
set HIGHLIGHTFONTCOLOR=blue
set BACKGROUNDCOLOR=gray11
set FONT=Arial.ttf
set FONT=%FONTDIR:~1,-1%\%FONT%
::Text and background colors for DVD menus
::List of Colors is available in %imagemagick%/config/colors.xml or use hex values in the form:  #FF0000
::Get the name of the font from the TTF file in the font path

set BUTTONHEIGHT=40
set BUTTONBUFFER=10
set /A BUTTONBUFFER_HALF=%BUTTONBUFFER%/2
::Default values for button height and the distance between buttons measured in pixels
::Don't set the button buffer too low or you will lose the menu links

set VIDEOFORMAT=
::Change to "VIDEOFORMAT=ntsc" or "VIDEOFORMAT=pal" otherwise vstrip will detect automatically

set MAXMENUWIDTH=580
::Do not change these values; they ensure that your DVD menu is viewable on your TV screen

set AUDIO=PCM
::Change to AC3 if required
IF %AUDIO% EQU PCM (SET AUDIOFORMAT=MPEG1 & SET AUDIOEXTENSION=mp2) ELSE (SET AUDIOFORMAT=AC3 & SET AUDIOEXTENSION=ac3)

set FRAMERATE=
set SCREENHEIGHT=
set PGCNUMBER=
set NUMPROGS=
set LABEL=
set DVDLABEL=
set SHOWNAME=
set NUMCOLS=
set NUMROWS=
set BUTTONWIDTH=
set MENU_YPOSITION_TOP=

DATE /T >%LOGFILE%
TIME /T >>%LOGFILE

::---------------------
::End Declarations Section
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 1
::Check to see if Comskip is set to output Cuttermaran files
::---------------------
ECHO Section 1 1>>%LOGFILE%

FINDSTR "output_cuttermaran=1" %Comskip:~0,-4%ini" 1>>%LOGFILE%  2>>%LOGFILE%
IF %ERRORLEVEL% EQU 0 GOTO :COMSKIPCHECKPASS

:COMSKIPCHECKFAIL
ECHO Comskip is not configured to output Cuttermaran files.
ECHO Please change the line "output_cuttermaran=0" to "output_cuttermaran=1"
ECHO in %Comskip:~0,-4%ini"
GOTO :EOF

:COMSKIPCHECKPASS

::---------------------
::End Section 1
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 2
::Create Working Directory and make it the active directory
::---------------------
ECHO Section 2 >> %LOGFILE%


IF NOT EXIST %WORKINGDIR% mkdir %WORKINGDIR% 1>>%LOGFILE%  2>>%LOGFILE%
cd /d %WORKINGDIR% 1>>%LOGFILE%  2>>%LOGFILE%
:: Change working directory to WORKINGDIR

::---------------------
::End Section 2
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 3
::Use vstrip to (a) detect NTSC or PAL and (b) get the number of recorded programs on DVD
::---------------------
ECHO Section 3 >> %LOGFILE%

:: The algorithm below is set up for use with the Cyberhome 1600 DVD Recorder.
:: Other recorders may use different formats.

%VSTRIP% %DVDDRIVE%\video_ts\vts_01_1.vob -i%DVDDRIVE%\video_ts\vts_01_0.ifo -w1 > vstrip_out.txt
:: Output vstrip information to vstrip_out.txt

IF DEFINED VIDEOFORMAT GOTO :CONTINUE
FIND "NTSC" vstrip_out.txt 1>>%LOGFILE% 2>>%LOGFILE%
IF ERRORLEVEL 0 (SET VIDEOFORMAT=ntsc) ELSE (SET VIDEOFORMAT=pal)
:CONTINUE

IF %VIDEOFORMAT% EQU ntsc (set FRAMERATE=29.97 & set SCREENHEIGHT=480) ELSE (set FRAMERATE=25.00 & set SCREENHEIGHT=576)
set /A MAXMENUHEIGHT=%SCREENHEIGHT%-110
::Check for NTSC or PAL


FOR /F "tokens=6 delims= " %%A IN ('findstr  %AUDIOFORMAT% vstrip_out.txt') DO ECHO %%A > audio_streams.txt
:: Search for line that contains the number of audio streams and output that line to audio_streams.txt
:: For the Cyberhome 1600 the line contains the following field
:: [0,1,2,3,4,5,6,7,8,9]
:: when there are four programs.
:: Other recorders (e.g. the Panasonic DMR-EH50) show the proper number of programs, e.g.
:: [0,1,2,3]
:: when there are four programs.



FOR /L %%G in (100,-1,2) DO  CMD /C FOR /F "tokens=%%G delims=," %%H in (audio_streams.txt) DO @ECHO %%H >> separated_streamnums.txt
:: Treat the commas in the field as field separators, start at 100 and work downwards and start separating the fields into individual lines
:: e.g. the field [0,1,2,3,4,5,6,7,8,9]
:: will be output as:
::    9]
::    8
::    7
:: etc.
:: in the separated_streamnums.txt file

FOR /F "tokens=1 delims=]" %%H in ('findstr "]" separated_streamnums.txt') DO SET /A NUMPROGS=(%%H-1)/2
:: Find the line in the separated_streamnums.txt file that has the "]" character and extract the number from it.
:: Then calculate the number of programs from it.
:: From the example above, the line "9]" in the separated_streamnums.txt file is found, the number "9" extracted,
:: and the number of programs calculated is 4.

::If your recorder shows the correct number of programs (e.g. the Panasonic DMR-EH50) just remove two colons in front of the following line
::FOR /F "tokens=1 delims=]" %%H in ('findstr "]" separated_streamnums.txt') DO SET /A NUMPROGS=%%H+1


ECHO.
ECHO.
ECHO The number of programs detected on this DVD is %NUMPROGS%

::---------------------
::End Section 3
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 4
::Get DVD label from User
::---------------------
ECHO Section 4 >> %LOGFILE%

ECHO.
ECHO.
ECHO Type a name for your new DVD (maximum 32 characters, no " marks)

SET /P DVDLABEL=and press ENTER ^>
:: Get user input for DVD Label
IF "%DVDLABEL%"==""  SET DVDLABEL=Recorded DVD
ECHO.
ECHO.
ECHO The new DVD will use the label "%DVDLABEL%"

::---------------------
::End Section 4
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 5
::Rip Programs
::---------------------
ECHO Section 5 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Ripping recorded DVD using DVDDecrypter

::************
SET PGCNUMBER=1
:LOOPDECRYPT

%DVDDECRYPTER% /MODE IFO /SRC "%DVDDRIVE%" /DEST %WORKINGDIR% /VTS 1 /PGC %PGCNUMBER% /DEMUX 0xE0 0xC0 /START /CLOSE /OVERWRITE YES /SPLIT NONE
:: Use DVDDecrypter to rip recorded DVD to separate files

for %%A in (VTS*.M2V) DO RENAME "%%A" temp%PGCNUMBER%.m2v 1>>%LOGFILE%  2>>%LOGFILE%
for %%B in (VTS*.MP2) DO RENAME "%%B" temp%PGCNUMBER%.%AUDIOEXTENSION% 1>>%LOGFILE%  2>>%LOGFILE%
del VTS*.* /F /Q  1>>%LOGFILE%  2>>%LOGFILE%
:: Rename the ripped files tempX.m2v and tempX.mp2 (or tempX.ac3)

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPDECRYPT
::************

::---------------------
::End Section 5
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 6
::Combine m2v and mp2 (or ac3) files to create an mpg file for use by Comskip
::---------------------
ECHO Section 6 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Combining ripped files for use in Comskip

::************
SET PGCNUMBER=1
:LOOPMUX1

%MPLEX% -f 8 -M -v 0 -o temp%PGCNUMBER%.mpg temp%PGCNUMBER%.m2v temp%PGCNUMBER%.%AUDIOEXTENSION% 1>>%LOGFILE%  2>>%LOGFILE%
:: Combine tempX.m2v and tempX.mp2 (or tempX.ac3) into a single file:  tempX.mpg

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPMUX1
::************

::---------------------
::End Section 6
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 7
::Run Comskip on tempX.mpg
::---------------------
ECHO Section 7 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Detecting commercials using Comskip

::************
SET PGCNUMBER=1
:LOOPCOMSKIP

%COMSKIP% -v 0 "temp%PGCNUMBER%.mpg" 1>>%LOGFILE% 2>>%LOGFILE%
:: Run ComSkip on tempX.mpg

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPCOMSKIP
::************

del *.mpg /F /Q 1>>%LOGFILE%

::---------------------
::End Section 7
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 8
::Run Cuttermaran and to automatically cut commercials detected by Comskip
::---------------------
ECHO Section 8 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Cutting detected commercials using Cuttermaran

::************
SET PGCNUMBER=1
:LOOPCUTTERMARAN1

%CUTTERMARAN% "temp%PGCNUMBER%.cpf"
:: Run Cuttermaran to cut the commercials identified by ComSkip

if exist temp%PGCNUMBER%_clean ren temp%PGCNUMBER%_clean temp%PGCNUMBER%_clean.m2v 1>>%LOGFILE% 2>>%LOGFILE%
::Comskip's cpf does not have .m2v extension for Cuttermaran version 1.67

del temp%PGCNUMBER%.m2v /F /Q 1>>%LOGFILE%  2>>%LOGFILE%
del temp%PGCNUMBER%.%AUDIOEXTENSION% /F /Q 1>>%LOGFILE%  2>>%LOGFILE%

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPCUTTERMARAN1
::************


::---------------------
::End Section 8
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 9
::Run Cuttermaran to allow for additional cuts
::---------------------
ECHO Section 9 >> %LOGFILE%

ECHO *
ECHO *
ECHO *
ECHO ***********************************************************************
ECHO * Cuttermaran will now start so you can make additional edits.        *
ECHO * Please save the file using the default name in the %WORKINGDIR%     *
ECHO * If you don't want to make additional edits, simply exit the program.*
ECHO ***********************************************************************
ECHO *
ECHO *

PAUSE

::************
SET PGCNUMBER=1
:LOOPCUTTERMARAN2

ECHO ^<?xml version="1.0" standalone="yes"?^> > movie%PGCNUMBER%.cpf
ECHO ^<StateData xmlns="http://cuttermaran.kickme.to/StateData.xsd"^> >> movie%PGCNUMBER%.cpf
ECHO ^<usedVideoFiles FileID="0" FileName="temp%PGCNUMBER%_clean.m2v" /^> >> movie%PGCNUMBER%.cpf
ECHO ^<usedAudioFiles FileID="1" FileName="temp%PGCNUMBER%_clean.%AUDIOEXTENSION%" StartDelay="0" /^> >> movie%PGCNUMBER%.cpf
ECHO ^<CurrentFiles refVideoFiles="0"^> >> movie%PGCNUMBER%.cpf
ECHO ^<currentAudioFiles refAudioFiles="1" /^> >> movie%PGCNUMBER%.cpf
ECHO ^</CurrentFiles^> >> movie%PGCNUMBER%.cpf
ECHO ^<CmdArgs OutFile="temp%PGCNUMBER%_clean.m2v" cut="false" unattended="false" muxResult="true" snapToCutPoints="true" closeApp="false" /^> >> movie%PGCNUMBER%.cpf
ECHO ^</StateData^> >> movie%PGCNUMBER%.cpf
:: Create cpf file for Cuttermaran


%CUTTERMARAN% "movie%PGCNUMBER%.cpf"
:: Run Cuttermaran to make new edits to the video

ECHO.
ECHO.
ECHO.



::Create Show Names
ECHO Please type a name for this program (maximum 64 characters, no " marks)
SET /P SHOWNAME=and press ENTER ^>
ECHO %SHOWNAME%> SHOWNAME%PGCNUMBER%.txt
FOR /F  "delims=`" %%T IN (SHOWNAME%PGCNUMBER%.txt) DO SET NAMEPROG%PGCNUMBER%=%%T
IF "%SHOWNAME%"=="" SET NAMEPROG%PGCNUMBER%=Program %PGCNUMBER%#



::Get user input for name of show
ECHO.
ECHO.
IF "%SHOWNAME%"=="" (ECHO Show number %PGCNUMBER% will be labelled "Program %PGCNUMBER%") ELSE (ECHO Show number %PGCNUMBER% will be labelled "%SHOWNAME:~0,-1%")
ECHO.
ECHO.
SET SHOWNAME=

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPCUTTERMARAN2
::************

::---------------------
::End Section 9
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 10
::Run mplex to combine initial Cuttermaran output files if no changes were made.
::---------------------
ECHO Section 10 >> %LOGFILE%

::************
SET PGCNUMBER=1
:LOOPMUX2

IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO.
IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO.
IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO.
IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO.
IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO.
IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO No additional edits for Program %PGCNUMBER% selected
IF NOT EXIST movie%PGCNUMBER%_cut.mpg ECHO Muxing Program %PGCNUMBER% from initial cuts
IF NOT EXIST movie%PGCNUMBER%_cut.mpg %MPLEX% -f 8 -M -v 0 -o movie%PGCNUMBER%_cut.mpg temp%PGCNUMBER%_clean.m2v temp%PGCNUMBER%_clean.%AUDIOEXTENSION% 1>>%LOGFILE% 2>>%LOGFILE%
:: If no cuts were made using Cuttermaran, use tempX_clean files to make movieX_cut.mpg

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPMUX2
::************

del *.%AUDIOEXTENSION% /F /Q  1>>%LOGFILE%  2>>%LOGFILE%
del *.m2v /F /Q  1>>%LOGFILE%  2>>%LOGFILE%

::---------------------
::End Section 10
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 11
::Create images and menus for DVD
::---------------------
ECHO Section 11 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Creating DVD structure

:: Create transparent background for Main Menu
%CONVERT% -size 720x%SCREENHEIGHT% xc:transparent menubackground.png

:: Calculate the maximum number of rows of buttons based on row height and buffer distance
SET /A MAXROWS=(%MAXMENUHEIGHT%+%BUTTONBUFFER%)/(%BUTTONHEIGHT%+%BUTTONBUFFER%)

:: Calculate the Number of Columns
SET /A NUMCOLS=%NUMPROGS%/%MAXROWS%
SET /A TEMP1=%MAXROWS%*%NUMCOLS%
IF %NUMPROGS% GTR %TEMP1% SET /A NUMCOLS=%NUMCOLS%+1

:: Calculate the number of rows
SET /A NUMROWS=%NUMPROGS%/%NUMCOLS%
SET /A TEMP2=%NUMCOLS%*%NUMROWS%
IF %NUMPROGS% GTR %TEMP2% SET /A NUMROWS=%NUMROWS%+1

:: Calculate the button width
SET /A BUTTONWIDTH=(%MAXMENUWIDTH%+%BUTTONBUFFER%-%BUTTONBUFFER%*%NUMCOLS%)/%NUMCOLS%

::************
::Create Buttons
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATEBUTTONS %%n)
GOTO :CONTINUE1

:LOOPCREATEBUTTONS
SET LABEL=NAMEPROG%1
CALL SET LABEL=%%%LABEL%%%
SET LABEL=%LABEL:~0,-1%

IF %1 LSS 10 (SET TEXTPROGNUM=0%1) ELSE (SET TEXTPROGNUM=%1)

%CONVERT% -size %BUTTONWIDTH%x%BUTTONHEIGHT% -gravity center -background transparent -fill %MAINFONTCOLOR%  -antialias -font "%FONT%" label:"%LABEL%" mainbutton%TEXTPROGNUM%.png
%CONVERT% -size %BUTTONWIDTH%x%BUTTONHEIGHT% -gravity center -background transparent -fill %ACTIONFONTCOLOR% +antialias -font "%FONT%" label:"%LABEL%" actionbutton%TEXTPROGNUM%.png
%CONVERT% -size %BUTTONWIDTH%x%BUTTONHEIGHT% -gravity center -background transparent -fill %HIGHLIGHTFONTCOLOR% +antialias -font "%FONT%" label:"%LABEL%" highlightbutton%TEXTPROGNUM%.png
GOTO :EOF

:CONTINUE1
::************

::Create Menu Images
IF %NUMPROGS% LSS 10 (SET TEXTNUMPROGS=0%NUMPROGS%) ELSE (SET TEXTNUMPROGS=%NUMPROGS%)

%MONTAGE% mainbutton*.png  -tile 1x%NUMROWS% -background transparent  -geometry +%BUTTONBUFFER_HALF%+%BUTTONBUFFER_HALF%  maintemp.png
%MONTAGE% maintemp*.png  -tile x1 -background transparent  -geometry +0+0 main_temp.png
%CONVERT% main_temp.png -size 720x%SCREENHEIGHT% xc:transparent +swap -gravity center -composite MainMenu1.png
if exist %MENUBACKGROUND% (%CONVERT% %MENUBACKGROUND% -resize 720x%SCREENHEIGHT%! menubackground_pic.png) ELSE (%CONVERT% -size 720x%SCREENHEIGHT% xc:%BACKGROUNDCOLOR% menubackground_pic.png)
::Inserts background picture or plain color
%COMPOSITE% MainMenu1.png menubackground_pic.png MainMenu.png

%MONTAGE% actionbutton*.png  -tile 1x%NUMROWS% -background transparent  -geometry +%BUTTONBUFFER_HALF%+%BUTTONBUFFER_HALF%  actiontemp.png
%MONTAGE% actiontemp*.png -tile x1 -background transparent  -geometry +0+0 action_temp.png
%CONVERT% action_temp.png -size 720x%SCREENHEIGHT% xc:transparent +swap -gravity center -composite ActionMenu.png

%MONTAGE% highlightbutton*.png  -tile 1x%NUMROWS% -background transparent  -geometry +%BUTTONBUFFER_HALF%+%BUTTONBUFFER_HALF%  highlighttemp.png
%MONTAGE% highlighttemp*.png  -tile x1 -background transparent  -geometry +0+0 highlight_temp.png
%CONVERT% highlight_temp.png -size 720x%SCREENHEIGHT% xc:transparent +swap -gravity center -composite HighlightMenu.png

::Create MainMenuSpu.xml file for use in menu
ECHO ^<subpictures^> >MainMenuSpu.xml
ECHO   ^<stream^> >>MainMenuSpu.xml
ECHO     ^<spu start="00:00:00.0" >>MainMenuSpu.xml
ECHO          highlight="HighlightMenu.png" >>MainMenuSpu.xml
ECHO          select="ActionMenu.png" >>MainMenuSpu.xml
ECHO          force="yes" >>MainMenuSpu.xml
ECHO          autoorder="rows"^> >>MainMenuSpu.xml
ECHO     ^<button name="DUMMYBUTTON" x0="1" y0="1" x1="2" y1="2"/^> >>MainMenuSpu.xml
::Need dummy button so that first menu item is not highlighted by default
::The highlight and action fonts are not antialiased, while the menu font is antialiased.
::When the menu items are highlighted the antialias-ing of the menu font appears around
::the highlighted font and can look awful. This way the menu looks nicer on first loading
::with the antialiased font.

::************
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATESPUMUXFILE %%n %BUTTONWIDTH% %NUMROWS% %NUMCOLS%)
GOTO :CONTINUE2

:LOOPCREATESPUMUXFILE
SET PROGRAMNUM=%1
SET BUTTONWIDTH=%2
SET NUMROWS=%3
SET NUMCOLS=%4

SET /A MENU_YPOSITION_TOP=(%SCREENHEIGHT%-(%NUMROWS%*(%BUTTONHEIGHT%+%BUTTONBUFFER%)))/2

SET /A COLUMNNUM=%PROGRAMNUM%/%NUMROWS%
SET /A TEMP3=%COLUMNNUM%*%NUMROWS%
IF %PROGRAMNUM% GTR %TEMP3% SET /A COLUMNNUM=%COLUMNNUM%+1
SET /A ROWNUM=%PROGRAMNUM%-(%NUMROWS%*(%COLUMNNUM%-1))

SET LABEL=NAMEPROG%1
CALL SET LABEL=%%%LABEL%%%
SET LABEL=%LABEL:~0,-1%
SET /A BUTTON_YPOSITION_TOP=%MENU_YPOSITION_TOP%+%BUTTONBUFFER%/2+(%ROWNUM%-1)*(%BUTTONHEIGHT%+%BUTTONBUFFER%)
SET /A BUTTON_YPOSITION_BOTTOM=%BUTTON_YPOSITION_TOP%+%BUTTONHEIGHT%
SET /A BUTTON_XPOSITION_LEFT=(720-%MAXMENUWIDTH%)/2+%BUTTONBUFFER%/2+(%COLUMNNUM%-1)*(%BUTTONWIDTH%+%BUTTONBUFFER%)
SET /A BUTTON_XPOSITION_RIGHT=BUTTON_XPOSITION_LEFT+%BUTTONWIDTH%

ECHO ^<button name="%LABEL%" x0="%BUTTON_XPOSITION_LEFT%" y0="%BUTTON_YPOSITION_TOP%" x1="%BUTTON_XPOSITION_RIGHT%" y1="%BUTTON_YPOSITION_BOTTOM%"/^> >>MainMenuSpu.xml


GOTO :EOF

:CONTINUE2
::************
ECHO     ^</spu^> >>MainMenuSpu.xml
ECHO   ^</stream^> >>MainMenuSpu.xml
ECHO ^</subpictures^> >>MainMenuSpu.xml

::Create MPEG movies for menus
%PNG2YUV% -n 1 -I p -L 0 -f %FRAMERATE% -j "menubackground.png" 2>>%LOGFILE% | %MPEG2ENC% -f 8 -I 0 -h -q 1 -b 7000 -a 2 -n n -o "MenuBackground.m2v" 1>>%LOGFILE% 2>>%LOGFILE%
%MPLEX% -f 8 -o "MenuBackground.mpg" "MenuBackground.m2v" 1>>%LOGFILE% 2>>%LOGFILE%

%PNG2YUV% -n 1 -I p -L 0 -f %FRAMERATE% -j "MainMenu.png" 2>NUL | %MPEG2ENC% -f 8 -I 0 -h -q 1 -b 7000 -a 2 -n n -o "MainMenuBackground.m2v" 1>>%LOGFILE% 2>>%LOGFILE%
%MPLEX% -f 8 -o "MainMenuBackground.mpg" "MainMenuBackground.m2v" 1>>%LOGFILE% 2>>%LOGFILE%

::Merge Files using spumux
%SPUMUX% "MainMenuSpu.xml" <"MainMenuBackground.mpg" > "MainMenu.mpg" 2>>%LOGFILE%

::Delete temporary PNG files
del *.png /F /Q  1>>%LOGFILE%  2>>%LOGFILE%

::Create dvdauthor xml file
ECHO ^<?xml version="1.0" encoding="utf-8"?^> > dvd.xml
ECHO ^<dvdauthor dest="%WORKINGDIR:~1,-1%DVD"^> >> dvd.xml
ECHO ^<vmgm^> >> dvd.xml
ECHO     ^<menus^> >> dvd.xml
ECHO     ^<video format="%VIDEOFORMAT%"^>^</video^> >> dvd.xml
ECHO       ^<pgc^> >> dvd.xml
ECHO       ^<pre^> { {button = 1024;} }  ^</pre^> >> dvd.xml
ECHO       ^<vob file="MainMenu.mpg" pause="inf"/^> >> dvd.xml
ECHO       ^<button name="DUMMYBUTTON"^>g1=1;jump title 1;^</button^> >> dvd.xml

::************
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATEDVDAUTHORFILE %%n)
GOTO :CONTINUE3

:LOOPCREATEDVDAUTHORFILE
SET LABEL=NAMEPROG%1
CALL SET LABEL=%%%LABEL%%%
SET LABEL=%LABEL:~0,-1%
SET /A G1VALUE=%1+1
ECHO         ^<button name="%LABEL%"^>g1=%G1VALUE%;jump title %1;^</button^> >> dvd.xml
GOTO :EOF

:CONTINUE3
::************
ECHO       ^</pgc^> >> dvd.xml
ECHO     ^</menus^> >> dvd.xml
ECHO ^</vmgm^> >> dvd.xml
ECHO ^<titleset^> >> dvd.xml
ECHO     ^<menus^> >> dvd.xml
ECHO     ^<video format="ntsc"^>^</video^> >> dvd.xml
ECHO       ^<pgc^> >> dvd.xml
ECHO         ^<vob file="MenuBackground.mpg" /^> >> dvd.xml
ECHO         ^<post^>jump vmgm menu 1;^</post^> >> dvd.xml
ECHO       ^</pgc^> >> dvd.xml
ECHO     ^</menus^> >> dvd.xml
ECHO     ^<titles^> >> dvd.xml
::************
SET PGCNUMBER=1
:LOOPXML2
ECHO      ^<pgc^> >> dvd.xml
ECHO         ^<vob file="movie%PGCNUMBER%_cut.mpg" chapters= "00:00:00,00:10:00,00:20:00,00:30:00,00:40:00,00:50:00,01:00:00,01:10:00,01:20:00,01:30:00,01:40:00,01:50:00,02:00:00,02:10:00,02:20:00,02:30:00,02:40:00,02:50:00,03:00:00"/^> >> dvd.xml
ECHO         ^<post^>call vmgm menu 1;^</post^> >> dvd.xml
ECHO       ^</pgc^> >> dvd.xml

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPXML2
::************
ECHO     ^</titles^> >> dvd.xml
ECHO   ^</titleset^> >> dvd.xml
ECHO ^</dvdauthor^> >> dvd.xml



::---------------------
::End Section 11
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 12
::Create DVD File structure using DVDAuthor
::---------------------
ECHO Section 12 >> %LOGFILE%

:: Convert movies into DVD format on the hard drive
%DVDAUTHOR% -x dvd.xml 1>>%LOGFILE% 2>>%LOGFILE%

::---------------------
::End Section 12
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 13
::Create ISO file from DVD File structure
::---------------------
ECHO Section 13 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Creating ISO file

%MKISOFS% -dvd-video -V "%DVDLABEL%" -o movie.iso ./dvd 1>>%LOGFILE% 2>>%LOGFILE%
:: Create an ISO image file from the DVD format created above

::---------------------
::End Section 13
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 14
::Burn DVD using DVDDecrypter
::---------------------
ECHO Section 14 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO Burning edited DVD


ECHO *
ECHO *
ECHO *
ECHO ***************************************************************
ECHO * Please Insert A New Blank Recordable DVD Now                *
ECHO ***************************************************************
ECHO *
ECHO *
ECHO *
PAUSE

%DVDDECRYPTER% /MODE ISOWRITE /SRC "MOVIE.ISO" /DEST "%DVDDRIVE%" /OVERWRITE YES /START /CLOSE
:: Burn Disc using ISO file

::---------------------
::End Section 14
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 15
::Remove files created in this process
::---------------------
ECHO Section 15 >> %LOGFILE%

::This is an optional step.  To allow deletion of temporary files, simply delete the "::" marks

::del %WORKINGDIR%\*.* /F /Q /S 1>>%LOGFILE%  2>>%LOGFILE%
::rmdir %WORKINGDIR%\dvd /F /Q 1>>%LOGFILE%  2>>%LOGFILE%

::---------------------
::End Section 15
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::---------------------
::Start Section 16
::Advise User that process is complete
::---------------------
ECHO Section 16 >> %LOGFILE%

ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO The new edited DVD has now been burned.  Please remove the DVD from the drive.
ECHO The program will now exit.
ECHO.
ECHO.
ECHO.
ECHO.
PAUSE

::---------------------
::End Section 16
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

endlocal

EXIT



Last edited by peliopoulos on Tue Jul 18, 2006 3:38 pm, edited 4 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun May 14, 2006 9:27 am 
Offline

Joined: Sun May 14, 2006 9:15 am
Posts: 116
Thanks for sharing your amazing script. I don't think I've ever seen a .bat file that long. I learned quite a bit from reading it, especially about manipulating strings. You've inspired me to expand and improve my own scripts.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon May 15, 2006 4:14 pm 
Offline

Joined: Mon Jan 23, 2006 4:02 pm
Posts: 8
Glad you liked it. It actually started very small and then grew significantly. I'm no batch file expert so I used this site:

http://www.robvanderwoude.com/index.html

a lot to look up how to do what I needed.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 16, 2006 5:42 am 
Offline

Joined: Sun May 14, 2006 5:29 am
Posts: 44
Location: Sydney, Australia
Thank you so much for sharing this! I use batch files to automate most of my tv processing, but authoring DVDs this way is new to me. If you don't mind I'd like to borrow some parts of this!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 16, 2006 2:09 pm 
Offline

Joined: Mon Jan 23, 2006 4:02 pm
Posts: 8
Hi mimwdv,

Feel free to use it however you like. That's why I posted it!

There's a lot more to dvdauthor than I put in here. I just used the most basic menu design. I would advise using GUI for DVDAuthor http://www.videohelp.com/~gfd/ to design your menus and work backwards from that.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue May 16, 2006 10:12 pm 
Offline

Joined: Tue May 16, 2006 10:05 pm
Posts: 1
I've compiled your great batch file as an executable.

Available here >

http://www11.rapidupload.com/d.php?file ... path=23429


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed May 31, 2006 4:27 pm 
Offline

Joined: Sun May 14, 2006 5:29 am
Posts: 44
Location: Sydney, Australia
I've taken your fantastic batch file as a basis for the following, which I thought might be useful to others. This version takes a folder of mpg files (and optionally srt subtitle files and/or a menu image) and authors a DVD from them. I'm not making any promises as to its robustness - I'm no programmer!

Code:
::USER INSTRUCTIONS

:: This Batch File is designed to take a folder of mpg files and author a DVD with menus, using the filenames as titles on the menu.
:: Names with a single digit only (ie 1.mpg) are invalid and will cause the script to fail.
:: If your filenames are truncated on your menu, try shrinking the pointsize (fontsize) or changing the font in the declarations section.
:: There is no provision for multi-page menus!


:: If there is a menu.jpg file in the folder, this will be used as an image for your menu.  It will automatically be resized to fit your menu.

:: If there are srt subtitle files present, it will mux the subtitles with the matching files (ie movie.mpg with movie.srt etc) before authoring the DVD.
:: Note the subtitle module is fragile, DOUBLE CHECK that the result is what you expect before you delete files.
:: Original files will be renamed moviesubless.mpg and placed in a \SUBLESS subdirectory in case of need.
:: If the srt file has errors, the muxing process will crash and your resulting mpg will be truncated.   
:: If the muxed file is smaller than the unmuxed file, it will also be placed in the \SUBLESS directory as a warning that there is a problem.
:: You may wish to repair your srt files with subtitle workshop or similar before you run this batch file.

:: The files will be placed on the DVD in alphabetical order, so rename or number them if you wish to have them in a different order.

:: During the process it renames the files to 1.mpg etc, and names them back to their original name at the end. 
:: In case of failure of the script, you might want to have a list of the filenames handy so you can rename them if needed. 
:: The script renameMPGs.bat is created during the process and can be used to rename files back to their original name if needed.

:: This file doesn't create an image or burn to a disk - if you want to script this too look at mkisofs and dvddecrypter or various other tools.

:: To run this script:
:: Alter the declarations section below to your needs and then drop a folder onto the batch file.

:: Requirements:
::    OS:
::       Windows XP

::    Programs:
::       ImageMagick
::       DVDAuthorGUI (the GUI isn't used, but this has all the components)

::The programs are available from http://www.videohelp.com

::The batch file is divided into sections. 

::The only place that changes should need to be made is in the DECLARATIONS section - change anything below that with care as it's easy to break!

::Credit to Peliopoulos from the Comskip support forum at http://mk.kaashoek.com/comskip/index.php on whose work this script has been based.


::---------------------
::Start Declarations Section
::Set locations of local files and initialize variables
::---------------------

setlocal
set SOURCEDIR=%~1
set SOURCEFOLDER=%~n1
set TARGETLOCATION=d:\
set TARGETDIR=%TARGETLOCATION%\%SOURCEFOLDER%
set WORKINGDIR="%SOURCEDIR%"
del "%TARGETLOCATION%%SOURCEFOLDER%\VIDEO_TS\*.*"

set DVDDRIVE="P:"
::Change this block to the desired drives and folders.

set DVDDECRYPTER="C:\Program Files\DVD Decrypter\DVDDecrypter.exe"
set COMSKIP="C:\Program Files\Comskip\Comskip.exe"
set CUTTERMARAN="C:\Program Files\Cuttermaran\Cuttermaran.exe"
set DVDAUTHORDIR="C:\Program Files\DVDAuthorGUI\bin"
set MKISOFS="C:\Program Files\mkisofs\mkisofs.exe"
set VSTRIP="C:\Program Files\vStrip\vStrip.exe"
set IMAGEMAGICKDIR="C:\Program Files\ImageMagick"
set FONTDIR=C:\Windows\Fonts
::Change this block as required

set MPLEX="%DVDAUTHORDIR:~1,-1%\mplex.exe"
set DVDAUTHOR="%DVDAUTHORDIR:~1,-1%\dvdauthor.exe"
set JPEG2YUV="%DVDAUTHORDIR:~1,-1%\jpeg2yuv.exe"
set PNG2YUV="%DVDAUTHORDIR:~1,-1%\png2yuv.exe"
set MPEG2ENC="%DVDAUTHORDIR:~1,-1%\mpeg2enc.exe"
set SPUMUX="%DVDAUTHORDIR:~1,-1%\spumux.exe"
set CONVERT="%IMAGEMAGICKDIR:~1,-1%\convert.exe"
set COMPOSITE="%IMAGEMAGICKDIR:~1,-1%\composite.exe"
set MONTAGE="%IMAGEMAGICKDIR:~1,-1%\montage.exe"
::Do not change this block unless you really know what you are doing

set MAINFONTCOLOR=#C05E06
set ACTIONFONTCOLOR=DarkOrchid
set HIGHLIGHTFONTCOLOR=DarkOrange
set FONT=ARIAL.ttf
set POINTSIZE=32
set BACKGROUNDCOLOR=#EEE7D6

set MENUTITLE=%SOURCEFOLDER:_= %
echo MENUTITLE IS %menutitle%

::Text and background colors for DVD menus
::List of Colors is available in %imagemagick%/config/colors.xml or use hex values in the form:  #FF0000
::Menu Buttons can be extensively re-designed using Imagemagick.
::Get the name of the font from the TTF file in the font path

set SCREENHEIGHT=576
set SCREENWIDTH=720
set SCREENWIDTHHEIGHT=%SCREENWIDTH%x%SCREENHEIGHT%
:: SCreen height and width set for PAL.  For NTSC might need to change these to ensure menu items line up properly

set MAXMENUHEIGHT=480
set MAXMENUWIDTH=580
::These values ensure that your DVD menu us viewable on your TV screen - might need changing for NTSC. 
::Needs to be smaller than screen size to allow for overscan on tv

set /A BUTTONHEIGHT=%POINTSIZE%+6
set BUTTONBUFFER=10
set /A BUTTONBUFFER_HALF=%BUTTONBUFFER%/2
::Default values for button height and the distance between buttons measured in pixels
::Don't set BUTTONBUFFER too small - the menu ends up with no links

echo buttonheight is %buttonheight%

set VIDEOFORMAT=pal
::Change to ntsc if required
IF %VIDEOFORMAT% EQU ntsc SET FRAMERATE=29.97
IF %VIDEOFORMAT% EQU pal SET FRAMERATE=25.00

set PGCNUMBER=
set NUMPROGS=
set LABEL=
set DVDLABEL=
set SHOWNAME=
set NUMCOLS=
set NUMROWS=
set BUTTONWIDTH=
set MENU_YPOSITION_TOP=


::---------------------
::End Declarations Section
::---------------------

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Go to Working Directory (source directory)
::---------------------

cd /d %SOURCEDIR%

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Muxing srt subtitles into mpgs
::---------------------

if not exist *.srt goto :endSubtitles
md f:\docos\just_write\subless
for %%f in (*.srt) do call :s_MuxSubtitles "%%~nf.srt"
for %%f in (*.mpg) do call :s_CheckSubSizes "%%~nf.mpg" "%SOURCEDIR%\subless\%%~nfsubless.mpg"
del subtitles.xml
echo CHECK YOUR SUBTITLE FILES ARE OK

pause
goto :endSubtitles

:s_MuxSubtitles
set NAME=%~n1
if not exist "%NAME%.mpg" goto :eof

echo ^<subpictures^> >subtitles.xml
echo    ^<stream^> >>subtitles.xml
echo       ^<textsub filename="%NAME%.srt" characterset="ISO8859-1" >>subtitles.xml
echo          fontsize="28.0" font="arial.ttf" horizontal-alignment="left" >>subtitles.xml
echo          vertical-alignment="bottom" left-margin="60" right-margin="60"  >>subtitles.xml
echo          top-margin="20" bottom-margin="30" subtitle-fps="25" >>subtitles.xml
echo          movie-fps="25" movie-width="720" movie-height="574" >>subtitles.xml
echo       /^> >>subtitles.xml
echo    ^</stream^> >>subtitles.xml
echo ^</subpictures^> >>subtitles.xml

ren "%name%.mpg" "%name%subless.mpg"

call %SPUMUX% "subtitles.xml" <"%NAME%subless.mpg" > "%NAME%.mpg"
move "%NAME%subless.mpg" "%SOURCEDIR%\subless\%NAME%subless.mpg"
goto :eof

:s_CheckSubSizes
set _size=%~z1
set /a _sizeMB=%_size:~0,-5%
set _sizesubless=%~z2
set /a _sizesublessMB=%_sizesubless:~0,-5%
if %_sizeMB% GTR %_sizesublessMB% goto :eof else move "%NAME%.mpg" "%SOURCEDIR%\subless\%NAME%.mpg"
goto :eof
:endSubtitles

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Get the number of recorded programs
::---------------------
set _NUMPROGS=0
for %%f in (*.mpg) do call :countMPAS %%~nf.mpg
GOTO :ContinueAfterCountMPAS

:countMPAS
set /a _NUMPROGS=1+%_NUMPROGS%
goto :eof

:ContinueAfterCountMPAS
set NUMPROGS=%_NUMPROGS%
ECHO The total number of programs detected is %NUMPROGS%

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Get DVD label from folder
::---------------------

SET DVDLABEL=%~n1

IF "%DVDLABEL%"==""  SET DVDLABEL=Recorded DVD
ECHO.
ECHO.
ECHO The new DVD will use the label "%DVDLABEL%"

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Extract Shownames from Filenames
::---------------------

set _PGCNUMBER=1
echo. > RenameMPGs.bat
for %%f in (*.mpg) do call :ExtractShownames "%%~nf.mpg"

:ExtractShownames
set _SHOWNAME=%~n1
set SHOWNAME=%_SHOWNAME%
set PGCNUMBER=%_PGCNUMBER%
echo %PGCNUMBER% %SHOWNAME%
echo ren "%PGCNUMBER%.mpg" "%SHOWNAME%.mpg" >> RenameMPGs.bat
ren "%_SHOWNAME%.mpg" %_PGCNUMBER%.mpg

ECHO %SHOWNAME%> SHOWNAME%PGCNUMBER%.txt
FOR /F  "delims=`" %%T IN (SHOWNAME%PGCNUMBER%.txt) DO SET NAMEPROG%PGCNUMBER%=%%T
IF "%SHOWNAME%"=="" SET NAMEPROG%PGCNUMBER%=Program %PGCNUMBER%

ECHO.
ECHO.
IF "%SHOWNAME%"=="" ECHO Show number %PGCNUMBER% will be labelled "Program %PGCNUMBER%"
IF NOT "%SHOWNAME%"=="" ECHO Show number %PGCNUMBER% will be labelled "%SHOWNAME%"
ECHO.
ECHO.
SET SHOWNAME=

SET /A _PGCNUMBER=%_PGCNUMBER%+1
set PGCNUMBER=%_PGCNUMBER%
IF %PGCNUMBER% GTR %NUMPROGS% GOTO :ContinueAfterExtractShownames

GOTO :eof

:ContinueAfterExtractShownames

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Create images and menus for DVD
::---------------------

if not exist "menu.jpg" %CONVERT% -size %SCREENWIDTH%x%SCREENHEIGHT% xc:%BACKGROUNDCOLOR% menu.jpg

%CONVERT% "menu.jpg" -resize %SCREENWIDTH%x%SCREENHEIGHT%! "menu.png"

:ContinueBackgrounds
copy menu.png blankbackground.png

:: Calculate the maximum number of rows of buttons based on row height and buffer distance
SET /A MAXROWS=(%MAXMENUHEIGHT%+%BUTTONBUFFER%)/(%BUTTONHEIGHT%+%BUTTONBUFFER%)

:: Calculate the Number of Columns
SET /A NUMCOLS=%NUMPROGS%/%MAXROWS%
SET /A TEMP1=%MAXROWS%*%NUMCOLS%
IF %NUMPROGS% GTR %TEMP1% SET /A NUMCOLS=%NUMCOLS%+1

:: Calculate the number of rows
SET /A NUMROWS=%NUMPROGS%/%NUMCOLS%
SET /A TEMP2=%NUMCOLS%*%NUMROWS%
IF %NUMPROGS% GTR %TEMP2% SET /A NUMROWS=%NUMROWS%+1

:: Calculate the button width
SET /A BUTTONWIDTH=(%MAXMENUWIDTH%+%BUTTONBUFFER%-%BUTTONBUFFER%*%NUMCOLS%)/%NUMCOLS%

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Create Buttons
::---------------------
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATEBUTTONS %%n)
GOTO :CONTINUE1
   
:LOOPCREATEBUTTONS
SET LABEL=NAMEPROG%1
CALL SET LABEL=%%%LABEL%%%

IF %1 LSS 10 (SET TEXTPROGNUM=0%1) ELSE (SET TEXTPROGNUM=%1)

%CONVERT% -size %BUTTONWIDTH%x%BUTTONHEIGHT% -gravity center -background transparent -fill %MAINFONTCOLOR% +antialias -font %FONTDIR%\%FONT% label:"%LABEL%" mainbutton%TEXTPROGNUM%.png
%CONVERT% -size %BUTTONWIDTH%x%BUTTONHEIGHT% -gravity center -background transparent -fill %ACTIONFONTCOLOR% +antialias -font %FONTDIR%\%FONT% label:"%LABEL%" actionbutton%TEXTPROGNUM%.png
%CONVERT% -size %BUTTONWIDTH%x%BUTTONHEIGHT% -gravity center -background transparent -fill %HIGHLIGHTFONTCOLOR% +antialias -font %FONTDIR%\%FONT% label:"%LABEL%" highlightbutton%TEXTPROGNUM%.png
GOTO :EOF
:CONTINUE1

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Create Menu Images
::---------------------

IF NUMPROGS LSS 10 (SET TEXTNUMPROGS=0%NUMPROGS%) ELSE (SET TEXTNUMPROGS=%NUMPROGS%)

%MONTAGE% mainbutton*.png  -tile 1x%NUMROWS% -background transparent  -geometry +%BUTTONBUFFER_HALF%+%BUTTONBUFFER_HALF%  maintemp.png
%MONTAGE% maintemp*.png  -tile x1 -background transparent  -geometry +0+0 main_temp.png
%CONVERT% main_temp.png -size %SCREENWIDTH%x%SCREENHEIGHT% -background transparent +swap -gravity center -composite MainMenu.png


%COMPOSITE% -gravity center  MainMenu.png  Menu.png MainMenu.png


%MONTAGE% actionbutton*.png  -tile 1x%NUMROWS% -background transparent  -geometry +%BUTTONBUFFER_HALF%+%BUTTONBUFFER_HALF%  actiontemp.png
%MONTAGE% actiontemp*.png -tile x1 -background transparent  -geometry +0+0 action_temp.png
%CONVERT% action_temp.png -size %SCREENWIDTH%x%SCREENHEIGHT% xc:transparent +swap -gravity center -composite ActionMenu.png

%MONTAGE% highlightbutton*.png  -tile 1x%NUMROWS% -background transparent  -geometry +%BUTTONBUFFER_HALF%+%BUTTONBUFFER_HALF%  highlighttemp.png
%MONTAGE% highlighttemp*.png  -tile x1 -background transparent  -geometry +0+0 highlight_temp.png
%CONVERT% highlight_temp.png -size %SCREENWIDTH%x%SCREENHEIGHT% xc:transparent +swap -gravity center -composite HighlightMenu.png

:://///////////////////////////////////////////////////////

::Create MainMenuSpu.xml file to create menu
::---------------------

ECHO ^<subpictures^> >MainMenuSpu.xml
ECHO   ^<stream^> >>MainMenuSpu.xml
ECHO     ^<spu start="00:00:00.0" >>MainMenuSpu.xml
ECHO          highlight="HighlightMenu.png" >>MainMenuSpu.xml
ECHO          select="ActionMenu.png" >>MainMenuSpu.xml
ECHO          force="yes" >>MainMenuSpu.xml
ECHO          autoorder="rows"^> >>MainMenuSpu.xml

::************
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATESPUMUXFILE %%n %BUTTONWIDTH% %NUMROWS% %NUMCOLS%)
GOTO :CONTINUE2
   
:LOOPCREATESPUMUXFILE
SET PROGRAMNUM=%1
SET BUTTONWIDTH=%2
SET NUMROWS=%3
SET NUMCOLS=%4

SET /A MENU_YPOSITION_TOP=(%SCREENHEIGHT%-(%NUMROWS%*(%BUTTONHEIGHT%+%BUTTONBUFFER%)))/2

SET /A COLUMNNUM=%PROGRAMNUM%/%NUMROWS%
SET /A TEMP3=%COLUMNNUM%*%NUMROWS%
IF %PROGRAMNUM% GTR %TEMP3% SET /A COLUMNNUM=%COLUMNNUM%+1
SET /A ROWNUM=%PROGRAMNUM%-(%NUMROWS%*(%COLUMNNUM%-1))

SET LABEL=NAMEPROG%1
CALL SET LABEL=%%%LABEL%%%
SET /A BUTTON_YPOSITION_TOP=%MENU_YPOSITION_TOP%+%BUTTONBUFFER%/2+(%ROWNUM%-1)*(%BUTTONHEIGHT%+%BUTTONBUFFER%)
SET /A BUTTON_YPOSITION_BOTTOM=%BUTTON_YPOSITION_TOP%+%BUTTONHEIGHT%
SET /A BUTTON_XPOSITION_LEFT=(%SCREENWIDTH%-%MAXMENUWIDTH%)/2+%BUTTONBUFFER%/2+(%COLUMNNUM%-1)*(%BUTTONWIDTH%+%BUTTONBUFFER%)
SET /A BUTTON_XPOSITION_RIGHT=BUTTON_XPOSITION_LEFT+%BUTTONWIDTH%

ECHO ^<button name="%LABEL%" x0="%BUTTON_XPOSITION_LEFT%" y0="%BUTTON_YPOSITION_TOP%" x1="%BUTTON_XPOSITION_RIGHT%" y1="%BUTTON_YPOSITION_BOTTOM%"/^> >>MainMenuSpu.xml


GOTO :EOF

:CONTINUE2
::************
ECHO     ^</spu^> >>MainMenuSpu.xml
ECHO   ^</stream^> >>MainMenuSpu.xml
ECHO ^</subpictures^> >>MainMenuSpu.xml


::////////////////////////////////////////////////////////

::Create MPEG movies for menus
::---------------------
%PNG2YUV% -n 1 -I p -L 0 -f %FRAMERATE% -j "blankbackground.png" 2>NUL | %MPEG2ENC% -f 8 -I 0 -h -q 1 -b 7000 -a 2 -n n -o "BlankBackground.m2v" >NUL 2>NUL
%MPLEX% -f 8 -o "BlankBackground.mpg" "BlankBackground.m2v" >NUL 2>NUL

%PNG2YUV% -n 1 -I p -L 0 -f %FRAMERATE% -j "MainMenu.png" 2>NUL | %MPEG2ENC% -f 8 -I 0 -h -q 1 -b 7000 -a 2 -n n -o "MainMenuBackground.m2v" >NUL 2>NUL
%MPLEX% -f 8 -o "MainMenuBackground.mpg" "MainMenuBackground.m2v" >NUL 2>NUL

::Merge Files using spumux
%SPUMUX% "MainMenuSpu.xml" <"MainMenuBackground.mpg" > "MainMenu.mpg" 2>NUL
pause

::////////////////////////////////////////////////////////

::Create dvdauthor xml file
::---------------------

ECHO ^<?xml version="1.0" encoding="utf-8"?^> > dvd.xml
ECHO ^<dvdauthor dest="%TARGETDIR%"^> >> dvd.xml
ECHO ^<vmgm^> >> dvd.xml
ECHO     ^<menus^> >> dvd.xml
ECHO     ^<video format="%videoformat%"^>^</video^> >> dvd.xml
ECHO       ^<pgc^> >> dvd.xml
ECHO       ^<pre^> { if (g1 eq 0) { button = 1024;} else  { button = g1*1024;} } ^</pre^> >> dvd.xml
ECHO       ^<vob file="MainMenu.mpg" pause="inf"/^> >> dvd.xml
::************
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATEDVDAUTHORFILE %%n)
GOTO :CONTINUE3
   
:LOOPCREATEDVDAUTHORFILE
SET LABEL=NAMEPROG%1
CALL SET LABEL=%%%LABEL%%%
ECHO         ^<button name="%LABEL%"^>g1=1;jump title %1;^</button^> >> dvd.xml
GOTO :EOF

:CONTINUE3
::************
ECHO       ^</pgc^> >> dvd.xml
ECHO     ^</menus^> >> dvd.xml
ECHO ^</vmgm^> >> dvd.xml
ECHO ^<titleset^> >> dvd.xml
ECHO     ^<menus^> >> dvd.xml
ECHO     ^<video format="%videoformat%"^>^</video^> >> dvd.xml
ECHO       ^<pgc^> >> dvd.xml
ECHO         ^<vob file="BlankBackground.mpg" /^> >> dvd.xml
ECHO         ^<post^>jump vmgm menu 1;^</post^> >> dvd.xml
ECHO       ^</pgc^> >> dvd.xml
ECHO     ^</menus^> >> dvd.xml
ECHO     ^<titles^> >> dvd.xml
::************
SET PGCNUMBER=1
:LOOPXML2
ECHO      ^<pgc^> >> dvd.xml
ECHO         ^<vob file="%PGCNUMBER%.mpg" chapters= "00:00:00,00:10:00,00:20:00,00:30:00,00:40:00,00:50:00,01:00:00,01:10:00,01:20:00,01:30:00,01:40:00,01:50:00,02:00:00,02:10:00,02:20:00,02:30:00,02:40:00,02:50:00,03:00:00"/^> >> dvd.xml
ECHO         ^<post^>call vmgm menu 1;^</post^> >> dvd.xml
ECHO       ^</pgc^> >> dvd.xml

SET /A PGCNUMBER=%PGCNUMBER%+1
IF %PGCNUMBER% LEQ %NUMPROGS% GOTO :LOOPXML2
::************
ECHO     ^</titles^> >> dvd.xml
ECHO   ^</titleset^> >> dvd.xml
ECHO ^</dvdauthor^> >> dvd.xml

::\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

::Create DVD File structure using DVDAuthor
::---------------------

:: Convert movies into DVD format on the hard drive
call %DVDAUTHOR% -x dvd.xml
call RenameMPGs.bat
endlocal
EXIT


There's one small change which might be useful to your script:
if you change
FOR /L %%n IN (1,1,%NUMROWS%) DO (call :LOOPCREATEDVDAUTHORFILE %%n)
to
FOR /L %%n IN (1,1,%NUMPROGS%) DO (call :LOOPCREATEDVDAUTHORFILE %%n)
it breaks menus with more than one column of titles otherwise.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 01, 2006 6:57 pm 
Offline

Joined: Mon Jan 23, 2006 4:02 pm
Posts: 8
Hello mimwdv,

Your file looks great and I see where it could be useful. I would post this in the guides at videohelp.com if I were you.

I will post an update to the original batch file shortly (when I have had a chance to test it). It incorporates a few changes based on your code. First is the better use of ntsc and pal settings. Second is the use of a menu background. Third is the bug fix you suggested (good catch!). Finally, I hope that AC3 recordings will be better supported.

Thanks for your help!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jun 02, 2006 6:53 am 
Offline

Joined: Sun May 14, 2006 5:29 am
Posts: 44
Location: Sydney, Australia
I don't know about posting at videohelp - it's still very fragile - every time I run it I seem to hit another problem! Anyone using it would need to have at least a reasonable knowledge of DOS to be able to fix it.

Yeah, setting up NTSC and pal properly is something I should do, esp since getting it wrong means the menu highlights etc don't line up properly.

The other thing I'm playing with is a clearer way to adjust where the menu items go - I've been experimenting with changing the gravity/geometry settings to align them differently - maybe creating some global settings for that might help - it looks really weird when you set the main menu as "north" and the highlight as "south", LOL.

As to AC3 recordings - I haven't had a problem with it. I've made DVDs with either AC3 or MPA streams, but I haven't tried one with both together - haven't worked out yet how to add more than one audio stream to the file!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Jun 02, 2006 1:37 pm 
Offline

Joined: Sun May 28, 2006 8:16 pm
Posts: 17
For more then one audio stream:

mplex.exe -f 8 -o output.mpg audio1.m2v audio2.mp2 audio3.mp2 audio4.ac3


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group