Archenar
commited on
Commit
Β·
96618f0
unverified
Β·
0
Parent(s):
Create app.ipynb
Browse files
app.ipynb
ADDED
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#@title Run Gradio
|
2 |
+
import os
|
3 |
+
from ffmpy import FFmpeg
|
4 |
+
import gradio as gr
|
5 |
+
import subprocess
|
6 |
+
import shortuuid
|
7 |
+
from tempfile import _TemporaryFileWrapper
|
8 |
+
|
9 |
+
# Check Runtime to avoid Error
|
10 |
+
globalopt = []
|
11 |
+
if os.getenv("SYSTEM") == "spaces":
|
12 |
+
globalopt = ["-y", "-hide_banner", "-threads 64", "-filter_threads 64", "-filter_complex_threads 64"]
|
13 |
+
else:
|
14 |
+
globalopt = ["-y", "-hide_banner", "-hwaccel cuda", "-threads 64", "-filter_threads 64", "-filter_complex_threads 64"]
|
15 |
+
|
16 |
+
# Function to process data
|
17 |
+
def convert(file: _TemporaryFileWrapper, options: str):
|
18 |
+
output_file=""
|
19 |
+
video=""
|
20 |
+
stdout=""
|
21 |
+
ffmpeg=FFmpeg()
|
22 |
+
print(file)
|
23 |
+
print(options)
|
24 |
+
try:
|
25 |
+
output_file = f"{shortuuid.ShortUUID().random(length=8)}.mp4"
|
26 |
+
ffmpeg = FFmpeg(inputs={file: None}, outputs={output_file: f"{options}"}, global_options=globalopt)
|
27 |
+
ffmpeg.run(stderr=subprocess.PIPE)
|
28 |
+
# pprint(f"{stdout} {stderr}")
|
29 |
+
stdout += f"{ffmpeg.cmd}"
|
30 |
+
gr.Textbox.update(value=stdout)
|
31 |
+
gr.Video.update(value=output_file)
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
stderr=e
|
35 |
+
stdout += f"{stderr}"
|
36 |
+
return [stdout, output_file]
|
37 |
+
|
38 |
+
# Command Builder: Smooth Interpolation
|
39 |
+
def cmdb_si(a, b, c):
|
40 |
+
tuning = c.split(" β")[0]
|
41 |
+
# print(tuning)
|
42 |
+
return f"-filter:v \"minterpolate='mi_mode=mci:mc_mode=aobmc:me_mode=bidir:vsbmc=1:fps={a}'\" -r {a} -preset {b} -tune {tuning}"
|
43 |
+
|
44 |
+
# Command Builder: Frame Blending
|
45 |
+
def cmdb_fb(a, b, c):
|
46 |
+
tuning = c.split(" β")[0]
|
47 |
+
# print(tuning)
|
48 |
+
return f"-filter:v \"tblend\" -r {a} -preset {b} -tune {tuning}"
|
49 |
+
|
50 |
+
with gr.Blocks() as main:
|
51 |
+
with gr.Tabs():
|
52 |
+
with gr.TabItem("Main"):
|
53 |
+
with gr.Row():
|
54 |
+
with gr.Column() as inp_main:
|
55 |
+
input_textbox = gr.Textbox(label="FFMPEG Command")
|
56 |
+
input_video = gr.Video(label="Input Video")
|
57 |
+
with gr.Column() as out_main:
|
58 |
+
output_textbox = gr.Textbox(label="Output Logs", interactive=False)
|
59 |
+
output_video = gr.Video(label="Output Video", interactive=False)
|
60 |
+
startconv = gr.Button("Start", variant="primary").click(fn=convert, inputs=[input_video,input_textbox], outputs=[output_textbox, output_video])
|
61 |
+
clear_button = gr.ClearButton([input_textbox, input_video, output_textbox, output_video])
|
62 |
+
|
63 |
+
with gr.TabItem("Smooth Interpolation"):
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column() as inp_si:
|
66 |
+
input_fps = gr.Slider(1, 144, value=60, label="Frame Per Second (FPS)", info="Choose between 1 and 144 Fps")
|
67 |
+
input_preset = gr.Dropdown(["ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"], value=["veryslow"], label="Preset (Required)", info="Semakin lama (slow), semakin bagus hasilnya.")
|
68 |
+
input_tune = gr.Radio(["film β use for high quality movie content; lowers deblocking", "animation β good for cartoons; uses higher deblocking and more reference frames", "grain β preserves the grain structure in old, grainy film material", "stillimage β good for slideshow-like content", "fastdecode β allows faster decoding by disabling certain filters", "zerolatency β good for fast encoding and low-latency streaming", "psnr β ignore this as it is only used for codec development", "ssim β ignore this as it is only used for codec development"], value=["film β use for high quality movie content; lowers deblocking"], label="Tune (Required)", info="Tuning Setting")
|
69 |
+
input_video2 = gr.Video(label="Input Video")
|
70 |
+
input_textbox2 = gr.Textbox(label="FFMPEG Command")
|
71 |
+
|
72 |
+
with gr.Column() as out_si:
|
73 |
+
output_textbox2 = gr.Textbox(label="Output Logs", interactive=False)
|
74 |
+
output_video2 = gr.Video(label="Output Video", interactive=False)
|
75 |
+
buildcmd = gr.Button("Build FFMPEG Command", variant="primary").click(fn=cmdb_si, inputs=[input_fps,input_preset,input_tune], outputs=[input_textbox2])
|
76 |
+
startconv2 = gr.Button("Start", variant="primary").click(fn=convert, inputs=[input_video2,input_textbox2], outputs=[output_textbox2, output_video2])
|
77 |
+
clear_button2 = gr.ClearButton([input_fps, input_preset, input_tune, input_video2, input_textbox2, output_textbox2, output_video2])
|
78 |
+
|
79 |
+
with gr.TabItem("Frame Blending"):
|
80 |
+
with gr.Row():
|
81 |
+
with gr.Column() as inp_fb:
|
82 |
+
input_fps2 = gr.Slider(1, 144, value=60, label="Frame Per Second (FPS)", info="Choose between 1 and 144 Fps")
|
83 |
+
input_preset2 = gr.Dropdown(["ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow", "slower", "veryslow"], value=["veryslow"], label="Preset (Required)", info="Semakin lama (slow), semakin bagus hasilnya.")
|
84 |
+
input_tune2 = gr.Radio(["film β use for high quality movie content; lowers deblocking", "animation β good for cartoons; uses higher deblocking and more reference frames", "grain β preserves the grain structure in old, grainy film material", "stillimage β good for slideshow-like content", "fastdecode β allows faster decoding by disabling certain filters", "zerolatency β good for fast encoding and low-latency streaming", "psnr β ignore this as it is only used for codec development", "ssim β ignore this as it is only used for codec development"], value=["film β use for high quality movie content; lowers deblocking"], label="Tune (Required)", info="Tuning Setting")
|
85 |
+
input_video3 = gr.Video(label="Input Video")
|
86 |
+
input_textbox3 = gr.Textbox(label="FFMPEG Command")
|
87 |
+
|
88 |
+
with gr.Column() as out_fb:
|
89 |
+
output_textbox3 = gr.Textbox(label="Output Logs", interactive=False)
|
90 |
+
output_video3 = gr.Video(label="Output Video", interactive=False)
|
91 |
+
buildcmd2 = gr.Button("Build FFMPEG Command", variant="primary").click(fn=cmdb_fb, inputs=[input_fps2,input_preset2,input_tune2], outputs=[input_textbox3])
|
92 |
+
startconv3 = gr.Button("Start", variant="primary").click(fn=convert, inputs=[input_video3,input_textbox3], outputs=[output_textbox3, output_video3])
|
93 |
+
clear_button3 = gr.ClearButton([input_fps2, input_preset2, input_tune2, input_video3, input_textbox3, output_textbox3, output_video3])
|
94 |
+
|
95 |
+
# Launch the combined interface
|
96 |
+
if __name__ == "__main__":
|
97 |
+
main.queue(concurrency_count=5).launch()
|