fffiloni commited on
Commit
3f4e0ec
·
1 Parent(s): db305d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -1,29 +1,35 @@
1
  import gradio as gr
2
  import subprocess
3
- import imageio
4
- import imageio_ffmpeg
5
 
6
- def convert_video(input_file, output_file, format='mp4', codec='libx264'):
7
  try:
8
  # Define input and output files
9
  input_path = input_file
10
- output_path = output_file + '.' + format
11
-
12
- # Read video file
13
- reader = imageio.get_reader(input_path)
14
-
15
- # Configure FFmpeg parameters
16
- ffmpeg_params = ['-vcodec', codec]
17
-
18
- # Get writer for output video file with specified codec
19
- writer = imageio.get_writer(output_path, format=format, ffmpeg_params=ffmpeg_params, plugin='imageio_ffmpeg')
20
-
21
- # Iterate through video frames and write to output file
22
- for frame in reader:
23
- writer.append_data(frame)
24
-
25
- # Close writer
26
- writer.close()
 
 
 
 
 
 
 
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