Pio*_*ski 11
如何使用python-ffmpeg:
import ffmpeg
probe = ffmpeg.probe(movie_path)
video_streams = [stream for stream in probe["streams"] if stream["codec_type"] == "video"]
Run Code Online (Sandbox Code Playgroud)
它为您提供了一个非常好的输出,如下所示:
>>> 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}
Run Code Online (Sandbox Code Playgroud)
唯一的缺点是需要 ffmpeg,但这在大多数情况下应该不是问题。
oma*_*al8 10
如果我理解正确,你的意思是视频的分辨率,例如(768x432).
这可以简单地在python中使用opencv来完成.
import cv2
file_path = "./video.avi" # change to your own video path
vid = cv2.VideoCapture(file_path)
height = vid.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = vid.get(cv2.CAP_PROP_FRAME_WIDTH)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15908 次 |
| 最近记录: |