Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
-
import
|
| 4 |
-
import imageio_ffmpeg
|
| 5 |
|
| 6 |
-
def convert_video(input_file, output_file,
|
| 7 |
try:
|
| 8 |
# Define input and output files
|
| 9 |
input_path = input_file
|
| 10 |
-
output_path = output_file
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
print(f"Video converted successfully: {output_path}")
|
| 29 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
+
import cv2
|
|
|
|
| 4 |
|
| 5 |
+
def convert_video(input_file, output_file, codec='mp4v'):
|
| 6 |
try:
|
| 7 |
# Define input and output files
|
| 8 |
input_path = input_file
|
| 9 |
+
output_path = output_file
|
| 10 |
+
|
| 11 |
+
# Open input video file
|
| 12 |
+
cap = cv2.VideoCapture(input_path)
|
| 13 |
+
|
| 14 |
+
# Get video codec and frame dimensions
|
| 15 |
+
fourcc = cv2.VideoWriter_fourcc(*codec)
|
| 16 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 17 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 18 |
+
|
| 19 |
+
# Create output video writer
|
| 20 |
+
out = cv2.VideoWriter(output_path, fourcc, 20.0, (width, height))
|
| 21 |
+
|
| 22 |
+
# Read and write video frames
|
| 23 |
+
while(cap.isOpened()):
|
| 24 |
+
ret, frame = cap.read()
|
| 25 |
+
if ret:
|
| 26 |
+
out.write(frame)
|
| 27 |
+
else:
|
| 28 |
+
break
|
| 29 |
+
|
| 30 |
+
# Release video objects
|
| 31 |
+
cap.release()
|
| 32 |
+
out.release()
|
| 33 |
|
| 34 |
print(f"Video converted successfully: {output_path}")
|
| 35 |
|