Spaces:
Running
Running
ziqiangao
commited on
Commit
·
004ce63
1
Parent(s):
6979b00
update ui
Browse files
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 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
|
189 |
# Define Gradio interface
|
190 |
iface = gr.Interface(
|
191 |
fn=gradio_interface,
|
192 |
inputs=[
|
193 |
-
gr.
|
194 |
-
gr.
|
195 |
-
gr.
|
196 |
-
gr.
|
197 |
-
gr.
|
198 |
-
gr.
|
199 |
],
|
200 |
-
outputs=
|
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 |
)
|