Skip to content

Commit ae4b8d0

Browse files
Merge pull request #2589 from invigorzz313/videoreverse
video reversing
2 parents 45c86b2 + c4721ea commit ae4b8d0

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

Video reversing/ReadMe.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Video reversing
2+
This python script will allow us to reverse a video
3+
4+
## Setup Instructions
5+
### Install python3
6+
sudo apt-get install python3
7+
### Install pip (package installer for python)
8+
sudo apt-get install python3-pip
9+
### Install OpenCV library with pip
10+
pip3 install opencv-python
11+
### Install tkinter library
12+
sudo apt-get install python3-tk
13+
14+
## Details/Output
15+
The input video is to be stored in the current folder.
16+
When the script is run, the progress is updated every 100 frames.
17+
The output reversed video is saved in the current folder.
18+
19+
## Author
20+
Github: invigorzz313

Video reversing/sampleOutput.mp4

1.26 MB
Binary file not shown.

Video reversing/sampleVideo.mp4

2.7 MB
Binary file not shown.

Video reversing/video_reversing.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import cv2
2+
import tkinter as tk
3+
from tkinter.filedialog import *
4+
5+
window = tk.Tk()
6+
window.title("Video reversing")
7+
window.geometry('400x200')
8+
label = tk.Label(window, text="Input video file should be in the current folder").grid(row=0, column=0)
9+
label = tk.Label(window, text="Output/reversed video file is saved in the current folder").grid(row=1, column=0)
10+
label = tk.Label(window, text="Close this dialog box to proceed").grid(row=3, column=0)
11+
window.mainloop()
12+
13+
14+
cap = cv2.VideoCapture('sampleVideo.mp4')
15+
16+
frames = cap.get(cv2.CAP_PROP_FRAME_COUNT)
17+
fps = cap.get(cv2.CAP_PROP_FPS)
18+
19+
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
20+
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
21+
size = (int(width*0.5), int(height*0.5))
22+
23+
# defining/writing the output video and its format
24+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
25+
out = cv2.VideoWriter('sampleOutput.mp4', fourcc, fps, size)
26+
27+
print("No. of frames: ", frames)
28+
print("FPS: ", fps)
29+
30+
frameIdx = frames - 1
31+
if(cap.isOpened()):
32+
# printing the progress
33+
print("Progress:\n")
34+
while(frameIdx!=0): # iterating from last frame to first
35+
cap.set(cv2.CAP_PROP_POS_FRAMES, frameIdx) # pointing to last frame
36+
ret, frame = cap.read()
37+
frame = cv2.resize(frame, size)
38+
frameIdx = frameIdx - 1
39+
if(frameIdx%100 == 0): # progress updated every 100 frames
40+
print(frameIdx)
41+
out.write(frame)
42+
43+
out.release()
44+
cap.release()
45+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)