import os
BLACK_FRAME_SIZE = 5124

def move():
	files = os.listdir('tmp')
	files = [f for f in files if not os.path.isdir('tmp/'+f)]
	files = sorted(files)

	sizes = []
	for f in files:
		sizes += [os.path.getsize('tmp/' + f)]
		
	prev = 0
	for i, s in enumerate(sizes):
		if prev == sizes[i] and sizes[i] != BLACK_FRAME_SIZE:
			print files[i]
			os.rename('tmp/' + files[i], 'tmp/mv/'+files[i])
			
			print 'MOVING'
			for j in xrange(i+1, len(files)):
				from_ = files[j]
				to_ = files[j-1]
				os.rename('tmp/' + from_, 'tmp/' + to_)
			
			return True
			
		prev = s
		
	return False
	
	
if not os.path.exists('tmp/mv'):
    os.makedirs('tmp/mv')
	
total = 0
while move():
	total += 1
print 'Total still frames', total