Can only save first 28 frames from a video with 31830 frames
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
For this kind of task, you should use FFmpeg:
ffmpeg -i myvideo.avi -vf fps=30 img%06d.png
Change fps accordingly.