Convert series of images to a video, similar to images_to_video, but provide more suitable parameters. Args: input_folder (str): input image folder. output_path (str): output gif file path. remove_raw_file (bool, optional): whether remove raw images. Defa
(
input_folder: str,
output_path: str,
remove_raw_file: bool = False,
img_format: str = '%06d.png',
fps: int = 15,
resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None,
start: int = 0,
end: Optional[int] = None,
disable_log: bool = False,
)
| 777 | |
| 778 | |
| 779 | def images_to_gif( |
| 780 | input_folder: str, |
| 781 | output_path: str, |
| 782 | remove_raw_file: bool = False, |
| 783 | img_format: str = '%06d.png', |
| 784 | fps: int = 15, |
| 785 | resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, |
| 786 | start: int = 0, |
| 787 | end: Optional[int] = None, |
| 788 | disable_log: bool = False, |
| 789 | ) -> None: |
| 790 | """Convert series of images to a video, similar to images_to_video, but |
| 791 | provide more suitable parameters. |
| 792 | |
| 793 | Args: |
| 794 | input_folder (str): input image folder. |
| 795 | output_path (str): output gif file path. |
| 796 | remove_raw_file (bool, optional): whether remove raw images. |
| 797 | Defaults to False. |
| 798 | img_format (str, optional): format to name the images. |
| 799 | Defaults to '%06d.png'. |
| 800 | fps (int, optional): output video fps. Defaults to 15. |
| 801 | resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]], |
| 802 | optional): (height, width) of output. Defaults to None. |
| 803 | start (int, optional): start frame index. Inclusive. |
| 804 | If < 0, will be converted to frame_index range in [0, frame_num]. |
| 805 | Defaults to 0. |
| 806 | end (int, optional): end frame index. Exclusive. |
| 807 | Could be positive int or negative int or None. |
| 808 | If None, all frames from start till the last frame are included. |
| 809 | Defaults to None. |
| 810 | disable_log (bool, optional): whether close the ffmepg command info. |
| 811 | Defaults to False. |
| 812 | Raises: |
| 813 | FileNotFoundError: check the input path. |
| 814 | FileNotFoundError: check the output path. |
| 815 | |
| 816 | Returns: |
| 817 | None |
| 818 | """ |
| 819 | input_folderinfo = Path(input_folder) |
| 820 | check_input_path( |
| 821 | input_folder, |
| 822 | allowed_suffix=[], |
| 823 | tag='input image folder', |
| 824 | path_type='dir') |
| 825 | prepare_output_path( |
| 826 | output_path, |
| 827 | allowed_suffix=['.gif'], |
| 828 | tag='output gif', |
| 829 | path_type='file', |
| 830 | overwrite=True) |
| 831 | num_frames = len(os.listdir(input_folder)) |
| 832 | start = (min(start, num_frames - 1) + num_frames) % num_frames |
| 833 | end = (min(end, num_frames - 1) + |
| 834 | num_frames) % num_frames if end is not None else num_frames |
| 835 | temp_input_folder = None |
| 836 | if img_format is None: |
no test coverage detected