/* EmperoarTV_MPG2_AVI_Batch.cmd */ /**************************************************************** 23-11-8 This REXX Program guides you to build a CMD-batch that contains the commands needed to convert MPEG2 files made by EmperoarTV to Avi. The batch uses the two pass encoding provided by ffmpeg: http://www.smedley.info/os2ports/index.php?page=ffmpeg The utility priority.exe is used to lower the priority of ffmpeg: ftp://ftp.netlabs.org/pub/fm2/fm2utils.zip Without it OS/2 or eCS would terribly slow down during it's calculations. Usage: Just drag and drop an by EmperoarTV made MPG-file to this Rexx program Program Object. The batch will appear in the same directory as the MPPEG 2 file. **************Sjoerd Visser (Copyright, 2008)******************/ TRACE E /* Trace errors */ /*********************************************************** These are the default variables. You can change them if you like. If ffmpeg is not in the path you can enter it as: FfmpegVersion='c:\tools\FFMPEG' or 'c:\tools\ffmpeg.exe' **************************************************************/ FfmpegVersion='FFMPEG' PriorityVersion='PRIORITY' MencoderVersion= 'MENCODER' MovieName="" TVFormat='pal' /* Enter 'pal' or 'ntsc' */ DriveLetter= "" SeekTime=0 EndTime=14400 AviTime = EndTime-Seektime MapAV='-map 0:0 -map 0:1' Acodec="libmp3lame" AbitRate=96 LameVol=6 Vcodec='mpeg4' VBitRate=1100 Vtag='xvid' Scale='512x288' Aspect='16:9' CropTop=72 CropBottom=72 CropLeft=8 CropRight=8 Quality='-mbd rd -flags +4mv+trell+aic -cmp 2 -subcmp 2 -g 300' Priority='1 0' /********End default values *******************/ /* main program */ PARSE ARG FullSourcePath PARSE VAR FullSourcePath '"' FullSourcePathStripped '"' IF FullSourcePathStripped = '' THEN NOP ELSE FullSourcePath = FullSourcePathStripped /* Above code dealt with some peculiarity of the WPS SAY 'FullSourcePathStripped is 'FullSourcePathStripped SAY 'FullSourcePath is 'FullSourcePath PULL . */ CALL CheckForNames FullSourcePath MovieName = result '@MODE co80,43' UserInput='' DO WHILE UserInput \=Q '@CLS' SAY '-------------------------------------------------' SAY 'Which predefined value do you want to reset?' SAY 'Type number [Enter] to change item' SAY SAY ' 1 Path to source : 'FullSourcePath SAY ' 2 Where to start coding(sec) : 'SeekTime SAY ' 3 Where to end coding(sec) : 'EndTime' + 'SeekTime SAY ' Movie duration : 'EndTime/3600' hours' SAY ' 4 How to map audio and video : 'MapAV SAY ' 5 Video codec : 'Vcodec SAY ' 6 Vtag (default xvid): : 'Vtag SAY ' 7 Video bitrate(kbs) : 'VBitRate SAY ' 8 Audio codec settings : 'Acodec SAY ' 9 Audio bitrate (kbs) : 'AbitRate SAY '10 The scale parameters are : 'Scale SAY '11 The aspect ratio is : 'Aspect SAY '12 The Crop Values are:' SAY ' Top 'CropTop SAY ' Left' 'Right 'CropRight' 'CropLeft SAY ' Bottom 'CropBottom SAY '13 Check BitsPerPixel' SAY '14 Priority settings are: 'Priority SAY '15 Quality settings are: 'Quality SAY SAY 'Enter "I" to build a script that reindexes the MPG file' SAY 'Enter "C" to build a CMD file that launches ffmpeg' SAY 'Enter "Q" to leave this script' PULL UserInput . SELECT WHEN UserInput = 1 THEN DO CALL FullSourcePath_Request FullSourcePath FullSourcePath = result CALL CheckForNames FullSourcePath MovieName = result END WHEN UserInput = 2 THEN DO CALL SeekTime_Request SeekTime SeekTime = result END WHEN UserInput = 3 THEN DO CALL EndTime_Request EndTime SeekTime EndTime = result END WHEN UserInput = 4 THEN DO CALL MapAV_Request MapAV MapAV = result END WHEN UserInput = 5 THEN DO CALL Vcodec_Request Vcodec Vcodec = result END WHEN UserInput = 6 THEN DO CALL Ffource_Request Vtag Vtag = result END WHEN UserInput = 7 THEN DO CALL VBitRate_Request VBitRate AbitRate EndTime VBitRate = result END WHEN UserInput = 8 THEN DO CALL Acodec_Request Acodec Acodec = result END WHEN UserInput = 9 THEN DO CALL AbitRate_Request AbitRate AbitRate = result END WHEN UserInput = 10 THEN DO CALL Scale_Request Scale Aspect VBitRate PARSE VAR result Scale Aspect END WHEN UserInput = 11 THEN DO CALL Aspect_Request Aspect CropTop CropBottom CropLeft CropRight Aspect = result END WHEN UserInput = 12 THEN DO CALL Crop_Request CropTop CropBottom CropLeft CropRight PARSE VAR result CropTop CropBottom CropLeft CropRight END WHEN UserInput = 13 THEN DO CALL BitsPerPixel_Request Scale VBitRate CropTop CropBottom CropLeft CropRight PARSE VAR result BitsPerPixel VBitRate END WHEN UserInput = 14 THEN DO CALL Priority_Setting Priority Priority = result END WHEN UserInput = 15 THEN DO CALL Quality_Request Quality Quality = result END WHEN UserInput = I THEN DO CALL Reindex FullSourcePath END WHEN UserInput = C THEN DO CALL BatchBuilding FullSourcePath END WHEN UserInput = 'Q' THEN DO SAY SAY 'Bye' END OTHERWISE /* Geen DO nodig */ SAY 'You entered no valid value : 'UserInput SAY 'Type the ENTER key to try again ' PULL . END END /* END twice */ EXIT 0 /*+++++++ SUBROUTINES +++++++++++++++++++= */ FullSourcePath_Request: PROCEDURE /* Ask for the MPEG 2 source file */ PARSE ARG FullSourcePath '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'Which MPG source file do you want to use?' SAY 'The file will not be changed.' SAY SAY 'Please enter the full path name between parantheses.' SAY 'Current one is 'FullSourcePath SAY 'Entering nothing leaves it the same' SAY '--------------------------------------------------------------------------------' PARSE PULL FullSourcePathNew SELECT WHEN FullSourcePathNew = "" THEN RETURN FullSourcePath WHEN FullSourcePathNew \= "" THEN DO SAY 'You entered 'FullSourcePathNew'.' Call File_Exists FullSourcePathNew If result = 1 THEN DO SAY 'The file 'FullSourcePathNew' will be used.' RETURN FullSourcePathNew END ELSE DO SAY 'I leave it as it was.' SAY 'Press Enter.' PULL . RETURN FullSourcePath END END RETURN FullSourcePath CheckForNames: /* PROCEDURE EXPOSE FullSourcePath MovieName FullMovieName SourceDir DriveLetter AviDir MovieNameCmd */ /* Tries to find out which file is meant to be encoded */ PARSE ARG FullSourcePath /* No . after the filename, but please check for blanks */ CALL File_Exists FullSourcePath IF result = 0 THEN DO '@CLS' SAY FullSourcePath 'does not exist.' SAY 'Maybe you entered difficult to parse filename' SAY 'OS/2 Tips:' SAY 'Tip1: Replace [] by () in the source path' SAY 'Tip2: Drag and drop the MPG-file to this program object.' SAY 'Tip3: Check the Real (not WPS) Filename under Right-click Settings / File!' SAY 'Please press Enter and try again' SAY 'Serve you later!' PULL . RETURN MovieName END IF result = 1 THEN SAY FullSourcePath 'exists.' /* Needs to be implemented: Check for blanks in this FullSourcePath */ /* Parse path and filename of the source */ FullSourcePathLength = LENGTH(FullSourcePath) FullMovieNameLength = FullSourcePathLength - (LASTPOS('\',FullSourcePath)) FullMovieName = RIGHT(FullSourcePath,FullMovieNameLength) MovieNameExtensionLength = FullMovieNameLength - (LASTPOS('.',FullMovieName)) SourceDir = LEFT(FullSourcePath,(FullSourcePathLength- FullMovieNameLength -1)) /*without \ */ DriveLetter = LEFT(FullSourcePath,1) MovieNameExtension = RIGHT(FullMovieName,MovieNameExtensionLength) IF TRANSLATE(MovieNameExtension) \= 'MPG' THEN DO SAY 'Is 'FullSourcePath' a MPG file?' SAY 'You better change the souce in Menu Option 1' Pull . RETURN '' MovieNameIndexCmd END MovieNameEnd = RIGHT(FullMovieName,7) /* _01.MPG counts 7*/ SELECT WHEN MovieNameEnd = '_01.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_02.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_03.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_04.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_05.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_06.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_07.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_08.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_09.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_10.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) WHEN MovieNameEnd = '_AL.MPG' THEN MovieName = LEFT(FullMovieName, (FullMovieNameLength-7)) OTHERWISE MovieName = LEFT(FullMovieName, (FullMovieNameLength-MovieNameExtensionLength-1)) END SAY 'Code for variables: Who is who?' SAY '--------------------------------' SAY 'You entered 'FullSourcePath' as the source.' /* Q:\Mpg\Mar_adentro_01.MPG */ SAY 'The extension is 'MovieNameExtension /* MPG */ SAY 'Drive is' DriveLetter 'without :' /* Q */ SAY 'SourceDir is 'SourceDir' without \' /* Q:\Mpg */ SAY 'FullMoviename of the source is 'FullMovieName /* Mar_adentro_01.MPG */ SAY "It's length is "FullMovieNameLength /* 18 */ MovieNameAvi = MovieName'.avi' /* Mar_adentro.avi */ AviDir = SourceDir ||'\'|| MovieName ||'_'|| VBitRate /* Mar_adentro_700 */ FullMovieNameAvi = AviDir || '\'|| MovieNameAvi /* Q:\Mpg\Mar_adentro_700\Mar_adentro.avi */ MovieNameCmd = SourceDir || '\' || TRANSLATE(MovieName,'_',' ') ||'_'|| VBitRate ||'.cmd' /* Q:\Mpg\Mar_adentro_700.cmd */ MovieNameIndexCmd = SourceDir || '\' || TRANSLATE(MovieName,'_',' ') ||'_'||'Reindex.cmd' /* Q:\Mpg\Mar_adentro_Reindex.cmd */ MovieNameReindexed = SourceDir || '\' || TRANSLATE(MovieName,'_',' ') ||'_IDX.MPG' /* Q:\Mpg\Mar_adentro_IDX.MPG */ SAY 'The CMD file to be created is 'MovieNameCmd /* Q:\Mpg\Mar_adentro_700.cmd */ SAY 'The AVI file becomes 'MovieNameAvi /* Mar_adentro.avi */ IF MovieNameEnd \= "MOVIENAMEEND" THEN SAY 'I stripped 'MovieNameEnd' ...' /* _01.MPG */ SAY 'The AviDir will become 'AviDir /* Q:\Mpg\Mar_adentro */ SAY 'The full filename wil be 'FullMovieNameAvi /* Q:\Mpg\Mar_adentro\Mar_adentro.avi */ RETURN MovieName SeekTime_Request: PROCEDURE PARSE ARG SeekTime '@CLS' /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ SAY '--------------------------------------------------------------------------------' SAY 'At what time in seconds (according to Mplayer)' SAY 'do you want to start encoding this movie?' SAY 'A value > 0 might remove not usefull MPEG2 stuff' SAY 'Your Mplayer starting time in seconds is now 'SeekTime SAY SAY 'If you inspect the movie with MPlayer using ->, <-, PageUp and' SAY 'PageDown keys and pause with "p" at the start and endtime, ' SAY 'you will see the times in seconds after the A at the MPlayer CLI.' SAY SAY 'A: 419.5 V: 419.5 A-V: -0.014 ct: 0.236 1674/1674 10% 24% 4.6% 0 0' SAY 'A:4961.5 V:4961.5 A-V: 0.025 ct: 0.244 2426/2426 8% 27% 3.5% 0 0' SAY ' ===== PAUSE =====' SAY 'So 419 is the seektime and 4961 is the endtime (time=4961-419)' SAY '--------------------------------------------------------------------------------' PARSE LINEIN SeekTimeNew IF SeekTimeNew = "" THEN RETURN SeekTime ELSE RETURN SeekTimeNew EndTime_Request: PROCEDURE PARSE ARG EndTime SeekTime '@CLS' /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ SAY '--------------------------------------------------------------------------------' SAY 'At which time in seconds (ask MPlayer) do you want to finish the encoding? ' SAY SAY 'Notice: The long default value of 14400 seconds (4 hours) is recommended' SAY 'when the framenumbers in the MPPEG2 files are not unique.' SAY 'FI when an 1 hour movie starts at 0 and ends at less then 3600 (60*60) seconds.' SAY 'In this case you could use the reindex option ("i")' SAY SAY 'Notice: Mencoders AVI endtime in seconds will be the MPEG2 'EndTime' minus 'SeekTime SAY 'If you Enter nothing nothing will be changed' SAY SAY 'If you inspect the movie with MPlayer using ->, <-, PageUp and' SAY 'PageDown keys and pause with "p" at the start and endtime, ' SAY 'you will see the times in seconds after the A at the MPlayer CLI.' SAY SAY 'A: 419.5 V: 419.5 A-V: -0.014 ct: 0.236 1674/1674 10% 24% 4.6% 0 0' SAY 'A:4961.5 V:4961.5 A-V: 0.025 ct: 0.244 2426/2426 8% 27% 3.5% 0 0' SAY ' ===== PAUSE =====' SAY 'So 419 is the seektime and 4961 is the endtime (time=4961-419)' SAY '--------------------------------------------------------------------------------' PARSE LINEIN EndTimeNew IF EndTimeNew = "" THEN RETURN EndTime - SeekTime IF EndTimeNew < 0 THEN RETURN EndTimeNew - SeekTime ELSE RETURN EndTimeNew - SeekTime AbitRate_Request:PROCEDURE PARSE ARG AbitRate . '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'At what AbitRate (in kilobits/s) do you want to encode? ' SAY 'With MP3 the value of 96 suffices most times and 128 or 196 are high quality options' SAY 'With AC3 at least 128 is needed. And 196 or higher is recommended' SAY '--------------------------------------------------------------------------------' PARSE LINEIN AbitRateNew IF AbitRateNew = "" THEN RETURN AbitRate ELSE RETURN AbitRateNew MapAV_Request: PROCEDURE PARSE ARG NewMapAV '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'How do you want to map the input and output streeams?' SAY 'Syntax: -map v#:v# -map a#:a# ' SAY 'Default: -map 0:0 -map 0:1' PARSE LINEIN NewMapAV IF NewMapAV == "" THEN RETURN '-map 0:0 -map 0:1' ELSE RETURN NewMapAV Vcodec_Request: PROCEDURE PARSE ARG Vcodec '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'What video codec do you want to use?' SAY 'Type the abbrevation of the video codec' SAY SAY 'Options are "mpeg4" en "h".' SAY 'Default = mpeg4' SAY '--------------------------------------------------------------------------------' PARSE LINEIN VcodecNew . IF VcodecNew =="" THEN RETURN 'mpeg4' ELSE SAY 'You entered 'VcodecNew RETURN VcodecNew Acodec_Request: PROCEDURE PARSE ARG Acodec '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'Which audio codec do you want to use?' SAY 'Type a valid acodec for FFMPEG.' SAY SAY 'Options are "ac3" en "libmp3lame".' SAY 'Default is libmp3lame.' SAY 'Current one is 'Acodec SAY '--------------------------------------------------------------------------------' PARSE PULL Acodec_New SELECT WHEN Acodec_New = '' THEN RETURN 'libmp3lame' WHEN Acodec_New = 'AC3' THEN RETURN 'ac3' WHEN Acodec_New = 'LIBMP3LAME' THEN RETURN 'libmp3lame' OTHERWISE SAY 'No valid option given.' PULL . END SAY 'We code with 'Acodec RETURN 'libmp3lame' VBitRate_Request: PROCEDURE PARSE ARG VBitRate AbitRate EndTime KBytesInMovie = (VBitRate + AbitRate) * EndTime / 8 MBytesInMovie = KBytesInMovie / 1024 NUMERIC DIGITS 4 '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'At what VBitRate (kbs/s) do you want to encode? ' SAY 'This parameter effects movie size most' SAY '700 suffices often, but 1200 gives better quality in action films.' SAY SAY 'Current value is' VBitRate SAY 'The estimated AVI file size is 'MBytesInMovie' MB.' SAY SAY 'Note: Maximum AVI size for FAT, HPFS and NetBIOS is 2048 MB.' SAY 'On FAT32, which is used by many media players, it is 4096 MB' SAY SAY 'Entering nothing keeps the current value' SAY SAY 'Please do not forget to visit: 13 Check BitsPerPixel!' SAY '--------------------------------------------------------------------------------' NUMERIC DIGITS 8 PARSE LINEIN VBitRateNew IF VBitRateNew = "" THEN RETURN VBitRate ELSE RETURN VBitRateNew Scale_Request: PROCEDURE PARSE ARG Scale Aspect VBitRate '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'In which scale (width:height in pixels) do you want to code?' SAY 'Your VBitRate is 'VBitRate SAY ' Usefull options are:' SAY SAY 'Modern 16:9 DVD format television' SAY ' Enter 1 for 768x432 (large, vbr > 1100k)' SAY ' Enter 2 for 672x384 (medium, vbr < 1100k)' SAY ' Enter 3 for 592x336 (medium, vbr < 1100k)' SAY ' Enter 4 for 512x288 (medium, vbr < 1100k)' SAY ' Enter 5 for 256x144 (tiny, vbr < 300k)' SAY SAY 'Classic 4:3 television' SAY ' Enter 6 for 640x480 (vbr > 1100k)' SAY ' Enter 7 for 576x432 (vbr > 1000k)' SAY ' Enter 8 for 512x384 (vbr > 600k)' SAY ' Enter 9 for 448x336 (vbr > 500k)' SAY ' Enter 10 for 384x288 (vbr > 400k)' SAY ' Enter 11 for 320x240 (vbr > 300k)' SAY SAY 'Choose your value: number [Enter]. Default is 8.' SAY 'If you want something else just enter a value like "704x400"' SAY 'without the paraentheses or tweak the batch by hand!' SAY '--------------------------------------------------------------------------------' PARSE LINEIN ScaleNew . SELECT WHEN ScaleNew ='1' THEN DO Scale ='768x432' Aspect = '16:9' END WHEN ScaleNew ='2' THEN DO Scale ='672x384' Aspect = '16:9' END WHEN ScaleNew ='3' THEN DO Scale ='592x336' Aspect = '16:9' END WHEN ScaleNew ='4' THEN DO Scale ='512x288' Aspect = '16:9' END WHEN ScaleNew ='5' THEN DO Scale ='256x144' Aspect = '16:9' END WHEN ScaleNew ='6' THEN DO Scale ='640x480' Aspect = '4:3' END WHEN ScaleNew ='7' THEN DO Scale ='576x432' Aspect = '4:3' END WHEN ScaleNew ='8' THEN DO Scale ='512x384' Aspect = '4:3' END WHEN ScaleNew ='9' THEN DO Scale ='448x336' Aspect = '4:3' END WHEN ScaleNew ='10' THEN DO Scale ='384x288' Aspect = '4:3' END WHEN ScaleNew ='11' THEN DO Scale ='320x240' Aspect = '4:3' END OTHERWISE RETURN ScaleNew Aspect END RETURN Scale Aspect Aspect_Request: PROCEDURE PARSE ARG Aspect CropTop CropBottom CropLeft CropRight PARSE VAR Aspect AspectSetWidth ':' AspectSetHeight SingleAspectValue = AspectSetWidth / AspectSetHeight SourceHeight = 576 - CropTop - CropBottom SourceWidth = 720 - CropLeft - CropRight SourceAspect = SourceWidth || ':' || SourceHeight SingleValueSourceAspect = SourceWidth / SourceHeight SourceArea = SourceHeight * SourceWidth Ratio = SingleValueSourceAspect / SingleAspectValue '@CLS' NUMERIC DIGITS 1 /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ SAY '--------------------------------------------------------------------------------' SAY 'Scale of full MPEG-2 source is 720:576 and contains 414720 pixels.' SAY 'After cutting the edges scale became 'SourceAspect' and contains 'SourceArea' pixels.' SAY 'The crop settings were 'CropTop CropBottom CropLeft CropRight'.' SAY SAY 'For which Width:Heigth ratio filter do you want to encode? ' SAY 'Entering nothing keeps the recommended value set for your scale' SAY SAY 'Aspect of the cropped source ('SourceAspect') is 'SingleValueSourceAspect SAY 'Aspect filter set with aspect ('Aspect') is 'SingleAspectValue SAY 'To prevent distortion their ratio (here: 'Ratio') should approach 1.' SAY SAY 'Enter 1 for 4:3 (classic TV)' SAY 'Enter 2 for 16:9 (DVD format)' SAY 'Or enter your "Width:Heigth" value by hand (not always supported by ffmpeg)' SAY '--------------------------------------------------------------------------------' PARSE LINEIN AspectNew SELECT WHEN AspectNew = "" THEN RETURN Aspect WHEN AspectNew = 1 THEN RETURN "4:3" WHEN AspectNew = 2 THEN RETURN "16:9" OTHERWISE RETURN AspectNew END RETURN Ffource_Request: PROCEDURE PARSE ARG Ffource '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'What v-tag should the FMP4 (Fast MP4) avi have?' SAY 'Valid options are: xvid, divx, dx50' SAY 'Recommended default = xvid (a better "divx" than divx)' SAY '--------------------------------------------------------------------------------' PARSE PULL UPPER LINEIN FfourceNew SELECT WHEN FfourceNew ="" THEN RETURN "xvid" WHEN FfourceNew ="XVID" THEN RETURN "xvid" WHEN FfourceNew ="DIVX" THEN RETURN "divx" WHEN FfourceNew ="DX50" THEN RETURN "dx50" OTHERWISE RETURN Ffource END Crop_Request: PROCEDURE PARSE ARG CropTop CropBottom CropLeft CropRight '@CLS' /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ SAY '--------------------------------------------------------------------------------' SAY 'Current Crop Settings are:' SAY SAY ' Top 'CropTop SAY ' Left' 'Right 'CropRight' 'CropLeft SAY ' Bottom 'CropBottom SAY SAY 'These are sizes in pixels of the (I hope) black bands that' SAY 'will be cut off from the edges of the source screen.' SAY SAY 'Here are some fine presets. Just Enter ONE number:' SAY '"1" is a shortcut for "8 8 8 8" (4:3 movie)' SAY '"2" is a shortcut for "80 80 8 8" (16:9 movie)' SAY '"3" is a shortcut for "72 72 8 8" (16:9 movie)' SAY SAY 'If you want to change them by hand Enter the FOUR values of' SAY '"CropTop CropBottom CropLeft CropRight" like "80 64 8 8"' SAY 'without parentheses. Or change them later by hand in the batch' SAY 'A lower crop bottom value will leave more space for subtitels.' SAY '--------------------------------------------------------------------------------' PARSE LINEIN CropTopNew CropBottomNew CropLeftNew CropRightNew . SELECT WHEN CropTopNew = "" THEN RETURN CropTop CropBottom CropLeft CropRight WHEN CropTopNew = "1" THEN RETURN "8 8 8 8" WHEN CropTopNew = "2" THEN RETURN "80 80 8 8" WHEN CropTopNew = "3" THEN RETURN "72 72 8 8" WHEN CropTopRightNew \= "" THEN RETURN CropTop CropBottom CropLeft CropRight OTHERWISE RETURN CropTopNew CropBottomNew CropLeftNew CropRightNew END BitsPerPixel_Request: PROCEDURE /* Do some checks on the entered data */ PARSE ARG Scale VBitRate CropTop CropBottom CropLeft CropRight PARSE VAR Scale ScaleWidth 'x' ScaleHeight ScaleArea = ScaleWidth * ScaleHeight /* The amount of pixels in scale) */ BitsPerPixel = VBitRate * 1000 / ScaleArea /* VBitRate/the amount of pixels is a measure of quality */ MinVBitRate = 2 * ScaleArea % 1000 MaxVBitRate = 10 * ScaleArea % 1000 SourceHeight = 576 - CropTop - CropBottom SourceWidth = 720 - CropLeft - CropRight SourceAspect = SourceWidth ||':'|| SourceHeight SingleValueSourceAspect = SourceWidth / SourceHeight SourceArea = SourceHeight * SourceWidth '@CLS' /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */ SAY 'Scale of full MPEG-2 source is 720x576 and contains 414720 pixels. After ' SAY 'cutting the edges scale became 'SourceAspect' and contains 'SourceArea' pixels.' SAY 'The crop settings were 'CropTop CropBottom CropLeft CropRight'.' SAY 'The scale of MPEG-4 avi-file 'Scale' contains 'ScaleArea' pixels' SAY SAY 'Do we have enough bandwith for this scale?' SAY ' Your video bitrate : 'VBitRate' k' SAY ' Bits/pixel with this scale : 'BitsPerPixel SAY ' Minimally advised VBitRate : 'MinVBitRate' k saves bandwidth. ' SAY ' Maximally advised VBitRate : 'MaxVBitRate' k is good for action movies.' SAY SAY 'For small frames (320x240) I consider a value of Bits/pixel < 2 as low' SAY '(poor quality) and a value > 10 as a waste of bandwidth.' SAY 'For larger frames the bitrate can be set in proportion to the square root of' SAY 'the number of pixels. So, when you want 640x480 you would double the bitrate.' SAY 'Notice that slow processors of dedicated Media Players (Cowon,iPod) also' SAY 'need relatively higher bitrates because they cannot decompress that fast.' SAY SAY 'Now, at what VBitRate (kbs/s) do you want to encode? ' SAY 'Current value is' VBitRate SAY 'Entering nothing keeps the current value' SAY '--------------------------------------------------------------------------------' PARSE LINEIN VBitRateNew IF VBitRateNew = "" THEN RETURN BitsPerPixel VBitRate ELSE RETURN BitsPerPixel VBitRateNew Priority_Setting: PROCEDURE /* In the future it should be possible to use nice for it by cheking PriorityVersion */ /* Setting the first value is skipped: >1 is risky and does not speed things really up */ '@CLS' SAY '--------------------------------------------------------------------------------' SAY 'With which idle priority (delta) do you want to code?' SAY 'Give a numeric value between "0-31"' SAY '--------------------------------------------------------------------------------' PARSE LINEIN Delta . IF Delta="" THEN RETURN Priority ELSE Priority='1 'Delta RETURN Priority Reindex: /* creates a batch that transforms the MPG to the same MPG file with a new index */ PARSE ARG FullSourcePath CALL CheckForNames FullSourcePath 'IF EXIST 'MovieNameIndexCmd' DEL 'MovieNameIndexCmd'' CALL LINEOUT MovieNameIndexCmd,'REM Batch to reindex "'FullSourcePath'" to "'MovieNameReindexed'"' CALL LINEOUT MovieNameIndexCmd, PriorityVersion Priority MencoderVersion ||' "'||FullSourcePath ||'" -forceidx -oac copy -ovc copy -of mpeg -o "' || MovieNameReindexed || '"' SAY 'The file 'MovieNameIndexCmd' has been created.' SAY 'It uses mencoder to create' MovieNameReindexed SAY 'Please inspect it before you execute it' SAY 'Press Enter' PULL . RETURN BatchBuilding: PARSE ARG FullSourcePath /* PARSE ARG FullSourcePath with blanks will give difficult PARSING problems */ /* So there is yet not a PROCEDURE here */ /* Anyway, these are the last actions */ CALL CheckForNames FullSourcePath MovieName = result /* Build a batch for OS/2 that you can edit by hand */ 'IF EXIST "MovieNameCmd" DEL "MovieNameCmd"' CALL LINEOUT MovieNameCmd,'REM Batch to convert "'FullSourcePath'" to "'FullMovieNameAvi'"' CALL LINEOUT MovieNameCmd,'REM' CALL LINEOUT MovieNameCmd,'MODE CO120,40' CALL LINEOUT MovieNameCmd, DriveLetter || ':' CALL LINEOUT MovieNameCmd,'CD' SourceDir CALL CheckForMoreResources FullSourcePath = result CALL LINEOUT MovieNameCmd,'MD "'MovieName ||'_'|| VBitRate'"' CALL LINEOUT MovieNameCmd,'CD '||'"' || MovieName ||'_'|| VBitRate ||'"' CALL LINEOUT MovieNameCmd,'REM Remove old logfiles' CALL LINEOUT MovieNameCmd,'DEL *.log' CALL LINEOUT MovieNameCmd,'REM Without this DEL *.avi FFMPEG will prompt you to overwrite the old AVI file' CALL LINEOUT MovieNameCmd,'DEL *.avi' CALL LINEOUT MovieNameCmd,'REM Here starts the first pass encoding which analyses the movie content and creates a log' CALL LINEOUT MovieNameCmd,PriorityVersion Priority FfmpegVersion '-i "'FullSourcePath'"' MapAV '-ss' SeekTime '-t' EndTime '-pass 1 -vcodec' Vcodec '-vtag' Vtag '-f avi -b' VBitRate||'k '|| Quality '-cropbottom' CropBottom '-cropleft' CropLeft '-cropright' CropRight '-croptop' CropTop '-s' Scale '-aspect' Aspect '-acodec' Acodec '-ac 2 -ab' AbitRate ||'k '|| '"'FullMovieNameAvi'"' CALL LINEOUT MovieNameCmd,'REM Here starts the second pass encoding that makes use of the log' CALL LINEOUT MovieNameCmd,'DEL "'FullMovieNameAvi'"' CALL LINEOUT MovieNameCmd,PriorityVersion Priority FfmpegVersion '-i "'FullSourcePath'"' MapAV '-ss' SeekTime '-t' EndTime '-pass 2 -vcodec' Vcodec '-vtag' Vtag '-f avi -b' VBitRate||'k '|| Quality '-cropbottom' CropBottom '-cropleft' CropLeft '-cropright' CropRight '-croptop' CropTop '-s' Scale '-aspect' Aspect '-acodec' Acodec '-ac 2 -ab' AbitRate ||'k '|| '"'FullMovieNameAvi'"' CALL LINEOUT MovieNameCmd,'EXIT' /* line out without data should close file */ SAY 'The batchfile 'MovieNameCmd' has been created.' SAY 'Please inspect it before you execute it' SAY 'Press Enter' PULL . RETURN CheckForMoreResources: /* Should be a PROCEDURE */ /* Problem: names with blanks may give us trouble */ CALL File_Exists SourceDir'\'MovieName'_AL.MPG' IF result= 1 THEN DO SAY SourceDir'\'MovieName'_AL.MPG exist' SAY 'This file will be encoded to AVI' RETURN SourceDir'\'MovieName'_AL.MPG' /* prevents Q:\Mpg\HommeDuTrain_AL_01.MPG */ END IF File_Exists(SourceDir'\'MovieName'_01.MPG') = 1 THEN SourceFileNumber=1 IF File_Exists(SourceDir'\'MovieName'_02.MPG') = 0 THEN RETURN SourceDir'\'MovieName'_01.MPG' IF File_Exists(SourceDir'\'MovieName'_02.MPG') = 1 THEN SourceFileNumber=2 IF File_Exists(SourceDir'\'MovieName'_03.MPG') = 1 THEN SourceFileNumber=3 IF File_Exists(SourceDir'\'MovieName'_04.MPG') = 1 THEN SourceFileNumber=4 IF File_Exists(SourceDir'\'MovieName'_05.MPG') = 1 THEN SourceFileNumber=5 IF File_Exists(SourceDir'\'MovieName'_06.MPG') = 1 THEN SourceFileNumber=6 IF File_Exists(SourceDir'\'MovieName'_07.MPG') = 1 THEN SourceFileNumber=7 IF File_Exists(SourceDir'\'MovieName'_08.MPG') = 1 THEN SourceFileNumber=8 IF File_Exists(SourceDir'\'MovieName'_09.MPG') = 1 THEN SourceFileNumber=9 IF File_Exists(SourceDir'\'MovieName'_10.MPG') = 1 THEN SourceFileNumber=10 IF SourceFileNumber = 1 THEN RETURN SourceDir'\'MovieName'_01.MPG' IF SourceFileNumber > 1 THEN DO SAY SourceDir'\'MovieName'_02.MPG exists.' SAY 'We have 'SourceFileNumber MovieName' sources.' SAY 'A binary COPY + command will concatenate all instances of 'MovieName'_0?.MPG to a them' SAY 'all including 'MovieName'_AL.MPG sourcefile, so that ALL MPG-sourcefiles can be used by ffmpeg.' SAY 'No files will be lost.' CALL LINEOUT MovieNameCmd,'REM This binary COPY will concatenate all instances of 'MovieName'_0?.MPG to' CALL LINEOUT MovieNameCmd,'REM a new 'MovieName'_AL.MPG sourcefile, so that one sourcefile can be used by ffmpeg.' CALL LINEOUT MovieNameCmd,'REM No files will be lost.' CALL LINEOUT MovieNameCmd,'IF NOT EXIST 'MovieName'_AL.MPG COPY 'MovieName'*.MPG /B 'MovieName'_AL.MPG' CALL LINEOUT MovieNameCmd,'ECHO Cat finished. Please check 'MovieName'_AL.MPG with MPlayer' CALL LINEOUT MovieNameCmd,'ECHO Please use 'MovieName'_AL.MPG as input for this script' CALL LINEOUT MovieNameCmd,'ECHO Otherwise remove the exit' CALL LINEOUT MovieNameCmd,'PAUSE' CALL LINEOUT MovieNameCmd,'EXIT' RETURN SourceDir'\'MovieName'_AL.MPG' END RETURN File_Exists: PROCEDURE /* Check if a file exists */ PARSE ARG File IF File = "" THEN SAY 'No filename given' IF STREAM(File,'C','QUERY EXISTS') = "" THEN DO SAY File' does not exist.' RETURN 0 END ELSE DO SAY File' exists.' RETURN 1 END EXIT NOTREADY: SAY 'File error has occured on line siql' SAY 'Program statement is ' sourceline(siql) SAY 'Program terminated' EXIT EXIT