Nixic commited on
Commit
512ddf3
Β·
1 Parent(s): f45a615

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -11
app.py CHANGED
@@ -1,5 +1,5 @@
1
  import os
2
- from ffmpy import FFmpeg
3
  import gradio as gr
4
  import subprocess
5
  import shortuuid
@@ -35,23 +35,48 @@ def convert(file: _TemporaryFileWrapper, options: str):
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
  # Command Builder: Advanced
51
- def cmdb_adv(a, b):
52
- tuning = b.split(" –")[0]
 
 
 
 
 
53
  #gr.Textbox.update(value=f"-preset {a} -tune {b}")
54
- return f"-preset {a} -tune {tuning}"
55
 
56
  with gr.Blocks(title="FFmo - FFmpeg Online", theme=gr.themes.Soft()) as main:
57
  with gr.Tabs():
@@ -63,7 +88,8 @@ with gr.Blocks(title="FFmo - FFmpeg Online", theme=gr.themes.Soft()) as main:
63
  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")
64
  input_video = gr.Video(label="Input Video")
65
  input_textbox = gr.Textbox(label="FFMPEG Command")
66
- buildcmd = gr.Button("Build FFMPEG Command", variant="primary").click(fn=cmdb_si, inputs=[input_fps,input_preset,input_tune], outputs=[input_textbox])
 
67
 
68
  with gr.Column() as out_si:
69
  output_textbox = gr.Textbox(label="Output Logs", interactive=False)
 
1
  import os
2
+ from ffmpy import FFmpeg, FFprobe
3
  import gradio as gr
4
  import subprocess
5
  import shortuuid
 
35
  stdout += f"{stderr}"
36
  return [stdout, output_file]
37
 
38
+ # Check Video Codec
39
+ def chk_cod(a):
40
+ command = f"ffprobe {a} 2>&1 >/dev/null"
41
+ output = subprocess.check_output(command, shell=True).decode("utf-8")
42
+ match = re.search(r"Stream.*Video.*", output)
43
+ if match:
44
+ video_info = match.group()
45
+ codec = re.sub(r".*Video: ([^, ]+).*", r"\1", video_info)
46
+ return codec
47
+
48
  # Command Builder: Smooth Interpolation
49
+ def cmdb_si(a, b, c, d):
50
+ # Check Input Video Codec
51
+ cod = chk_cod(d)
52
+ if cod == "h264":
53
+ tuning = f"-tune {c.split(' –')[0]}"
54
+ else:
55
+ tuning = ""
56
  # print(tuning)
57
+ return f"-filter:v \"minterpolate='mi_mode=mci:mc_mode=aobmc:me_mode=bidir:vsbmc=1:fps={a}'\" -r {a} -preset {b} {tuning}"
58
 
59
  # Command Builder: Frame Blending
60
+ def cmdb_fb(a, b, c, d):
61
+ # Check Input Video Codec
62
+ cod = chk_cod(d)
63
+ if cod == "h264":
64
+ tuning = f"-tune {c.split(' –')[0]}"
65
+ else:
66
+ tuning = ""
67
  # print(tuning)
68
+ return f"-filter:v \"tblend\" -r {a} -preset {b} {tuning}"
69
 
70
  # Command Builder: Advanced
71
+ def cmdb_adv(a, b, c):
72
+ # Check Input Video Codec
73
+ cod = chk_cod(c)
74
+ if cod == "h264":
75
+ tuning = f"-tune {b.split(' –')[0]}"
76
+ else:
77
+ tuning = ""
78
  #gr.Textbox.update(value=f"-preset {a} -tune {b}")
79
+ return f"-preset {a} {tuning}"
80
 
81
  with gr.Blocks(title="FFmo - FFmpeg Online", theme=gr.themes.Soft()) as main:
82
  with gr.Tabs():
 
88
  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")
89
  input_video = gr.Video(label="Input Video")
90
  input_textbox = gr.Textbox(label="FFMPEG Command")
91
+ buildcmd = gr.Button("Build FFMPEG Command", variant="primary").click(fn=cmdb_si, inputs=[input_fps,input_preset,input_tune,input_video], outputs=[input_textbox])
92
+ # input_video.change()
93
 
94
  with gr.Column() as out_si:
95
  output_textbox = gr.Textbox(label="Output Logs", interactive=False)