1
When using the command
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 smoothly. How do I get around this problem?
The project is on github https://github.com/flavioribeiro/video-thumbnail-generator
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)
Your error seems to be quite simple: you have many files open at the same time! If you are generating temporary files with each frame of the video and keeping them all open, it will be crazy (imagine a video recorded in 30 frames per second... with 10 minutes of video you have 18 thousand files open! ). Post the relevant code here that makes it easier to help you (maybe from the function
generate_video_thumbnail
is enough? ). You can even keep the github link, but the question has to have all the details.– Luiz Vieira
I made the changes, put in other functions that I believe have relevance
– Guilherme Pichok