Can only save first 28 frames from a video with 31830 frames

asked 2018-10-24 17:32:52 -0500

Nbb gravatar image

updated 2018-10-24 17:33:30 -0500

I have an issue where I try to save a video into a sequence of images but it is only able to save 28 frames. I have 31830 frames to save but ret becomes a false on the 28th frame. I have checked the video and it is not corrupt. What could the issue be ?

import numpy as np
import matplotlib.pyplot as plt
import cv2
import sys
import time

from tqdm import tqdm

inp = sys.argv[1]
out = sys.argv[2]

cap = cv2.VideoCapture(inp)

i = 0
pbar = tqdm(total=int(cap.get(cv2.CAP_PROP_FRAME_COUNT)))
while(cap.isOpened()):
    ret, im = cap.read()

    #print(ret)

    #break
    if(ret == True):
        cv2.imwrite(out + str(i).zfill(10) + ".png", im, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
        pbar.update(1)
        print(i)
        i=i+1
    else:
        break
edit retag flag offensive close merge delete

Comments

2

For this kind of task, you should use FFmpeg:

ffmpeg -i myvideo.avi -vf fps=30 img%06d.png

Change fps accordingly.

Eduardo gravatar imageEduardo ( 2018-10-25 03:56:24 -0500 )edit

thank you very much !

Nbb gravatar imageNbb ( 2018-10-26 12:16:58 -0500 )edit