Write a video from a folder with images.
- author: Brigitte Bigi
- contact: contact@sppas.org
Write a video from a folder with images.
Create an instance of sppasImageVideoWriter.
def __init__(self, folder):
"""Create an instance of sppasImageVideoWriter.
:param folder: (str) Input directory with images.
"""
super(sppasImageVideoWriter, self).__init__()
self.__mul = 1
self.__repeat = 1
logging.debug('Search for images in folder {}'.format(folder))
self.__all_images = list()
for img_ext in image_extensions:
img_files = sppasDirUtils.dir_entries(folder, extension=img_ext, subdir=True)
if len(img_files) > 0:
logging.debug('... found {} {} images in folder'.format(len(img_files), img_ext))
self.__all_images.extend(img_files)
else:
logging.debug(' .. no image found with extension {}'.format(img_ext))
Set the number of times to write each image.
def img_mul(self, value):
"""Set the number of times to write each image.
:param value: (int) At least 1.
"""
value = int(value)
if value < 1:
value = 1
self.__mul = value
Set the number of times to repeat the sequence of images.
def repeat(self, value):
"""Set the number of times to repeat the sequence of images.
:param value: (int) At least 1.
"""
value = int(value)
if value < 1:
value = 1
self.__repeat = value
def export(self, video_name):
"""
"""
self.open(video_name)
for r in range(self.__repeat):
for i, img_name in enumerate(sorted(self.__all_images)):
img = sppasImage(filename=img_name)
for x in range(self.__mul):
self.write(img)
if i > 0 and i % 100 == 0:
logging.debug('{:d} images added to the video'.format(i))
self.close()