Spatially or temporally crop a video or gif file. Args: input_path (str): input video or gif file path. output_path (str): output video or gif file path. box (Iterable[int], optional): [x, y of the crop region left. corner and width and height]. Defaults to [
(
input_path: str,
output_path: str,
box: Optional[Union[List[int], Tuple[int, int, int, int]]] = None,
resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None,
disable_log: bool = False,
)
| 988 | |
| 989 | |
| 990 | def crop_video( |
| 991 | input_path: str, |
| 992 | output_path: str, |
| 993 | box: Optional[Union[List[int], Tuple[int, int, int, int]]] = None, |
| 994 | resolution: Optional[Union[Tuple[int, int], Tuple[float, float]]] = None, |
| 995 | disable_log: bool = False, |
| 996 | ) -> None: |
| 997 | """Spatially or temporally crop a video or gif file. |
| 998 | |
| 999 | Args: |
| 1000 | input_path (str): input video or gif file path. |
| 1001 | output_path (str): output video or gif file path. |
| 1002 | box (Iterable[int], optional): [x, y of the crop region left. |
| 1003 | corner and width and height]. Defaults to [0, 0, 100, 100]. |
| 1004 | resolution (Optional[Union[Tuple[int, int], Tuple[float, float]]], |
| 1005 | optional): (height, width) of output. Defaults to None. |
| 1006 | disable_log (bool, optional): whether close the ffmepg command info. |
| 1007 | Defaults to False. |
| 1008 | Raises: |
| 1009 | FileNotFoundError: check the input path. |
| 1010 | FileNotFoundError: check the output path. |
| 1011 | |
| 1012 | Returns: |
| 1013 | None'-start_number', f'{start}', |
| 1014 | """ |
| 1015 | check_input_path( |
| 1016 | input_path, |
| 1017 | allowed_suffix=['.gif', '.mp4'], |
| 1018 | tag='input video', |
| 1019 | path_type='file') |
| 1020 | prepare_output_path( |
| 1021 | output_path, |
| 1022 | allowed_suffix=['.gif', '.mp4'], |
| 1023 | tag='output video', |
| 1024 | path_type='file', |
| 1025 | overwrite=True) |
| 1026 | |
| 1027 | info = vid_info_reader(input_path) |
| 1028 | width, height = int(info['width']), int(info['height']) |
| 1029 | |
| 1030 | if box is None: |
| 1031 | box = [0, 0, width, height] |
| 1032 | |
| 1033 | assert len(box) == 4 |
| 1034 | x, y, w, h = box |
| 1035 | assert (w > 0 and h > 0) |
| 1036 | command = [ |
| 1037 | 'ffmpeg', '-i', input_path, '-vcodec', 'libx264', '-vf', |
| 1038 | 'crop=%d:%d:%d:%d' % (w, h, x, y), '-loglevel', 'error', '-y', |
| 1039 | output_path |
| 1040 | ] |
| 1041 | if resolution: |
| 1042 | height, width = resolution |
| 1043 | width += width % 2 |
| 1044 | height += height % 2 |
| 1045 | command.insert(-1, '-s') |
| 1046 | command.insert(-1, '%dx%d' % (width, height)) |
| 1047 | if not disable_log: |
nothing calls this directly
no test coverage detected