【问题标题】:Can get timestamp of frame in video with pyav - python可以使用pyav获取视频中帧的时间戳 - python
【发布时间】:2019-02-09 08:51:06
【问题描述】:

如何从 pts 和 time_base 或 duration 获取视频或 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)

PS:frame.time 与实际时间不符

【问题讨论】:

    标签: python-3.x ffmpeg timestamp pts pyav


    【解决方案1】:

    在撰写本文时,此错误是 GitHub 上的 just fixed

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-24
      • 2018-04-12
      • 2019-10-10
      • 2013-01-06
      • 2020-03-24
      • 2010-11-07
      • 1970-01-01
      • 2017-07-02
      相关资源
      最近更新 更多