Advertisement
RiCON

nonpositivetrims.patch

Jan 26th, 2012
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.34 KB | None | 0 0
  1. diff --git a/vfr.py b/vfr.py
  2. index 7ae1440..bb48b26 100755
  3. --- a/vfr.py
  4. +++ b/vfr.py
  5. @@ -177,7 +177,7 @@ def main(args):
  6.      if chapter_type:
  7.  
  8.          if chapter_type == 'MKV':
  9. -            Trims2ts = [(fmt_time(i[0]),fmt_time(i[1])) for i in Trims2ts]
  10. +            Trims2ts = [(fmt_time(i[0]),fmt_time(i[1]) if i[1] != 0 else None) for i in Trims2ts]
  11.  
  12.          if o.template:
  13.              from templates import AutoMKVChapters as amkvc
  14. @@ -489,12 +489,12 @@ def parse_avs(avs, label=None, reverse=None):
  15.      
  16.      """
  17.  
  18. -    trimre = compile("(?<!#)trim\((\d+)\s*,\s*(\d+)\)(?i)")
  19. +    trimre = compile("(?<!#)trim\((\d+)\s*,\s*(-?\d+)\)(?i)")
  20.      Trims = []
  21.  
  22.      with open(avs) as avsfile:
  23.          avs = avsfile.readlines()
  24. -        findTrims = compile("(?<!#)[^#]*\s*\.?\s*{0}\((\d+)\s*,\s*(\d+)\){1}".format(label if label else "trim", "" if label else "(?i)"))
  25. +        findTrims = compile("(?<!#)[^#]*\s*\.?\s*{0}\((\d+)\s*,\s*(-?\d+)\){1}".format(label if label else "trim", "" if label else "(?i)"))
  26.          for line in avs if not reverse else reversed(avs):
  27.              if findTrims.match(line):
  28.                  Trims = trimre.findall(line)
  29. @@ -527,7 +527,13 @@ def parse_trims(avs, fps, outfps=None, otc=None, input=None, label=None, reverse
  30.      nt1 = len(Trims)
  31.  
  32.      # Parse timecodes/fps
  33. -    tc, max = parse_tc(fps, int(Trims[-1][1])+2,otc)
  34. +    last_frame = int(Trims[-1][1])
  35. +    if last_frame < 0:
  36. +        last_frame = int(Trims[-1][0]) - int(Trims[-1][1])-1
  37. +    elif last_frame == 0:
  38. +        last_frame = int(Trims[-1][0])
  39. +
  40. +    tc, max = parse_tc(fps, last_frame+2,otc)
  41.      if tc[1] == 'vfr' and outfps:
  42.          exit("Can't use --ofps with timecodes file input")
  43.      if outfps and fps != outfps:
  44. @@ -542,10 +548,22 @@ def parse_trims(avs, fps, outfps=None, otc=None, input=None, label=None, reverse
  45.          fn1ts = get_ts(fn1,tc)
  46.          fn1tsaud = get_ts(fn1,tc)
  47.          fn2 = int(Trims[i][1])
  48. -        fn2ts = get_ts(fn2+1,tc)
  49. -        fn2tsaud = get_ts(fn2+1,tc)
  50. -        adjacent = False
  51. -        Trimsts.append((fmt_time(fn1ts),fmt_time(fn2ts)))
  52. +        if fn2 > 0:
  53. +            fn2ts = get_ts(fn2+1,tc)
  54. +            fn2tsaud = get_ts(fn2+1,tc)
  55. +            adjacent = False
  56. +            Trimsts.append((fmt_time(fn1ts),fmt_time(fn2ts)))
  57. +        elif fn2 < 0:
  58. +            fn2 = fn1 - fn2-1
  59. +            print(fn2)
  60. +            fn2ts = get_ts(fn2+1,tc)
  61. +            fn2tsaud = get_ts(fn2+1,tc)
  62. +            adjacent = False
  63. +            Trimsts.append((fmt_time(fn1ts),fmt_time(fn2ts)))
  64. +        else:
  65. +            fn2ts = 0
  66. +            fn2tsaud = 0
  67. +            Trimsts.append((fmt_time(fn1ts),0))
  68.  
  69.          # Calculate offsets for non-continuous trims
  70.          if i == 0:
  71. @@ -570,14 +588,14 @@ def parse_trims(avs, fps, outfps=None, otc=None, input=None, label=None, reverse
  72.              elif fn1 <= max:
  73.                  audio.append(fmt_time(fn1tsaud))
  74.  
  75. -            if fn2 <= max:
  76. +            if fn2 <= max and fn2 != 0:
  77.                  audio.append(fmt_time(fn2tsaud))
  78.  
  79.          # Apply the offset to the trims
  80.          fn1 -= offset
  81. -        fn2 -= offset
  82. +        fn2 -= offset if fn2 else 0
  83.          fn1ts -= offsetts
  84. -        fn2ts -= offsetts
  85. +        fn2ts -= offsetts if fn2 else 0
  86.  
  87.          # Add trims and their timestamps to list
  88.          Trims2.append([fn1,fn2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement