Skip to content

Commit

Permalink
Add CAP_PROP_FRAME_COUNT for YouTube sources (#3193)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed May 17, 2021
1 parent ae53f50 commit 36b0a9e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __next__(self):
ret_val, img0 = self.cap.read()

self.frame += 1
print(f'video {self.count + 1}/{self.nf} ({self.frame}/{self.nframes}) {path}: ', end='')
print(f'video {self.count + 1}/{self.nf} ({self.frame}/{self.frames}) {path}: ', end='')

else:
# Read image
Expand All @@ -193,7 +193,7 @@ def __next__(self):
def new_video(self, path):
self.frame = 0
self.cap = cv2.VideoCapture(path)
self.nframes = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
self.frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))

def __len__(self):
return self.nf # number of files
Expand Down Expand Up @@ -285,10 +285,11 @@ def __init__(self, sources='streams.txt', img_size=640, stride=32):
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
self.fps = cap.get(cv2.CAP_PROP_FPS) % 100
self.frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))

_, self.imgs[i] = cap.read() # guarantee first frame
thread = Thread(target=self.update, args=([i, cap]), daemon=True)
print(f' success ({w}x{h} at {self.fps:.2f} FPS).')
print(f" success ({f'{self.frames} frames ' if self.frames else ''}{w}x{h} at {self.fps:.2f} FPS).")
thread.start()
print('') # newline

Expand Down

0 comments on commit 36b0a9e

Please sign in to comment.