Skip to content

Instantly share code, notes, and snippets.

@catichenor
Last active February 21, 2018 06:06
Show Gist options
  • Save catichenor/87868e35c13e4b0586b29f38e04d1c7f to your computer and use it in GitHub Desktop.
Save catichenor/87868e35c13e4b0586b29f38e04d1c7f to your computer and use it in GitHub Desktop.
Frame range calculator
# This is my frame range calculator. There are many like it, but this one is mine.
# Python 2 and 3 compatible. The division method becomes less optimal as the number increases, but
# it works for the use case of relatively small numbers of divisions (up to a few dozen).
import math
import argparse
argparser = argparse.ArgumentParser()
argparser.add_argument('first_frame', type=int, help='first frame')
argparser.add_argument('last_frame', type=int, help='last frame')
argparser.add_argument('divisions', type=int, help='number of divisions')
args = argparser.parse_args()
def get_range(num_frames, first_frame, last_frame, multiple):
begin = (num_frames * multiple) + first_frame
end = num_frames * (multiple + 1) + first_frame - 1
if end > last_frame:
end = last_frame
return (int(begin), int(end))
first = args.first_frame
last = args.last_frame
divisions = args.divisions
frames = last - first
num_frames = math.ceil(float(frames) / float(divisions))
ranges = [get_range(num_frames, first, last, x) for x in range(divisions)]
for x in ranges:
print('{}-{}'.format(x[0],x[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment