Advertisement
tophf

logBlackBorders

Nov 6th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. # Usage:
  3.  
  4.     ep = "01"
  5.     logBlackBorders(ep+".borders.log", ep+".xvid")
  6.     #or:
  7.     logBlackBordersRF(ep+".borders.log", ep+".framelist.txt")
  8.     #or:
  9.     logBlackBordersRF(ep+".borders.log", "0 178 223 261 269 355 364 453 464 526 554 618 754 854 923 944")
  10.  
  11. # Log example:
  12.  
  13.     1668 Top Bottom
  14.     1669 Left Top Right Bottom
  15.     1670 Top Bottom
  16.     1680 Top Bottom
  17.  
  18. # For logBlackBordersRF() the plain list of frames (scenecuts) can be generated by the batch file below.
  19. # Multiple xvid logs may be specified, for each one a new file with .remfs.txt suffix is created.
  20. # It's also possible to simply drag'n'drop multiple xvid log files onto the batch file in Explorer.
  21.  
  22.     @echo off
  23.     if "%~1"=="" echo Usage: scxvid2remfs 01-xvid.log 02-xvid.log 03-xvid.log & exit/b
  24.     :loop
  25.     (
  26.         for /f "delims=:" %%a in ('findstr /bn "i" "%~1"') do (
  27.             set /a frame=%%a-4
  28.             setlocal enableDelayedExpansion
  29.             echo !frame!
  30.             endlocal
  31.         )
  32.     )>"%~n1.remfs.txt"
  33.     shift
  34.     if not "%~1"=="" goto loop
  35.  
  36. # Code:
  37. */
  38.  
  39. function logBlackBorders(clip c, string logfile, val scxvid_maskorfile, int "bordersize", int "lumathreshold") {
  40.     bord = default(bordersize, 1)
  41.     thr = string(default(lumathreshold, 20))
  42.  
  43.     c.converttoy8()
  44.     mask = isclip(scxvid_maskorfile) ? scxvid_maskorfile
  45.         \ : isstring(scxvid_maskorfile) ? SCXvidMask(scxvid_maskorfile)
  46.         \ : assert(false, "logBlackBorders: 'scxvid' parameter should be a clip or a file name string")
  47.     L = mt_lutf(last, "max", "x", w=bord).crop(0,0,1,1)
  48.     T = mt_lutf(last, "max", "x", h=bord).crop(0,0,1,1)
  49.     R = mt_lutf(last, "max", "x", offx=c.width-bord).crop(c.width-1,0,1,1)
  50.     B = mt_lutf(last, "max", "x", offy=c.height-bord).crop(0,c.height-1,1,1)
  51.  
  52.     mask.converttoy8.crop(0,0,4,1)
  53.     conditionalfilter(last,
  54.         \ writefileif(stackhorizontal(L, T, R, B), logfile, "YPlaneMax(75) <= "+thr, """
  55.             string(current_frame)
  56.             \ + (crop(0,0,1,0).YPlaneMax <= """ + thr + """ ? " Left" : "")
  57.             \ + (crop(1,0,1,0).YPlaneMax <= """ + thr + """ ? " Top" : "")
  58.             \ + (crop(2,0,1,0).YPlaneMax <= """ + thr + """ ? " Right" : "")
  59.             \ + (crop(3,0,1,0).YPlaneMax <= """ + thr + """ ? " Bottom" : "")
  60.         """, append=false, flush=true),
  61.         \ last,
  62.         \ "YPlaneMin", "=", "255")
  63. }
  64.  
  65. /***********************************************************************************************/
  66.  
  67. function logBlackBordersRF(clip c, string logfile, string scenecuts_stringorfilename, int "bordersize", int "lumathreshold") {
  68.     bord = default(bordersize, 1)
  69.     thr = string(default(lumathreshold, 20))
  70.  
  71.     c.converttoy8()
  72.     L = mt_lutf(last, "max", "x", w=bord).crop(0,0,1,1)
  73.     T = mt_lutf(last, "max", "x", h=bord).crop(0,0,1,1)
  74.     R = mt_lutf(last, "max", "x", offx=c.width-bord).crop(c.width-1,0,1,1)
  75.     B = mt_lutf(last, "max", "x", offy=c.height-bord).crop(0,c.height-1,1,1)
  76.  
  77.     writefileif(stackhorizontal(L, T, R, B), logfile, "YPlaneMax(75) <= "+thr, """
  78.         string(current_frame)
  79.         \ + (crop(0,0,1,0).YPlaneMax <= """ + thr + """ ? " Left" : "")
  80.         \ + (crop(1,0,1,0).YPlaneMax <= """ + thr + """ ? " Top" : "")
  81.         \ + (crop(2,0,1,0).YPlaneMax <= """ + thr + """ ? " Right" : "")
  82.         \ + (crop(3,0,1,0).YPlaneMax <= """ + thr + """ ? " Bottom" : "")
  83.     """, append=false, flush=true)
  84.     \ .remfs(mappings=exist(scenecuts_stringorfilename) ? undefined : scenecuts_stringorfilename,
  85.         \ filename=exist(scenecuts_stringorfilename) ? scenecuts_stringorfilename : undefined)
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement