def test_toggle_fractional_frame(self): tc = Timecode(24, 421729315) self.assertEqual(tc.__repr__(), '19:23:14:23') tc.set_fractional(True) self.assertEqual(tc.__repr__(), '19:23:14.958') tc.set_fractional(False) self.assertEqual(tc.__repr__(), '19:23:14:23')
def main(): """Automatically cutting a video using ffmpeg.""" parser = argparse.ArgumentParser( prog="cutter", description="Cutting videos using a decision list and FFmpeg") parser.add_argument("list", help="path to cut list") parser.add_argument("input", help="input video file") parser.add_argument("-t", "--tolerance", action="store", default=0, help="number of frames added") #parser.add_argument("basename", help="basename for the scenes") parser.add_argument("-v", "--verbose", action='store_true', help="verbose mode") args = parser.parse_args() stream = 0 output = 'scene' video_manager = VideoManager([args.input]) fps = video_manager.get_framerate() # tolerance = Timecode(fps, frames=int(args.tolerance)).frames_to_tc tolerance = int(args.tolerance) if args.verbose: print("FPS: %d" % (fps)) print(tolerance) raw = ffmpeg.input(args.input) cut_list = pandas.read_pickle(args.list) for i, scene in cut_list.iterrows(): start = re.sub(',', '.', cut_list.start[i]) end = re.sub(',', '.', cut_list.end[i]) print("%s %s" % (start, end)) start = Timecode(fps, start) - tolerance start.set_fractional(True) end = Timecode(fps, end) + tolerance end.set_fractional(True) print("%s %s" % (start, end)) if args.verbose: print(' Start %s, End %s' % (start, end)) audio = (raw.filter_('atrim', start=start, end=end).filter_('asetpts', 'PTS-STARTPTS')) video = ffmpeg.trim(raw, start=start, end=end) video = video.setpts('PTS-STARTPTS') stream = ffmpeg.concat(video, audio, v=1, a=1) stream = ffmpeg.output(stream, output + str(i) + '.mp4') stream.run()
def current(self): tc = Timecode(self.sync.fr, secs_to_hms(self.pos)) tc.set_fractional(False) return tc