I am looking for someone who can teach me how to segment a video file into chunks. Will appreciate it greatly if anyone decides to help me!
Here is a (python 2) function to help you. It takes an open input file as argument together with an input chunk size and an output chunk size. It generates a sequence of pairs (i, s) where i is the index of the output file where the string s must be written
def dispatched(ifh, isize, osize, start = 0): assert isize > 0 assert osize > 0 left = osize while True: s = ifh.read(isize) if not s: return while s: x = min(left, len(s)) yield (start, s[:x]) s = s[x:] left -= x if not left: left = osize start += 1 example = '''Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.''' if __name__ == '__main__': from StringIO import StringIO ifh = StringIO(example) # simulate an opened input file for item in dispatched(ifh, 20, 35, 1): print item ''' my output ---> (1, 'Python is a programm') (1, 'ing language th') (2, 'at\nle') (2, 'ts you work more qui') (2, 'ckly and i') (3, 'ntegrate y') (3, 'our systems\nmore eff') (3, 'ectiv') (4, 'ely. You can le') (4, 'arn to use Python an') (5, 'd see almost\nimmedia') (5, 'te gains in pro') (6, 'ducti') (6, 'vity and lower maint') (6, 'enance cos') (7, 'ts.') '''
We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.