fffiloni commited on
Commit
08e62ba
·
1 Parent(s): 44106fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -1,20 +1,25 @@
1
  import gradio as gr
2
  import subprocess
3
- import ffmpeg
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
- # Define ffmpeg command
12
- ffmpeg_cmd = (
13
- ffmpeg
14
- .input(input_path)
15
- .output(output_path, vcodec='libx264', acodec='aac')
16
- .run()
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