|
|
|
|
|
from PIL import Image |
|
|
from pkg_resources import parse_version |
|
|
|
|
|
if parse_version(Image.__version__) >= parse_version('10.0.0'): |
|
|
Image.ANTIALIAS = Image.Resampling.LANCZOS |
|
|
|
|
|
import gradio as gr |
|
|
from moviepy.editor import * |
|
|
import os |
|
|
|
|
|
def process_videos(video_paths, logo_path, outro_path, logo_size): |
|
|
output_paths = [] |
|
|
|
|
|
for i, video_path in enumerate(video_paths): |
|
|
main_video = VideoFileClip(video_path.name) |
|
|
|
|
|
|
|
|
logo = (ImageClip(logo_path) |
|
|
.set_duration(main_video.duration) |
|
|
.resize(height=int(logo_size)) |
|
|
.margin(right=8, bottom=8, opacity=0) |
|
|
.set_pos(("right", "bottom"))) |
|
|
|
|
|
outro_video = VideoFileClip(outro_path) |
|
|
|
|
|
|
|
|
final_video = CompositeVideoClip([main_video, logo]) |
|
|
|
|
|
|
|
|
final_video = concatenate_videoclips([final_video, outro_video]) |
|
|
|
|
|
|
|
|
output_path = f"final_video_{i}.mp4" |
|
|
final_video.write_videofile(output_path, codec="libx264") |
|
|
output_paths.append(output_path) |
|
|
|
|
|
return output_paths |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("## Bulk Video Watermarker and Outro Adder") |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
|
|
|
videos_input = gr.File(label="Upload Your Videos", file_types=["video"], file_count="multiple") |
|
|
logo_input = gr.Image(label="Upload Your Logo", type="filepath") |
|
|
outro_input = gr.Video(label="Upload Your Outro") |
|
|
logo_size = gr.Slider(label="Logo Size", minimum=50, maximum=500, step=10, value=100) |
|
|
process_button = gr.Button("Process Videos") |
|
|
with gr.Column(): |
|
|
|
|
|
video_outputs = gr.Gallery(label="Processed Videos") |
|
|
|
|
|
process_button.click( |
|
|
fn=process_videos, |
|
|
inputs=[videos_input, logo_input, outro_input, logo_size], |
|
|
outputs=video_outputs |
|
|
) |
|
|
|
|
|
demo.launch() |
|
|
|