Avi3738 commited on
Commit
488bf9d
·
verified ·
1 Parent(s): 8d76d2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -57
app.py CHANGED
@@ -1,58 +1,48 @@
1
  import gradio as gr
2
- import subprocess
3
- import os
4
- import zipfile
5
-
6
- def process_videos(video_filepaths, logo_path, outro_path):
7
- output_dir = "outputs"
8
- if not os.path.exists(output_dir):
9
- os.makedirs(output_dir)
10
- output_paths = []
11
-
12
- for video_path in video_filepaths:
13
- basename = os.path.basename(video_path)
14
- watermarked_path = os.path.join(output_dir, f"watermarked_{basename}")
15
- final_path = os.path.join(output_dir, f"final_{basename}")
16
-
17
- # Add watermark using FFmpeg
18
- subprocess.run(
19
- f"ffmpeg -y -i \"{video_path}\" -i \"{logo_path}\" -filter_complex \"overlay=10:10\" -codec:a copy \"{watermarked_path}\"",
20
- shell=True,
21
- check=True
22
- )
23
-
24
- # Add outro by concatenating video and outro
25
- subprocess.run(
26
- f"ffmpeg -y -i \"{watermarked_path}\" -i \"{outro_path}\" -filter_complex \"[0:v:0][0:a:0][1:v:0][1:a:0]concat=n=2:v=1:a=1[outv][outa]\" -map \"[outv]\" -map \"[outa]\" \"{final_path}\"",
27
- shell=True,
28
- check=True
29
- )
30
-
31
- output_paths.append(final_path)
32
-
33
- # Clean intermediate watermarked file
34
- os.remove(watermarked_path)
35
-
36
- # Zip all processed videos
37
- zip_filename = "processed_videos.zip"
38
- with zipfile.ZipFile(zip_filename, 'w') as zipf:
39
- for filepath in output_paths:
40
- zipf.write(filepath, os.path.basename(filepath))
41
- os.remove(filepath) # Remove after adding to ZIP
42
-
43
- return zip_filename
44
-
45
- demo = gr.Interface(
46
- fn=process_videos,
47
- inputs=[
48
- gr.Files(label="Upload Videos (MP4)", file_types=[".mp4"], type="filepaths"),
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
+