Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 从视频读取帧时数据包太小_Python 3.x_Opencv_Opencv3.0 - Fatal编程技术网

Python 3.x 从视频读取帧时数据包太小

Python 3.x 从视频读取帧时数据包太小,python-3.x,opencv,opencv3.0,Python 3.x,Opencv,Opencv3.0,我有一个脚本,可以从视频中获取任意数量的帧并将其保存为图像:代码如下 def get_n_frames(n, k, src, dst): # read n frames from video in src and save them as images on folder dst. If dst does not exists, it is created. # if n == -1, are saved as many frames as posiible # k is the number

我有一个脚本,可以从视频中获取任意数量的帧并将其保存为图像:代码如下

def get_n_frames(n, k, src, dst):
# read n frames from video in src and save them as images on folder dst. If dst does not exists, it is created.
# if n == -1, are saved as many frames as posiible
# k is the number of frames to skip between each pair of frames (ie save only one out of k)

    max_intentos = 10
    end_of_video = 0


    while True:
        cap = cv2.VideoCapture(src)
        if cap.isOpened():
            break
        if max_intentos:
            raise "Capture is not open. There may be a problem with source {}".format(src)
        print("trying again")
        max_intentos -=1

    try:
        i=0
        frame_number = 0 
        while(frame_number < n or n==-1):
            # Capture frame-by-frame
            ret, frame = cap.read()

            if ret:
                end_of_video = 0
                if i % k == 0:

                    final_dest = join(dst, '{0}_{1:03}.jpg'.format(datetime.now().strftime('%Y-%m-%d-%H:%M:%S'), frame_number))
                if cv2.imwrite(final_dest, frame):
                    print("Saving frame {}".format(frame_number))
                    frame_number +=1
                i+=1
            elif end_of_video < 10:
                end_of_video +=1
            else:
                if n != -1:
                    print("WARNING: Video is too short, can not take {} frames with k={}".format(n, k))
                break
    finally:
        # When everything done, release the capture
        cap.release()
        print("{} frames were saved".format(frame_number))
def get_n_帧(n、k、src、dst):
#从src中的视频读取n帧,并将其保存为文件夹dst上的图像。如果dst不存在,则创建它。
#如果n==-1,则保存尽可能多的帧
#k是每对帧之间要跳过的帧数(即只保存k中的一个)
最大强度=10
视频结束\u=0
尽管如此:
cap=cv2.视频捕获(src)
如果cap.isOpened():
打破
如果最大意图:
raise“捕获未打开。源{}可能有问题”。格式(src)
打印(“重试”)
最大强度-=1
尝试:
i=0
帧编号=0
而(帧号
我已经在很多
.avi
视频中使用过它,没有问题,但现在我收到了一条奇怪的消息:
[msvideo1@0x5615d5f85280]数据包太小了
我一直在网上搜索,但这似乎很奇怪,这不是一个例外,输出看起来好像程序完成了一样

我用一个.avi视频作为源调用它,它的相对路径是k=10和n=-1


我不确定这些是否都是视频中的帧,更重要的是,这个奇怪的错误是什么?

是针对一个特定视频的错误,还是针对多个文件的错误?文件/帧是否会损坏?30个视频中有两个会损坏。如何检查文件是否已损坏?提取的1732帧和1733帧还可以。我不知道。是否可以共享一个有效的视频和一个无效的视频?