ffprobe获取视频的分辨率帧数等信息

这里演示下如何用ffprobe获取视频的各种信息,ffprobe是和ffmepg一起的,不需要特别安装,只需要有ffmpeg,就自动会带ffprobe。
获取视频的分辨率:

    ffprobe_path = '/home/user/ffprobe'
    video_path = 'your_video_path'
    command = '{ffprobe_path} -v error -select_streams v:0 -show_entries stream=width,height -of json {video_path}'.format(ffprobe_path=ffprobe_path,
                                                                                                                           video_path=video_path)

    value = subprocess.check_output(command)
    data = json.loads(value)

获取视频的帧速率:

    ffprobe_path = '/home/user/ffprobe'
    video_path = 'your_video_path'
    command = '{ffprobe_path} -v error -select_streams v -show_entries stream=r_frame_rate -of json {video_path}'.format(ffprobe_path=ffprobe_path,
                                                                                                                         video_path=video_path)

    value = subprocess.check_output(command)
    data = json.loads(value)
    frame_rate = eval(data.get('streams')[0].get('r_frame_rate'))

最后用eval只是将其value变成ini类型

获取视频帧数:

    ffprobe_path = '/home/user/ffprobe'
    video_path = 'your_video_path'
    command = '{ffprobe_path} -v error -select_streams v -show_entries stream=nb_frames -of json {video_path}'.format(ffprobe_path=ffprobe_path,
                                                                                                                      video_path=video_path)

    value = subprocess.check_output(command)
    data = json.loads(value)
    frames = data.get('streams')[0].get('nb_frames')

你可能感兴趣的:(ffmpeg,ffmepg,视频帧数)