Avi3738 commited on
Commit
c4ae8a5
·
verified ·
1 Parent(s): d44a3e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -32
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
- def process_video(video_path, logo_path, outro_path, logo_size):
12
- # Load the video, logo, and outro
13
- main_video = VideoFileClip(video_path)
14
-
15
- # Position the logo in the bottom right corner
16
- logo = (ImageClip(logo_path)
17
- .set_duration(main_video.duration)
18
- .resize(height=int(logo_size))
19
- .margin(right=8, bottom=8, opacity=0)
20
- .set_pos(("right", "bottom")))
21
-
22
- outro_video = VideoFileClip(outro_path)
23
-
24
- # Add the watermark to the main video
25
- final_video = CompositeVideoClip([main_video, logo])
26
-
27
- # Concatenate the watermarked video with the outro
28
- final_video = concatenate_videoclips([final_video, outro_video])
29
-
30
- # Save the final video to a temporary file
31
- output_path = "final_video.mp4"
32
- final_video.write_videofile(output_path, codec="libx264")
33
-
34
- return output_path
 
 
 
 
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
- video_input = gr.Video(label="Upload Your Video")
 
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 Video")
46
  with gr.Column():
47
- video_output = gr.Video(label="Processed Video")
 
48
 
49
  process_button.click(
50
- fn=process_video,
51
- inputs=[video_input, logo_input, outro_input, logo_size],
52
- outputs=video_output
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()