Jeffgold commited on
Commit
87e9456
·
1 Parent(s): 7148179

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -1,37 +1,35 @@
1
  import gradio as gr
2
  import ffmpeg
3
 
4
- from gradio.components import File
5
 
6
- import os
7
-
8
- def transcode_video(input_video_file):
9
  """Transcodes a video file to m3u8 using ffmpeg.
10
  Args:
11
- input_video_file: The path to the video file to transcode.
12
  Returns:
13
  The path to the transcoded file.
14
  """
15
 
16
  # Create a folder to save the transcoded video file to.
17
- output_dir = os.path.dirname(input_video_file)
18
  if not os.path.exists(output_dir):
19
  os.makedirs(output_dir)
20
 
21
  # Transcode the video file.
22
- output_file = os.path.join(output_dir, f"{input_video_file.name}.m3u8")
23
- ffmpeg.input(input_video_file).output(output_file, format="hls").run()
24
 
25
  # Return the path to the transcoded file.
26
  return output_file
27
 
28
- # Remove unused keyword argument
29
- input_video_file = File()
30
 
31
- outputs={"output_file": File(accept=".m3u8")}
 
 
 
 
 
 
32
 
33
- gr.Interface(
34
- transcode_video,
35
- inputs={"input_video_file": input_video_file},
36
- outputs=outputs
37
- ).launch()
 
1
  import gradio as gr
2
  import ffmpeg
3
 
 
4
 
5
+ def transcode_video(video):
 
 
6
  """Transcodes a video file to m3u8 using ffmpeg.
7
  Args:
8
+ video: The video file to transcode.
9
  Returns:
10
  The path to the transcoded file.
11
  """
12
 
13
  # Create a folder to save the transcoded video file to.
14
+ output_dir = os.path.dirname(video.path)
15
  if not os.path.exists(output_dir):
16
  os.makedirs(output_dir)
17
 
18
  # Transcode the video file.
19
+ output_file = os.path.join(output_dir, f"{video.name}.m3u8" )
20
+ ffmpeg.input(video.path).output(output_file, format="hls").run()
21
 
22
  # Return the path to the transcoded file.
23
  return output_file
24
 
 
 
25
 
26
+ demo = gr.Interface(transcode_video,
27
+ gr.Video(),
28
+ "playable_video",
29
+ examples=[
30
+ os.path.join(os.path.dirname(__file__),
31
+ "video/video_sample.mp4")],
32
+ cache_examples=True)
33
 
34
+ if __name__ == "__main__":
35
+ demo.launch()