def combine_images(fol, movie_name, frame_rate=10, start_number=-1, images_prefix='', images_format='', images_type='', ffmpeg_cmd='ffmpeg', **kwargs): if images_type == '': images_types = set([utils.file_type(image) for image in glob.glob(op.join(fol, '{}*.*'.format(images_prefix)))]) for opt_type in ['png', 'jpg', 'bmp', 'gif']: if opt_type in images_types: images_type = opt_type print('Images type is {}'.format(images_type)) break if images_type == '': raise Exception("Can't find the images type!") images = glob.glob(op.join(fol, '{}*.{}'.format(images_prefix, images_type))) image_nb = utils.namebase(images[0]) number = utils.read_numbers_rx(image_nb)[0] if images_prefix == '': images_prefix = image_nb[:-len(number)] if images_format == '': images_format = '%0{}d'.format(len(number)) if start_number == -1: start_number = min([int(utils.namebase(image)[len(images_prefix):]) for image in images]) images_prefix = op.join(fol, images_prefix) movie_name = op.join(fol, movie_name) combine_images_cmd = '{ffmpeg_cmd} -framerate {frame_rate} ' if start_number > 1: # You might want to use a static ffmpeg if your ffmepg version doesn't support the start_number flag, like: # ffmpeg_cmd = '~/space1/Downloads/ffmpeg-git-static/ffmpeg' combine_images_cmd += '-start_number {start_number} ' combine_images_cmd += '-i {images_prefix}{images_format}.{images_type} ' # http://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2 combine_images_cmd += '-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" ' combine_images_cmd += '-c:v libx264 -r 30 -pix_fmt yuv420p {movie_name}.mp4' rs = utils.partial_run_script(locals()) rs(combine_images_cmd)
def find_images_props(fol, start_number=-1, images_prefix='', images_format='', images_type=''): if images_type == '': images_types = set([ utils.file_type(image) for image in glob.glob(op.join(fol, '{}*.*'.format(images_prefix))) ]) for opt_type in ['png', 'jpg', 'jpeg', 'bmp', 'gif']: if opt_type in images_types: images_type = opt_type print('Images type is {}'.format(images_type)) break if images_type == '': raise Exception("Can't find the images type!") images = glob.glob( op.join(fol, '{}*.{}'.format(images_prefix, images_type))) image_nb = utils.namebase(images[0]) number = utils.read_numbers_rx(image_nb)[0] if images_prefix == '': images_prefix = image_nb[:-len(number)] if images_format == '': images_format = '%0{}d'.format(len(number)) if start_number == -1: start_number = min([ int(utils.namebase(image)[len(images_prefix):]) for image in images ]) return images_type, images_prefix, images_format, len(number), start_number
def combine_images(fol, movie_name, frame_rate=10, start_number=-1, images_prefix='', images_format='', images_type='', ffmpeg_cmd='ffmpeg', **kwargs): if images_type == '': images_types = set([ utils.file_type(image) for image in glob.glob(op.join(fol, '{}*.*'.format(images_prefix))) ]) for opt_type in ['png', 'jpg', 'bmp', 'gif']: if opt_type in images_types: images_type = opt_type print('Images type is {}'.format(images_type)) break if images_type == '': raise Exception("Can't find the images type!") images = glob.glob( op.join(fol, '{}*.{}'.format(images_prefix, images_type))) image_nb = utils.namebase(images[0]) number = utils.read_numbers_rx(image_nb)[0] if images_prefix == '': images_prefix = image_nb[:-len(number)] if images_format == '': images_format = '%0{}d'.format(len(number)) if start_number == -1: start_number = min([ int(utils.namebase(image)[len(images_prefix):]) for image in images ]) images_prefix = op.join(fol, images_prefix) movie_name = op.join(fol, movie_name) combine_images_cmd = '{ffmpeg_cmd} -framerate {frame_rate} ' if start_number > 1: # You might want to use a static ffmpeg if your ffmepg version doesn't support the start_number flag, like: # ffmpeg_cmd = '~/space1/Downloads/ffmpeg-git-static/ffmpeg' combine_images_cmd += '-start_number {start_number} ' combine_images_cmd += '-i {images_prefix}{images_format}.{images_type} ' # http://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2 combine_images_cmd += '-vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" ' combine_images_cmd += '-c:v libx264 -r 30 -pix_fmt yuv420p {movie_name}.mp4' rs = utils.partial_run_script(locals()) rs(combine_images_cmd)