Spaces:
Running
Running
File size: 791 Bytes
95f8bbc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import cv2
from tqdm import tqdm
path = '../outputs/nba2k.mp4'
stream = cv2.VideoCapture(path)
assert stream.isOpened(), 'Cannot capture source'
video_length = int(stream.get(cv2.CAP_PROP_FRAME_COUNT))
video_fps = stream.get(cv2.CAP_PROP_FPS)
video_size = (int(stream.get(cv2.CAP_PROP_FRAME_WIDTH)), int(stream.get(cv2.CAP_PROP_FRAME_HEIGHT)))
writer = cv2.VideoWriter('out.mp4', cv2.VideoWriter_fourcc(*'MP4V'), video_fps, video_size)
for i in tqdm(range(video_length)):
i += 1
grabbed, frame = stream.read()
writer.write(frame)
# if the `grabbed` boolean is `False`, then we have
# reached the end of the video file
if not grabbed:
print('\n===========================> This video get ' + str(i) + ' frames in total.')
break
writer.release()
|