Update app.py
Browse files
app.py
CHANGED
|
@@ -1,58 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
gr.File(label="Upload Logo (PNG)", file_types=[".png"], type="filepath"),
|
| 50 |
-
gr.File(label="Upload Outro Video (MP4)", file_types=[".mp4"], type="filepath")
|
| 51 |
-
],
|
| 52 |
-
outputs=gr.File(label="Download ZIP of Processed Videos"),
|
| 53 |
-
title="Bulk Video Watermark and Outro Adder",
|
| 54 |
-
description="Upload multiple videos, a logo image, and an outro video to add watermark and append outro in bulk."
|
| 55 |
-
)
|
| 56 |
-
|
| 57 |
-
if __name__ == "__main__":
|
| 58 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from moviepy.editor import *
|
| 3 |
+
|
| 4 |
+
def process_video(video_path, logo_path, outro_path, logo_position, logo_size):
|
| 5 |
+
# Load the video, logo, and outro
|
| 6 |
+
main_video = VideoFileClip(video_path)
|
| 7 |
+
logo = (ImageClip(logo_path)
|
| 8 |
+
.set_duration(main_video.duration)
|
| 9 |
+
.resize(height=int(logo_size))
|
| 10 |
+
.margin(right=8, top=8, opacity=0)
|
| 11 |
+
.set_pos((logo_position)))
|
| 12 |
+
|
| 13 |
+
outro_video = VideoFileClip(outro_path)
|
| 14 |
+
|
| 15 |
+
# Add the watermark to the main video
|
| 16 |
+
final_video = CompositeVideoClip([main_video, logo])
|
| 17 |
+
|
| 18 |
+
# Concatenate the watermarked video with the outro
|
| 19 |
+
final_video = concatenate_videoclips([final_video, outro_video])
|
| 20 |
+
|
| 21 |
+
# Save the final video to a temporary file
|
| 22 |
+
output_path = "final_video.mp4"
|
| 23 |
+
final_video.write_videofile(output_path, codec="libx264")
|
| 24 |
+
|
| 25 |
+
return output_path
|
| 26 |
+
|
| 27 |
+
# Define the Gradio interface
|
| 28 |
+
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("## Video Watermarker and Outro Adder")
|
| 30 |
+
with gr.Row():
|
| 31 |
+
with gr.Column():
|
| 32 |
+
video_input = gr.Video(label="Upload Your Video")
|
| 33 |
+
logo_input = gr.Image(label="Upload Your Logo", type="filepath")
|
| 34 |
+
outro_input = gr.Video(label="Upload Your Outro")
|
| 35 |
+
logo_position = gr.Dropdown(label="Logo Position", choices=["left", "center", "right"], value="right")
|
| 36 |
+
logo_size = gr.Slider(label="Logo Size", minimum=50, maximum=500, step=10, value=100)
|
| 37 |
+
process_button = gr.Button("Process Video")
|
| 38 |
+
with gr.Column():
|
| 39 |
+
video_output = gr.Video(label="Processed Video")
|
| 40 |
+
|
| 41 |
+
process_button.click(
|
| 42 |
+
fn=process_video,
|
| 43 |
+
inputs=[video_input, logo_input, outro_input, logo_position, logo_size],
|
| 44 |
+
outputs=video_output
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
demo.launch()
|
| 48 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|