Home > Enterprise >  How to skip a video in an nth increment in OpenCV
How to skip a video in an nth increment in OpenCV

Time:09-17

I've been reading OpenCV documentation about reading and skipping on a video using trackbar, for example 10, the video will play at 10s, 20s, 30s...n. But I can't seem to implement it on the right way using Python. I just want to ask for your suggestion of an algorithm. If any, some snippets. Thank you.

CodePudding user response:

I'm have understood your comment This is code to show just every 10s 20s etc..

import cv2

cap = cv2.VideoCapture('../folder/' video_name)

num_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
fps = cap.get(cv2.CAP_PROP_FPS)

### loop over video and show
for i in range(num_frames):
          ret_prev, frame = cap.read()


      ### this we show every 10s other will be skip
          if i % fps*10:
            cv2.imshow('frame',frame)
            cv2.waitKey(0)

CodePudding user response:

You can make loop over video files and open every video[i] with step like in this code

import cv2

video_files = os.listdir(folder)

step = 10    ## every 5 video

### loop over videos show every 10..
for i in range(0,100, step):

     video_name = video_files[i]
     cap = cv2.VideoCapture('../folder/' video_name)

     num_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

     ### loop over video and show
     for i in range(num_frames):
          ret_prev, frame = cap.read()
          cv2.imshow('frame',frame)
          cv2.waitKey(0)

  • Related