Created
September 30, 2021 19:56
-
-
Save jairajsahgal/376a545b48b3e278108c14dc127610f0 to your computer and use it in GitHub Desktop.
This program reverses your video using opencv, and saves it with mp4 content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make sure you have opencv installed, "pip install opencv-python" | |
# make sure your video is .avi or .mp4 encoded, else change the encoder accordingly | |
import cv2 | |
output_file = "output.mp4" | |
cap = cv2.VideoCapture("Video File Location") | |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) | |
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) | |
fps = cap.get(cv2.CAP_PROP_FPS) | |
check , vid = cap.read() | |
counter = 0 | |
check = True | |
video_type_cv2 = cv2.VideoWriter_fourcc(*'XVID') | |
out = cv2.VideoWriter(output_file,video_type_cv2,int(fps),(width,height)) | |
frame_list = [] | |
while(check == True): | |
check , vid = cap.read() | |
frame_list.append(vid) | |
counter += 1 | |
frame_list.pop() | |
frame_list.reverse() | |
for frame in frame_list: | |
out.write(frame) | |
cap.release() | |
out.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment