Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
def convert_video(input_file, output_file, format='mp4'):
|
| 6 |
try:
|
| 7 |
# Define input and output files
|
| 8 |
input_path = input_file
|
| 9 |
output_path = output_file + '.' + format
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
print(f"Video converted successfully: {output_path}")
|
| 20 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
+
import imageio
|
| 4 |
|
| 5 |
+
def convert_video(input_file, output_file, format='mp4', codec='libx264'):
|
| 6 |
try:
|
| 7 |
# Define input and output files
|
| 8 |
input_path = input_file
|
| 9 |
output_path = output_file + '.' + format
|
| 10 |
|
| 11 |
+
# Read video file
|
| 12 |
+
reader = imageio.get_reader(input_path)
|
| 13 |
+
|
| 14 |
+
# Get writer for output video file with specified codec
|
| 15 |
+
writer = imageio.get_writer(output_path, format=format, ffmpeg_params=['-vcodec', codec])
|
| 16 |
+
|
| 17 |
+
# Iterate through video frames and write to output file
|
| 18 |
+
for frame in reader:
|
| 19 |
+
writer.append_data(frame)
|
| 20 |
+
|
| 21 |
+
# Close writer
|
| 22 |
+
writer.close()
|
| 23 |
|
| 24 |
print(f"Video converted successfully: {output_path}")
|
| 25 |
|