File size: 2,152 Bytes
1b05743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
from moviepy.editor import *
from PIL import ImageFont, ImageDraw, Image

def edit_video(video_file, name, author, font, filter):
    # Load the video
    clip = VideoFileClip(video_file)

    # Apply the chosen filter
    clip = eval(f"clip.{filter}()")

    # Load the font based on user input
    font_path = f"{font}.ttf"
    font_size = clip.size[0] // 10
    font = ImageFont.truetype(font_path, font_size)

    # Create an image with the author text
    author_text = f"Author: {author}"
    author_image = Image.new('RGB', (clip.w//2, clip.h//8), (0, 0, 0))
    author_draw = ImageDraw.Draw(author_image)
    author_draw.text((10, 10), author_text, font=font, fill=(255, 255, 255))

    # Create an image with the bigger text
    bigger_text = f"Author: {author}"
    bigger_image = Image.new('RGB', (clip.w//2, clip.h//4), (0, 0, 0))
    bigger_draw = ImageDraw.Draw(bigger_image)
    bigger_draw.text((10, 10), bigger_text, font=font, fill=(255, 255, 255))

    # Create a composite video with the texts
    text_clip1 = ImageClip(author_image).set_duration(4).set_position(("right", "bottom"))
    text_clip2 = ImageClip(bigger_image).set_duration(4).set_position(("right", "bottom"))
    composite_clip = CompositeVideoClip([clip, text_clip1, text_clip2])

    # Save the edited video
    output_file = f"{name}_edited.mp4"
    composite_clip.write_videofile(output_file, codec='libx264')

    return output_file

def video_editor(name, author, font, filter, video_file):
    edited_video = edit_video(video_file, name, author, font, filter)
    return edited_video

# Define the inputs and outputs for Gradio app
inputs = [
    gr.inputs.Textbox(label="Video Name"),
    gr.inputs.Textbox(label="Author Name"),
    gr.inputs.Radio(["Arial", "Barbie", "MrBeast", "OptiAgle"], label="Font"),
    gr.inputs.Radio(["blur", "rotate", "resize", "mirror"], label="Filter"),
    gr.inputs.File(label="Video File")
]

outputs = gr.outputs.File(label="Edited Video")

# Create a Gradio app interface
grapp = gr.Interface(fn=video_editor, inputs=inputs, outputs=outputs, capture_session=True)

# Run the Gradio app
grapp.launch()