可以使用 pyav - python 获取视频中帧的时间戳

Tha*_*yen 4 timestamp ffmpeg pts python-3.x pyav

如何从 pts 和 time_base 或持续时间获取视频或 rtmp 流中帧的时间戳?多谢!

import av
def init_input(file_name):
    global a
    container = av.open(file_name)
    a = container.duration
    return container.decode(video=0)
url = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"
stream1 = init_input(url)
for frame1 in stream1:
    print(frame1.pts)
    print(frame1.time_base)
Run Code Online (Sandbox Code Playgroud)

PS:frame.time与实际时间不正确

Mik*_*ers 6

截至撰写本文时,该错误刚刚在 GitHub 上修复

如果您需要它与当前发布的 PyAV(即在 PyPI 上)一起使用,那么您可以time_base在视频上使用Stream

import av

url = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov"

container = av.open(url, options={'rtsp_transport': 'tcp'})
stream = container.streams.video[0]

for frame in container.decode(stream):
    print(float(frame.pts * stream.time_base))
Run Code Online (Sandbox Code Playgroud)