Compress a video file. Args: input_path (str): input video file path. output_path (str): output video file path. compress_rate (int, optional): compress rate, influents the bit rate. Defaults to 1. down_sample_scale (Union[float, int], optional): spat
(input_path: str,
output_path: str,
compress_rate: int = 1,
down_sample_scale: Union[float, int] = 1,
fps: int = 30,
disable_log: bool = False)
| 1260 | |
| 1261 | |
| 1262 | def compress_video(input_path: str, |
| 1263 | output_path: str, |
| 1264 | compress_rate: int = 1, |
| 1265 | down_sample_scale: Union[float, int] = 1, |
| 1266 | fps: int = 30, |
| 1267 | disable_log: bool = False) -> None: |
| 1268 | """Compress a video file. |
| 1269 | |
| 1270 | Args: |
| 1271 | input_path (str): input video file path. |
| 1272 | output_path (str): output video file path. |
| 1273 | compress_rate (int, optional): compress rate, influents the bit rate. |
| 1274 | Defaults to 1. |
| 1275 | down_sample_scale (Union[float, int], optional): spatial down sample |
| 1276 | scale. Defaults to 1. |
| 1277 | fps (int, optional): Frames per second. Defaults to 30. |
| 1278 | disable_log (bool, optional): whether close the ffmepg command info. |
| 1279 | Defaults to False. |
| 1280 | Raises: |
| 1281 | FileNotFoundError: check the input path. |
| 1282 | FileNotFoundError: check the output path. |
| 1283 | |
| 1284 | Returns: |
| 1285 | None. |
| 1286 | """ |
| 1287 | input_pathinfo = Path(input_path) |
| 1288 | |
| 1289 | check_input_path( |
| 1290 | input_path, |
| 1291 | allowed_suffix=['.gif', '.mp4'], |
| 1292 | tag='input video', |
| 1293 | path_type='file') |
| 1294 | prepare_output_path( |
| 1295 | output_path, |
| 1296 | allowed_suffix=['.gif', '.mp4'], |
| 1297 | tag='output video', |
| 1298 | path_type='file', |
| 1299 | overwrite=True) |
| 1300 | |
| 1301 | info = vid_info_reader(input_path) |
| 1302 | |
| 1303 | width = int(info['width']) |
| 1304 | height = int(info['height']) |
| 1305 | bit_rate = int(info['bit_rate']) |
| 1306 | duration = float(info['duration']) |
| 1307 | if (output_path == input_path) or (not output_path): |
| 1308 | temp_outpath = os.path.join( |
| 1309 | os.path.abspath(input_pathinfo.parent), |
| 1310 | 'temp_file' + input_pathinfo.suffix) |
| 1311 | else: |
| 1312 | temp_outpath = output_path |
| 1313 | new_width = int(width / down_sample_scale) |
| 1314 | new_width += new_width % 2 |
| 1315 | new_height = int(height / down_sample_scale) |
| 1316 | new_height += new_height % 2 |
| 1317 | command = [ |
| 1318 | 'ffmpeg', '-y', '-r', |
| 1319 | str(info['r_frame_rate']), '-i', input_path, '-loglevel', 'error', |
nothing calls this directly
no test coverage detected