MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / vid_info_reader

Class vid_info_reader

detrsmpl/utils/ffmpeg_utils.py:492–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490
491
492class 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
549def video_to_gif(

Callers 8

render_smplFunction · 0.90
video_to_arrayFunction · 0.85
images_to_arrayFunction · 0.85
video_to_gifFunction · 0.85
video_to_imagesFunction · 0.85
crop_videoFunction · 0.85
slice_videoFunction · 0.85
compress_videoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected