Convert a gif file to a folder of images. Args: input_path (str): input gif file path. output_folder (str): output folder to save the images. fps (int, optional): fps. Defaults to 30. img_format (str, optional): output image name format. Defaults to '
(input_path: str,
output_folder: str,
fps: int = 30,
img_format: str = '%06d.png',
resolution: Optional[Union[Tuple[int, int],
Tuple[float, float]]] = None,
disable_log: bool = False)
| 939 | |
| 940 | |
| 941 | def gif_to_images(input_path: str, |
| 942 | output_folder: str, |
| 943 | fps: int = 30, |
| 944 | img_format: str = '%06d.png', |
| 945 | resolution: Optional[Union[Tuple[int, int], |
| 946 | Tuple[float, float]]] = None, |
| 947 | disable_log: bool = False) -> None: |
| 948 | """Convert a gif file to a folder of images. |
| 949 | |
| 950 | Args: |
| 951 | input_path (str): input gif file path. |
| 952 | output_folder (str): output folder to save the images. |
| 953 | fps (int, optional): fps. Defaults to 30. |
| 954 | img_format (str, optional): output image name format. |
| 955 | Defaults to '%06d.png'. |
| 956 | resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]], |
| 957 | optional): (height, width) of output. |
| 958 | Defaults to None. |
| 959 | disable_log (bool, optional): whether close the ffmepg command info. |
| 960 | Defaults to False. |
| 961 | Raises: |
| 962 | FileNotFoundError: check the input path. |
| 963 | FileNotFoundError: check the output path. |
| 964 | |
| 965 | Returns: |
| 966 | None |
| 967 | """ |
| 968 | check_input_path( |
| 969 | input_path, allowed_suffix=['.gif'], tag='input gif', path_type='file') |
| 970 | prepare_output_path( |
| 971 | output_folder, |
| 972 | allowed_suffix=[], |
| 973 | tag='output image folder', |
| 974 | path_type='dir', |
| 975 | overwrite=True) |
| 976 | command = [ |
| 977 | 'ffmpeg', '-r', f'{fps}', '-i', input_path, '-loglevel', 'error', '-f', |
| 978 | 'image2', '-v', 'error', '-threads', '4', '-y', '-start_number', '0', |
| 979 | f'{output_folder}/{img_format}' |
| 980 | ] |
| 981 | if resolution: |
| 982 | height, width = resolution |
| 983 | command.insert(3, '-s') |
| 984 | command.insert(4, '%dx%d' % (width, height)) |
| 985 | if not disable_log: |
| 986 | print(f'Running \"{" ".join(command)}\"') |
| 987 | subprocess.call(command) |
| 988 | |
| 989 | |
| 990 | def crop_video( |
nothing calls this directly
no test coverage detected