Jeffgold commited on
Commit
2d3ac4b
·
1 Parent(s): d51b3b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
app.py CHANGED
@@ -72,15 +72,14 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
72
  video = VideoFileClip(str(input_path))
73
  original_height = video.size[1]
74
 
75
- output_paths = []
76
 
77
  for res in standard_resolutions:
78
- # Skip if resolution is higher than original
79
  if res > original_height:
80
  continue
81
 
82
- scale = "-1:" + str(res) # we scale the height to res and keep aspect ratio
83
- output_path = get_output_path(input_path, str(res) + 'p') # pass the resolution to create a unique output file
84
 
85
  ffmpeg_command = [
86
  "ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
@@ -92,28 +91,30 @@ def convert_video(video_file, quality, aspect_ratio, video_url):
92
  logging.info("Running ffmpeg command: " + ' '.join(ffmpeg_command))
93
  subprocess.run(ffmpeg_command, check=True)
94
 
95
- output_paths.append(output_path)
96
 
97
  master_playlist_path = create_master_playlist(output_paths)
98
  output_paths.append(master_playlist_path)
99
 
100
- html_components = []
101
 
102
  for path in output_paths:
103
- # Create a video player and a download link for each video file
104
- if path.suffix in ['.mp4', '.webm', '.ogg']:
105
- video_path = f"http://localhost:5000/files/{path.name}"
106
- video_component = f"<video width='320' height='240' controls><source src='{video_path}' type='video/{path.suffix.lstrip('.')}'>Your browser does not support the video tag.</video>"
107
- download_link = f"<p><a href='{video_path}' download>Download this video</a></p>"
108
- html_components.append(f"{video_component}{download_link}")
109
-
110
- return html_components, # add more return values as needed
111
-
112
- outputs = [
113
- gr.outputs.HTML(label="Video Players"),
114
- # add more outputs as needed
115
- ]
116
-
 
 
117
 
118
  video_file = gr.inputs.File(label="Video File")
119
  quality = gr.inputs.Dropdown(
 
72
  video = VideoFileClip(str(input_path))
73
  original_height = video.size[1]
74
 
75
+ output_paths = []
76
 
77
  for res in standard_resolutions:
 
78
  if res > original_height:
79
  continue
80
 
81
+ scale = "-1:" + str(res)
82
+ output_path = get_output_path(input_path, str(res) + 'p')
83
 
84
  ffmpeg_command = [
85
  "ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
 
91
  logging.info("Running ffmpeg command: " + ' '.join(ffmpeg_command))
92
  subprocess.run(ffmpeg_command, check=True)
93
 
94
+ output_paths.append(output_path)
95
 
96
  master_playlist_path = create_master_playlist(output_paths)
97
  output_paths.append(master_playlist_path)
98
 
99
+ html_blocks = []
100
 
101
  for path in output_paths:
102
+ video_path = f'http://localhost:5000/files/{path.name}'
103
+ video_component = f'''
104
+ <div style="margin-bottom: 20px; border: 1px solid #ccc; padding: 10px;">
105
+ <video width="320" height="240" controls>
106
+ <source src="{video_path}" type="video/mp4">
107
+ Your browser does not support the video tag.
108
+ </video>
109
+ <p>
110
+ <a href="{video_path}" target="_blank">Download {path.stem}</a>
111
+ </p>
112
+ <p>Resolution: {path.stem.split('_')[-1]}</p>
113
+ </div>
114
+ '''
115
+ html_blocks.append(video_component)
116
+
117
+ return "\n".join(html_blocks),
118
 
119
  video_file = gr.inputs.File(label="Video File")
120
  quality = gr.inputs.Dropdown(