如何使用 Python 提取视频文件的比特率和其他统计信息 [英] How to extract the bitrate and other statistics of a video file with Python

查看:74
本文介绍了如何使用 Python 提取视频文件的比特率和其他统计信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在正常播放条件下以 1-10 秒的固定采样间隔提取视频文件(例如包含电影的 .mkv 文件)的主要比特率.有点像您在 vlc 中看到的,在统计窗口中播放文件期间.

I am trying to extract the prevailing bitrate of a video file (e.g. .mkv file containing a movie) at a regular sampling interval of between 1-10 seconds under conditions of normal playback. Kind of like you may see in vlc, during playback of the file in the statistics window.

谁能建议引导此类分析器编码的最佳方法?是否有一个库为人们知道的此类信息提供 API?也许是 ffmpeg 的 Python 包装器或处理视频文件的等效工具,从而可以提取此类统计信息.

Can anyone suggest the best way to bootstrap the coding of such an analyser? Is there a library that provides an API to such information that people know of? Perhaps a Python wrapper for ffmpeg or equivalent tool that processes video files and can thereby extract such statistics.

我真正的目标是一个 CSV 格式的文件,其中包含秒偏移量以及该偏移量到资产的平均或实际比特率(以 KiB/s 为单位).

What I am really aiming for is a CSV format file containing the seconds offset and the average or actual bitrate in KiB/s at that offset into the asset.

更新:

我构建了 pyffmpeg 并编写了以下峰值:

I built pyffmpeg and wrote the following spike:

import pyffmpeg

reader = pyffmpeg.FFMpegReader(False)
reader.open("/home/mark/Videos/BBB.m2ts", pyffmpeg.TS_VIDEO)
tracks=reader.get_tracks()

# Called for each frame
def obs(f):
  pass

tracks[0].set_observer(obs)
reader.run()

但是在回调中观察帧信息 (f) 似乎没有给我任何计算每秒比特率的钩子.事实上,pyffmpeg 中的比特率计算是在整个文件(文件大小/持续时间)中测量的,因此库中的处理非常肤浅.显然,它的重点是提取 i 帧和其他帧/GOP 特定工作.

But observing frame information (f) in the callback does not appear to give me any hooks to calculate per second bitrates. In fact bitrate calculations within pyffmpeg are measured across the entire file (filesize / duration) and so the treatment within the library is very superficial. Clearly its focus is on extract i-frames and other frame/GOP specific work.

推荐答案

您应该可以使用 gstreamer 做到这一点.http://pygstdocs.berlios.de/pygst-tutorial/seeking.html有一个简单的媒体播放器的例子.它调用

You should be able to do this with gstreamer. http://pygstdocs.berlios.de/pygst-tutorial/seeking.html has an example of a simple media player. It calls

pos_int = self.player.query_position(gst.FORMAT_TIME, None)[0]

定期.您所要做的就是使用 gst.FORMAT_BYTES 第二次调用 query_position(),做一些简单的数学运算,瞧!比特率与时间.

periodically. All you have to do is call query_position() a second time with gst.FORMAT_BYTES, do some simple math, and voila! Bitrate vs. time.

这篇关于如何使用 Python 提取视频文件的比特率和其他统计信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆