三、ffmpeg获取视频信息

获取信息是视频编解码的基础,ffmpeg提供了非常方便的获取信息的方式,代码也比较简单.我就直接贴出来了

import ffmpeg
import sys

# 执行probe执行
probe = ffmpeg.probe("dummy1.mp4")
video_stream = next((stream for stream in probe['streams'] if stream['codec_type'] == 'video'), None)
if video_stream is None:
    print('No video stream found', file=sys.stderr)
    sys.exit(1)
# 宽度
width = int(video_stream['width'])
# 高度
height = int(video_stream['height'])
# 帧数
num_frames = int(video_stream['nb_frames'])
# 时长
time = (video_stream['duration'])
# 比特率
bitrate = (video_stream['bit_rate'])

print('width: {}'.format(width))
print('height: {}'.format(height))
print('num_frames: {}'.format(num_frames))
print('time: {}'.format(time))
print('bitrate: {}'.format(bitrate))

# 查看全部信息
print(video_stream)


博主开发的第三方CSDN客户端.体验很棒哦,快来体验下载吧
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/aa375809600/article/details/84521203