VideoManager.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Albireo 作者: lordfriend 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号