Get dimensions of a video file

前端 未结 8 2060
情歌与酒
情歌与酒 2020-12-01 09:39

Is there a way in python to get the dimensions of a video file or some other library that would accomplish this? The equivalent of a Media Info or something? Th

相关标签:
8条回答
  • 2020-12-01 10:08

    This library seems to have an example that does just that on its main page (print_info(vs)):

    http://code.google.com/p/ffvideo/

    It's a wrapper around ffmpeg (there seems to be a few Python libraries for using ffmpeg).

    0 讨论(0)
  • 2020-12-01 10:08

    How about using python-ffmpeg:

    import ffmpeg
    probe = ffmpeg.probe(movie_path)
    video_streams = [stream for stream in probe["streams"] if stream["codec_type"] == "video"]
    

    It gives you a very nice output like this:

    >>> import pprint
    >>> pprint.pprint(video_streams[0])
    {'avg_frame_rate': '30/1',
     'bit_rate': '3291',
     'bits_per_raw_sample': '8',
     'chroma_location': 'left',
     'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10',
     'codec_name': 'h264',
     'codec_tag': '0x31637661',
     'codec_tag_string': 'avc1',
     'codec_time_base': '1/60',
     'codec_type': 'video',
     'coded_height': 240,
     'coded_width': 320,
     'color_primaries': 'bt709',
     'color_range': 'tv',
     'color_space': 'bt709',
     'color_transfer': 'bt709',
     'display_aspect_ratio': '4:3',
     'disposition': {'attached_pic': 0,
                     'clean_effects': 0,
                     'comment': 0,
                     'default': 1,
                     'dub': 0,
                     'forced': 0,
                     'hearing_impaired': 0,
                     'karaoke': 0,
                     'lyrics': 0,
                     'original': 0,
                     'timed_thumbnails': 0,
                     'visual_impaired': 0},
     'duration': '71.833333',
     'duration_ts': 6465000,
     'field_order': 'progressive',
     'has_b_frames': 1,
     'height': 240,
     'index': 0,
     'is_avc': 'true',
     'level': 13,
     'nal_length_size': '4',
     'pix_fmt': 'yuv420p',
     'profile': 'Main',
     'r_frame_rate': '30/1',
     'refs': 1,
     'sample_aspect_ratio': '1:1',
     'start_pts': 0,
     'start_time': '0.000000',
     'tags': {'creation_time': '2018-10-26T04:25:07.000000Z',
              'handler_name': 'VideoHandler',
              'language': 'und'},
     'time_base': '1/90000',
     'width': 320}
    

    The only downside is that ffmpeg is required, but this should not be a problem in most of the cases.

    0 讨论(0)
提交回复
热议问题