ziqiangao commited on
Commit
004ce63
·
1 Parent(s): 6979b00
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -127,6 +127,9 @@ def render_frame(params):
127
  os.makedirs(path+f'out/{name}/', exist_ok=True)
128
  img.save(path+f'out/{name}/{str(n)}.png', 'PNG',)
129
 
 
 
 
130
  def RenderVid(af, n, fps=30):
131
  (ffmpeg
132
  .input(path+f'out/{n}/%d.png', framerate=fps)
@@ -134,6 +137,7 @@ def RenderVid(af, n, fps=30):
134
  .output(n + '.mp4', vcodec='libx264', r=fps, pix_fmt='yuv420p', acodec='aac', shortest=None)
135
  .run()
136
  )
 
137
 
138
  def main(file, name, fps=30, res: tuple=(1280,720), oscres = 512):
139
  global iii
@@ -179,25 +183,26 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres = 512):
179
  path+f'{name}.mp4' # Output MP4 filename
180
  ]
181
  subprocess.run(ffmpeg_cmd)
 
182
 
183
  def gradio_interface(audio_file, output_name, fps=30, vidwidth=1280, vidhight=720, oscres=512):
184
- resolution = f"{vidwidth}x{vidhight}"
185
- res = tuple(map(int, resolution.split('x')))
186
- main(audio_file, output_name, fps=fps, res=res, oscres=oscres)
187
- return f"Output video '{output_name}.mp4' has been created. Click the link to download."
188
 
189
  # Define Gradio interface
190
  iface = gr.Interface(
191
  fn=gradio_interface,
192
  inputs=[
193
- gr.components.File(label="Upload your MP3 file"),
194
- gr.components.Textbox(label="Output Video Name (without extension)"),
195
- gr.components.Slider(label="Frames per Second", value=30, minimum=30, maximum=60, step=1),
196
- gr.components.Slider(label="Output Video Width", value=1280, minimum=100, maximum=4096),
197
- gr.components.Slider(label="Output Video Height", value=720, minimum=100, maximum=2160),
198
- gr.components.Slider(label="Number of Visualization Segments", value=512, minimum=128, maximum=2048, step=2)
199
  ],
200
- outputs=[gr.components.Textbox(label="Output")],
201
  title="MP3 to Video Visualization",
202
  description="Upload an MP3 file and configure parameters to create a visualization video."
203
  )
 
127
  os.makedirs(path+f'out/{name}/', exist_ok=True)
128
  img.save(path+f'out/{name}/{str(n)}.png', 'PNG',)
129
 
130
+ progress = (n + 1) / num_frames * 100
131
+ gr.Interface.update("Processing frames: {:.2f}%".format(progress))
132
+
133
  def RenderVid(af, n, fps=30):
134
  (ffmpeg
135
  .input(path+f'out/{n}/%d.png', framerate=fps)
 
137
  .output(n + '.mp4', vcodec='libx264', r=fps, pix_fmt='yuv420p', acodec='aac', shortest=None)
138
  .run()
139
  )
140
+ gr.Interface.download(f"{n}.mp4")
141
 
142
  def main(file, name, fps=30, res: tuple=(1280,720), oscres = 512):
143
  global iii
 
183
  path+f'{name}.mp4' # Output MP4 filename
184
  ]
185
  subprocess.run(ffmpeg_cmd)
186
+ gr.Interface.download(f"{name}.mp4")
187
 
188
  def gradio_interface(audio_file, output_name, fps=30, vidwidth=1280, vidhight=720, oscres=512):
189
+ resolution = f"{vidwidth}x{vidhight}"
190
+ res = tuple(map(int, resolution.split('x')))
191
+ main(audio_file, output_name, fps=fps, res=res, oscres=oscres)
192
+ return f"Processing complete. Download your video: <a href='{path}{output_name}.mp4'>{output_name}.mp4</a>"
193
 
194
  # Define Gradio interface
195
  iface = gr.Interface(
196
  fn=gradio_interface,
197
  inputs=[
198
+ gr.inputs.File(label="Upload your MP3 file"),
199
+ gr.inputs.Textbox(label="Output Video Name (without extension)"),
200
+ gr.inputs.Slider(label="Frames per Second", minimum=30, maximum=60, step=1, default=30),
201
+ gr.inputs.Slider(label="Output Video Width", minimum=100, maximum=4096, default=1280),
202
+ gr.inputs.Slider(label="Output Video Height", minimum=100, maximum=2160, default=720),
203
+ gr.inputs.Slider(label="Number of Visualization Segments", minimum=128, maximum=2048, step=2, default=512)
204
  ],
205
+ outputs=gr.outputs.HTML(label="Output"),
206
  title="MP3 to Video Visualization",
207
  description="Upload an MP3 file and configure parameters to create a visualization video."
208
  )