我正在使用python OpenCV从具有可变帧速率的视频文件中读取帧。
我需要了解墙上时间在各帧之间的变化(即,我希望能够在每个帧上写入时间戳)。我的理解是,底层视频格式存储了每一帧的持续时间,即视频文件包含的信息告诉视频播放器在移至下一帧之前应显示给定帧多长时间。
我想使用python OpenCV接口(interface)以编程方式访问此数据。下面的示例(无效):

import numpy as np
import cv2 as cv

cap = cv.VideoCapture('my_variable_frame_rate_video.mp4')

while cap.isOpened():
    ret, frame = cap.read()

    frame_length_ms = ret.frame_length()   # obviously doesn't work

    print("The length of the frame in ms is {}".format(frame_length_ms))

   # Should print: The length of the frame in ms is 23
无效的东西
  • 从捕获设备读取源帧速率:
  • fps = cap.get(cv2.cv.CV_CAP_PROP_FPS)
  • 计算帧总数:
  • fps = cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)/total_length这两个都不起作用,因为我们正在处理可变的帧速率

    最佳答案

    一个想法可能是提取时间量并将其写入每个帧中

    import cv2
    import time
    
    path="video.mp4"
    video = cv2.VideoCapture(path);
    
    start = time.time()
    ret, frame = video.read()
    font = cv2.FONT_HERSHEY_SIMPLEX
    i = 0
    while ret:
        start = time.time()
        ret, frame = video.read()
        end = time.time()
        seconds = end - start
        cv2.putText(frame,str(seconds),(10,500), font, 4,(255,255,255),2,cv2.LINE_AA)
        cv2.imwrite(str(i)+".jpg", frame)
        i+=1
    
    video.release()
    
    python - OPENCV:提取帧率可变的视频中一帧的生存期-LMLPHP

    关于python - OPENCV:提取帧率可变的视频中一帧的生存期,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63036200/

    10-12 00:10
    查看更多