Python3 代码多视频格式支持:获取视频信息
Python3 代码多视频格式支持:获取视频信息
为了增加多视频格式支持,可以在使用 mediainfo 获取视频信息时,增加对其他格式的支持。需要根据不同视频格式,调整 mediainfo 命令中的参数和输出格式。例如:
- 增加对 .mkv 格式的支持:
# 之前的代码
if video_file.endswith('.mkv'):
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String% %/s|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
else:
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
# 之后的代码
- 增加对 .avi 格式的支持:
# 之前的代码
if video_file.endswith('.mkv'):
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String% %/s|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
elif video_file.endswith('.avi'):
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
else:
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
# 之后的代码
- 增加对 .flv 格式的支持:
# 之前的代码
if video_file.endswith('.mkv'):
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String% %/s|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
elif video_file.endswith('.avi'):
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
elif video_file.endswith('.flv'):
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
else:
video_result = subprocess.run(['mediainfo', '--Inform=Video;%Format%|%Width%x%Height%|%BitRate/String%|%FrameRate%|%Duration/String3%', video_file], stdout=subprocess.PIPE)
# 之后的代码
需要根据实际情况,增加对应视频格式的支持。
原文地址: https://www.cveoy.top/t/topic/mAlX 著作权归作者所有。请勿转载和采集!