def mosh(self):
    if self.to_mosh is None:
      return False
    else:
      for avi_filename in self.to_mosh:
        moshed_avi_filename = avi_filename.replace('.avi','_moshed.avi')
        msg = '{0}Creating moshed movie:\n{1}{0}'.format(HR, moshed_avi_filename)
        if IS_TTY: print hilite(msg,15)
        input_avi = os.path.join(self.outdir, avi_filename)
        moshed_avi = os.path.join(self.outdir, moshed_avi_filename) 
        # by johannesgj
        # https://github.com/grampajoe/pymosh/blob/master/examples/moshmotion.py
        # loads in the index of frames in the given avi file
        f = Index(input_avi)
        # So I can assign to the closed-over buffer
        buf = [None]
      
        def process_frame(frame):
          """Process a frame, holding onto one P-frame at a time,
          which is used to replace any I-frames encountered."""
          # if there is no frame in buf or the frame is not i-frame
          if buf[0] == None or not is_iframe(frame):
            # then buf is the seen p-frame
            buf[0] = frame
          else:
            # if it IS an iframe then use the buf'ers pframe
            frame = buf[0]
          # return the frame
          return frame
      
        # we use the list of frames in the loaded file
        for stream in f.video:
          # make a new list to put in frames YOU decide
          newstream = []
          # append it with a i-frame to make it load fine in video player
          newstream.append(stream[0])
          # two variables for counting frames and interval
          ix = 0
          jx = 0
          # stream is reduced by one since we have allready added one frame above
          for i in stream[1:]:
            ix += 1
            jx += 1
            # if ix the counter of interval is < interval select normal frames
            if ix < self.interval:
              newstream.append(process_frame(stream[jx]))
            # else bleed the reached frame for interval time
            else:
              newstream.append(newstream[-1])
            # init interval
            if self.interval * 2 > ix:
              ix = 0
          # replace original stream with same length newstream
          stream.replace(newstream)
      
        # Call rebuild to recombine the modified streams and perform any other
        # maintenance the file format needs for clean output.
        f.rebuild()
      
        # Finally, write the modified file .
        f.write(moshed_avi)
        self.moshed.append(moshed_avi_filename)
dataset/ETHPy150Open robmoggach/python-moshion/moshion/core.py/Moshion.mosh/swapped operands of `>`