三、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)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章