Guest User

Untitled

a guest
Sep 9th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Sets up race grid
  2. function RaceGrid(clip c1, clip c2, clip c3, clip c4, int start)
  3. {
  4.     border = 15
  5.     StackVertical(StackHorizontal(c1.AddBorders(0, 0, border, border), c2.AddBorders(0, 0, 0, border)), StackHorizontal(c3.AddBorders(0, 0, border, 0), c4))
  6.     ShowTime(offset_f=-start, x=Width(last)/2, y=Height(last)/2+13, size=18.0, text_color=$00FFFFFF, font="Arial")
  7. }
  8.  
  9. # Standardized subtitle
  10. function HeaderText(clip c, string text, int align, int x, int y, int "start", int "end")
  11. {
  12.     start = Default(start, 0)
  13.     end = Default(end, FrameCount(c)-1)
  14.     Subtitle(c, text, align=align, size=20.0, text_color=$00FFFFFF, font="Upheaval TT (BRK)", x=x, y=y, first_frame=start, last_frame=end)
  15. }
  16.  
  17. # Prepare race video
  18. function Race(clip video, string name, bool detect, bool top)
  19. {
  20.     # Normalize video format
  21.     height = 640.0 / Width(video) * Height(video)
  22.     video = video.ChangeFPS(30).BilinearResize(640, Int(height))
  23.     trim = (360 - Height(video)) / 2
  24.     video = (trim > 0) ? video.Crop(0, trim, 0, -trim) : video.AddBorders(0, trim, 0, trim)
  25.    
  26.     # Add header
  27.     header = ImageSource("..\header.png", 0, FrameCount(video)-1, 30).ConvertToYV12()
  28.     video = top ? StackVertical(header, video) : StackVertical(video, header)
  29.  
  30.     global levelX = 32
  31.     global deathX = Width(video)-38
  32.     global headerY = top ? 0 : Height(video)-24
  33.     video = video.HeaderText(name, 8, -1, headerY)
  34.    
  35.     # Detect death and level transitions
  36.     global levelString = "2-%.0fX"
  37.     global bossString = "2-BOSS"
  38.     global deathString = "%.0f"
  39.    
  40.     global levelLuma = 18.0
  41.     global levelLength = 6
  42.     global deathDiff = 10.0
  43.     global deathLuma = 25.0
  44.     global deathLength = 1
  45.    
  46.     global started = true
  47.     global levelTransition = false
  48.     global deathTransition = false
  49.     global levelDuration = 0
  50.     global deathDuration = 0
  51.     global deaths = 0
  52.     global level = 1
  53.    
  54.     detect ?\
  55.     ScriptClip(video,"""diff = YDifferenceFromPrevious()
  56.                         luma = AverageLuma()
  57.                         deathTransition = (diff > deathDiff && luma < deathLuma)
  58.                         levelTransition = (luma < levelLuma && !deathTransition)
  59.                         level =  (!levelTransition && levelDuration >= levelLength && levelDuration <= levelLength*3) ? level + 1 : level
  60.                         deaths = (!deathTransition && deathDuration == deathLength) ? deaths + 1 : deaths
  61.                         levelDuration = (levelTransition) ? levelDuration + 1 : 0
  62.                         deathDuration = (deathTransition) ? deathDuration + 1 : 0
  63.                        
  64.                         HeaderText(String(level, levelString), 7, levelX, headerY)
  65.                         HeaderText(String(deaths, deathString), 7, deathX, headerY)"""):\
  66.     video.HeaderText("-", 7, levelX, headerY).HeaderText("-", 7, deathX, headerY)
  67.     #ScriptClip(video, """Subtitle("diff:"+String(YDifferenceFromPrevious)+" avg:"+String(AverageLuma), y=30)""")
  68. }
Add Comment
Please, Sign In to add comment