When using the
python generator video.mp4 2 150 80 10 thumbnails.jpg
I have the following return
Extracting 734 frames
[####################################] 100%
Frames extracted.
Traceback (most recent call last):
File "generator", line 90, in <module>
generate_video_thumbnail(arguments)
File "generator", line 39, in generate_video_thumbnail
generate_sprite_from_frames(outputPrefix, columns, size, output)
File "generator", line 62, in generate_sprite_from_frames
images = [Image.open(filename) for filename in framesMap]
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2312, in open
fp = builtins.open(filename, "rb")
IOError: [Errno 24] Too many open files: 'c:\users\gpich\appdata\local\temp\tmpellfxjf728913fdda8373761ccb51c69fe51d5_00497.png'
When I need to generate smaller numbers of thumbnails, it generates without problems. How do I get around this?
The project is in github link
below the some functions relevant to the generation
def generate_video_thumbnail(args):
videoFileClip = VideoFileClip(args['<video>'])
interval = int(args['<interval>'])
size = (int(args['<width>']), int(args['<height>']))
outputPrefix = get_output_prefix()
generate_frames(videoFileClip, interval, outputPrefix, size)
columns = int(args['<columns>'])
output = args['<output>']
generate_sprite_from_frames(outputPrefix, columns, size, output)
def extract_frame(videoFileClip, moment, outputPrefix, size, frameCount):
output = outputPrefix + ("%05d.png" % frameCount)
videoFileClip.save_frame(output, t=int(moment))
resize_frame(output, size)
def resize_frame(filename, size):
image = Image.open(filename)
image = image.resize(size, Image.ANTIALIAS)
image.save(filename)
def generate_sprite_from_frames(framesPath, columns, size, output):
framesMap = sorted(glob.glob(framesPath + "*.png"))
images = [Image.open(filename) for filename in framesMap]
masterWidth = size[0] * columns
masterHeight = size[1] * int(math.ceil(float(len(images)) / columns))
finalImage = Image.new(mode='RGBA', size=(masterWidth, masterHeight), color=(0,0,0,0))
merge_frames(images, finalImage, columns, size, output)