Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CAP_PROP_FRAME_COUNT for YouTube sources #3193

Merged
merged 1 commit into from
May 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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