|
import gradio as gr |
|
import subprocess |
|
import os |
|
|
|
def enhance_video(input_file): |
|
""" |
|
Hàm xử lý video đầu vào và trả về video đã tăng cường. |
|
""" |
|
|
|
input_path = "input.mp4" |
|
output_path = "enhanced_output.mp4" |
|
|
|
|
|
with open(input_path, "wb") as f: |
|
f.write(input_file.read()) |
|
|
|
|
|
filters = [ |
|
"unsharp=5:5:1.0", |
|
"hqdn3d=4:3:6:4", |
|
"eq=contrast=1.2:brightness=0.1" |
|
] |
|
|
|
|
|
filter_chain = ",".join(filters) |
|
|
|
|
|
command = [ |
|
"ffmpeg", |
|
"-i", input_path, |
|
"-vf", filter_chain, |
|
"-c:a", "copy", |
|
output_path |
|
] |
|
|
|
try: |
|
|
|
subprocess.run(command, check=True) |
|
return output_path |
|
except subprocess.CalledProcessError as e: |
|
return f"Lỗi khi xử lý video: {e}" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Video Enhancement with FFmpeg") |
|
gr.Markdown("Upload a video and get an enhanced version with improved quality.") |
|
|
|
with gr.Row(): |
|
input_video = gr.File(label="Upload Video") |
|
output_video = gr.Video(label="Enhanced Video") |
|
|
|
submit_button = gr.Button("Enhance Video") |
|
submit_button.click(enhance_video, inputs=input_video, outputs=output_video) |
|
|
|
|
|
demo.launch() |