def get_video_meta(self, video_path):
'''
get video meta information
:param video_path: the absolute path of video file
:return: a dictionary
{
'width': integer,
'height': integer,
'duration': integer (millisecond)
}
if an error occurred, this method will return None
'''
try:
output = subprocess.check_output([
'ffprobe',
'-v',
'error',
'-show_entries',
'format=duration:stream=width:stream=height',
'-select_streams',
'v:0',
'-of',
'json',
b'{0}'.format(video_path.encode('utf-8'))
])
meta = json.loads(output)
result = {}
if 'format' in meta and 'duration' in meta['format']:
result['duration'] = int(float(meta['format']['duration']) * 1000)
if 'streams' in meta and len(meta['streams']) and 'width' in meta['streams'][0] and 'height' in meta['streams'][0]:
result['width'] = meta['streams'][0]['width']
result['height'] = meta['streams'][0]['height']
return result
except subprocess.CalledProcessError as error:
logger.error(error)
return None
评论列表
文章目录