Skip to content

Instantly share code, notes, and snippets.

@igarag
Last active August 19, 2020 18:04
Show Gist options
  • Save igarag/8f1f82db8686003c3f573c65f77aa9a2 to your computer and use it in GitHub Desktop.
Save igarag/8f1f82db8686003c3f573c65f77aa9a2 to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
cap = cv2.VideoCapture('path_to_video.mp4')
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
name = 'output.mp4'
out = cv2.VideoWriter(name, fourcc, 25.0, (1920, 1080))
show_image = False
i = 0
while(cap.isOpened()):
i += 1
if i % 1000 == 0:
print(f'frame{i}')
ret, frame = cap.read()
if ret:
im_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img_rotate_180 = cv2.rotate(im_rgb, cv2.ROTATE_180)
out.write(img_rotate_180)
else:
break
if show_image:
cv2.imshow('frame', img_rotate_180)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
print("\nEnd of program")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment