opencv_contrib icon indicating copy to clipboard operation
opencv_contrib copied to clipboard

about how to use cv2:: codacodec:: VdieoReader::set()

Open RookieDeng33 opened this issue 6 months ago • 6 comments

How to use similar functions in cv2:: codacodec:: VdieoReader like cv2:: VideoCapture:: set (CAP_PROP_POS_FRAMES, target)

I need to read the video frame from the customized key frame position, or repeat the reading from the specified frame when reading the video to the last frame

just like

def get_cap_frames_by_range(f_cap, frames_idx, prepared_f_frames):
      min_index, max_index = min(frames_idx), max(frames_idx)
      # print(min_index, max_index)
      temp_counter = {}
      temp_frames = {}  
      for item in frames_idx:
          if item not in temp_counter:
          temp_counter[item] = 0
          temp_counter[item] += 1
      if int(f_cap.get(cv2.CAP_PROP_POS_FRAMES)) != min_index:
          # print("switch CAP_PROP_POS_FRAMES")
          f_cap.set(cv2.CAP_PROP_POS_FRAMES, min_index)
      ...

RookieDeng33 avatar May 21 '25 02:05 RookieDeng33