#!/usr/bin/python # Python script to tranlate black frame listing produced by mencoder with # "-vf blackframe" into a list of times suitable for use as a chapter list # with dvdauthor. # Feel free to redistribute, modify, or do whatever you want to do with this # file. I don't care. import sys framerate = 25.0 threshold_length = 10 data = "0" lasttime = ["00", "00", "00"] def secs_diff (time1, time2): return (int(time2[2]) - int(time1[2])) + 60*(int(time2[1]) - int(time1[1])) + 3600*(int(time2[0]) - int(time1[0])) def time_from_frame (frameno): seconds = frameno / framerate intsec = int(seconds) thou = int((seconds - intsec) * 1000) hours = intsec / 3600 minutes = (intsec / 60) % 60 seconds = intsec % 60 return "%02d:%02d:%02d.%03d" % (hours, minutes, seconds, thou) groupstart = -2 grouplen = 0 if len(sys.argv) > 1: framerate = float(sys.argv[1]) if len(sys.argv) > 2: threshold_length = int(sys.argv[2]) for line in sys.stdin: if line[0:12] != "Black frame:": continue splitln = line.strip().split (' ') if len(splitln) < 5: print "malformed line: " + line continue frameno = int(splitln[3]) #print frameno,groupstart,grouplen if frameno != groupstart + grouplen + 1: if grouplen > threshold_length: time = time_from_frame (groupstart + grouplen/2) th = time.split('.') timea = th[0].split (':') if secs_diff (lasttime, timea) < 30: print "skipping " + time + " (delta t = " + repr(secs_diff (lasttime, timea)) + ")" else: print "group from " + str(groupstart) + " (" + time_from_frame(groupstart) + ") to " + str(groupstart+grouplen) + " (" + time_from_frame(groupstart+grouplen) + ")" if time.startswith("00:"): time = time[3:] data += ", " + time lasttime = timea groupstart = frameno grouplen = 0 else: grouplen = grouplen + 1 print data