| 490 | |
| 491 | |
| 492 | class vid_info_reader(object): |
| 493 | |
| 494 | def __init__(self, input_path) -> None: |
| 495 | """Get video information from video, mimiced from ffmpeg-python. |
| 496 | https://github.com/kkroening/ffmpeg-python. |
| 497 | |
| 498 | Args: |
| 499 | vid_file ([str]): video file path. |
| 500 | |
| 501 | Raises: |
| 502 | FileNotFoundError: check the input path. |
| 503 | |
| 504 | Returns: |
| 505 | None. |
| 506 | """ |
| 507 | check_input_path( |
| 508 | input_path, |
| 509 | allowed_suffix=['.mp4', '.gif', '.png', '.jpg', '.jpeg'], |
| 510 | tag='input file', |
| 511 | path_type='file') |
| 512 | cmd = [ |
| 513 | 'ffprobe', '-show_format', '-show_streams', '-of', 'json', |
| 514 | input_path |
| 515 | ] |
| 516 | process = subprocess.Popen( |
| 517 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 518 | out, _ = process.communicate() |
| 519 | probe = json.loads(out.decode('utf-8')) |
| 520 | video_stream = next((stream for stream in probe['streams'] |
| 521 | if stream['codec_type'] == 'video'), None) |
| 522 | if video_stream is None: |
| 523 | print('No video stream found', file=sys.stderr) |
| 524 | sys.exit(1) |
| 525 | self.video_stream = video_stream |
| 526 | |
| 527 | def __getitem__( |
| 528 | self, |
| 529 | key: Literal['index', 'codec_name', 'codec_long_name', 'profile', |
| 530 | 'codec_type', 'codec_time_base', 'codec_tag_string', |
| 531 | 'codec_tag', 'width', 'height', 'coded_width', |
| 532 | 'coded_height', 'has_b_frames', 'pix_fmt', 'level', |
| 533 | 'chroma_location', 'refs', 'is_avc', 'nal_length_size', |
| 534 | 'r_frame_rate', 'avg_frame_rate', 'time_base', |
| 535 | 'start_pts', 'start_time', 'duration_ts', 'duration', |
| 536 | 'bit_rate', 'bits_per_raw_sample', 'nb_frames', |
| 537 | 'disposition', 'tags']): |
| 538 | """Key (str): select in ['index', 'codec_name', 'codec_long_name', |
| 539 | 'profile', 'codec_type', 'codec_time_base', 'codec_tag_string', |
| 540 | 'codec_tag', 'width', 'height', 'coded_width', 'coded_height', |
| 541 | 'has_b_frames', 'pix_fmt', 'level', 'chroma_location', 'refs', |
| 542 | 'is_avc', 'nal_length_size', 'r_frame_rate', 'avg_frame_rate', |
| 543 | 'time_base', 'start_pts', 'start_time', 'duration_ts', 'duration', |
| 544 | 'bit_rate', 'bits_per_raw_sample', 'nb_frames', 'disposition', |
| 545 | 'tags']""" |
| 546 | return self.video_stream[key] |
| 547 | |
| 548 | |
| 549 | def video_to_gif( |
no outgoing calls
no test coverage detected