Update app.py
Browse files
app.py
CHANGED
|
@@ -7,49 +7,55 @@ if parse_version(Image.__version__) >= parse_version('10.0.0'):
|
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
from moviepy.editor import *
|
| 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 |
# Define the Gradio interface
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
-
gr.Markdown("## Video Watermarker and Outro Adder")
|
| 39 |
with gr.Row():
|
| 40 |
with gr.Column():
|
| 41 |
-
|
|
|
|
| 42 |
logo_input = gr.Image(label="Upload Your Logo", type="filepath")
|
| 43 |
outro_input = gr.Video(label="Upload Your Outro")
|
| 44 |
logo_size = gr.Slider(label="Logo Size", minimum=50, maximum=500, step=10, value=100)
|
| 45 |
-
process_button = gr.Button("Process
|
| 46 |
with gr.Column():
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
process_button.click(
|
| 50 |
-
fn=
|
| 51 |
-
inputs=[
|
| 52 |
-
outputs=
|
| 53 |
)
|
| 54 |
|
| 55 |
demo.launch()
|
|
|
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
from moviepy.editor import *
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
def process_videos(video_paths, logo_path, outro_path, logo_size):
|
| 13 |
+
output_paths = []
|
| 14 |
+
# Loop through each uploaded video path
|
| 15 |
+
for i, video_path in enumerate(video_paths):
|
| 16 |
+
main_video = VideoFileClip(video_path.name) # Use .name to get the file path
|
| 17 |
+
|
| 18 |
+
# Position the logo in the bottom right corner
|
| 19 |
+
logo = (ImageClip(logo_path)
|
| 20 |
+
.set_duration(main_video.duration)
|
| 21 |
+
.resize(height=int(logo_size))
|
| 22 |
+
.margin(right=8, bottom=8, opacity=0)
|
| 23 |
+
.set_pos(("right", "bottom")))
|
| 24 |
+
|
| 25 |
+
outro_video = VideoFileClip(outro_path)
|
| 26 |
+
|
| 27 |
+
# Add the watermark to the main video
|
| 28 |
+
final_video = CompositeVideoClip([main_video, logo])
|
| 29 |
+
|
| 30 |
+
# Concatenate the watermarked video with the outro
|
| 31 |
+
final_video = concatenate_videoclips([final_video, outro_video])
|
| 32 |
+
|
| 33 |
+
# Create a unique output path for each video
|
| 34 |
+
output_path = f"final_video_{i}.mp4"
|
| 35 |
+
final_video.write_videofile(output_path, codec="libx264")
|
| 36 |
+
output_paths.append(output_path)
|
| 37 |
+
|
| 38 |
+
return output_paths
|
| 39 |
|
| 40 |
# Define the Gradio interface
|
| 41 |
with gr.Blocks() as demo:
|
| 42 |
+
gr.Markdown("## Bulk Video Watermarker and Outro Adder")
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column():
|
| 45 |
+
# Use gr.File for multiple uploads
|
| 46 |
+
videos_input = gr.File(label="Upload Your Videos", file_types=["video"], file_count="multiple")
|
| 47 |
logo_input = gr.Image(label="Upload Your Logo", type="filepath")
|
| 48 |
outro_input = gr.Video(label="Upload Your Outro")
|
| 49 |
logo_size = gr.Slider(label="Logo Size", minimum=50, maximum=500, step=10, value=100)
|
| 50 |
+
process_button = gr.Button("Process Videos")
|
| 51 |
with gr.Column():
|
| 52 |
+
# Use gr.Gallery to display multiple output videos
|
| 53 |
+
video_outputs = gr.Gallery(label="Processed Videos")
|
| 54 |
|
| 55 |
process_button.click(
|
| 56 |
+
fn=process_videos,
|
| 57 |
+
inputs=[videos_input, logo_input, outro_input, logo_size],
|
| 58 |
+
outputs=video_outputs
|
| 59 |
)
|
| 60 |
|
| 61 |
demo.launch()
|