File size: 1,797 Bytes
e39102f
daf0716
b547fb9
 
 
 
 
e39102f
b2da359
 
7abead3
e39102f
daf0716
7abead3
b2da359
daf0716
d9be6e7
daf0716
 
 
 
b2da359
fa34786
daf0716
fa34786
 
 
 
 
 
 
 
b2da359
 
 
 
 
 
 
7abead3
 
b2da359
9f6393f
daf0716
 
b2da359
 
 
1
2
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
import gradio as gr
from moviepy.editor import AudioFileClip, ImageClip, CompositeVideoClip
from PIL import Image

# Ensure compatibility with updated PIL library
if not hasattr(Image, 'ANTIALIAS'):  # Image.ANTIALIAS is deprecated; LANCZOS is the replacement
    Image.ANTIALIAS = Image.LANCZOS

def create_video(image, audio):
    # Load the audio file
    audio_clip = AudioFileClip(audio)
    
    # Load the main image and set its duration to match the audio
    image_clip = ImageClip(image).set_duration(audio_clip.duration)
    
    # Load the logo image, resize it, and position it in the top-right corner
    logo = ImageClip("Logo.png").resize(height=100)  # Adjust the height as needed
    logo = logo.set_position(("right", "top")).set_duration(audio_clip.duration)
    
    # Create a composite video with the main image and the logo overlay
    video_clip = CompositeVideoClip([image_clip, logo]).set_audio(audio_clip)
    
    # Save the video to a temporary file with Twitter-compatible settings
    output_path = "/tmp/output_video_with_logo.mp4"
    video_clip.write_videofile(
        output_path,
        fps=30,
        codec="libx264",
        audio_codec="aac",
        preset="slow",
        ffmpeg_params=["-b:v", "2000k"]  # Adjust bitrate if needed
    )
    
    return output_path

# Create Gradio interface
iface = gr.Interface(
    fn=create_video,
    inputs=[
        gr.Image(type="filepath", label="Upload Image"),
        gr.Audio(type="filepath", label="Upload Audio")
    ],
    outputs=gr.Video(label="Output Video"),
    title="Image + Audio to Video Converter with Logo Overlay",
    description="Upload an image and an audio file to generate a video with the image and audio combined, including a logo overlay in the top-right corner."
)

iface.launch()