0

我使用 cv2 来阅读通常时长约 2 小时的视频。标准代码是这样的:

import cv2
vid = cv2.VideoCapture(vidname)
video_FourCC    = int(vid.get(cv2.CAP_PROP_FOURCC))
video_fps       = vid.get(cv2.CAP_PROP_FPS)
video_frame_count= vid.get(cv2.CAP_PROP_FRAME_COUNT)   
video_size      = (int(vid.get(cv2.CAP_PROP_FRAME_HEIGHT)),int(vid.get(cv2.CAP_PROP_FRAME_WIDTH)))

vid.set(1,frame)
res, img = vid.read()

#do lots of analysis on the frame

现在偶尔,我会有一个视频,它的某些部分已损坏,并且 cv2 会在尝试读取该帧时抛出错误。这些帧可能发生在最后,也可能发生在开头和中间。我想提前弄清楚哪些帧已损坏。例如,我可以执行以下代码之类的操作,但每次在开始处理之前阅读 2 小时的视频会太长。有没有办法更快地找到坏帧?

vid.set(1,0)
corrupt_frames = []
for i in range(int(video_frame_count)):
    try:
       res, img = vid.read()
    except:
       corrupt_frames.append(i)

损坏帧中的错误读取示例

[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe81c99e2: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe81c9afc: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe81c9c18: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe81c9d2f: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 1, offset 0xe81c9e50: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe82195d8: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe82196ef: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe8219812: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe821993d: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002e49408dd80] stream 0, offset 0xe821
4

0 回答 0