Ask Your Question
0

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

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

Nbb gravatar image

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

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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-10-26 12:16:58 -0600

Nbb gravatar image

thank you very much !

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-24 17:32:52 -0600

Seen: 394 times

Last updated: Oct 24 '18