import gradio as gr from moviepy.editor import VideoFileClip, TextClip, CompositeVideoClip from moviepy.video.fx.all import speedx, rotate, multiply_brightness, colorx from moviepy.video.fx.all import lum_contrast def video_editor(input_video, start_time, end_time, playback_speed, create_gif, rotation_degrees, watermark_text, brightness_factor, contrast, saturation): # Load video clip = VideoFileClip(input_video).subclip(start_time, end_time) # Change playback speed if applicable if playback_speed != 1: clip = speedx(clip, factor=playback_speed) # Rotate the video if applicable if rotation_degrees != 0: clip = rotate(clip, rotation_degrees) # Adjust brightness if applicable if brightness_factor != 1: clip = multiply_brightness(clip, brightness_factor) # Adjust contrast if applicable if contrast != 1: clip = lum_contrast(clip, contrast=contrast - 1) # Adjust color saturation if applicable if saturation != 1: clip = colorx(clip, factor=saturation) # Add text watermark if applicable if watermark_text: txt_clip = TextClip(watermark_text, fontsize=24, color='white', bg_color='black') txt_clip = txt_clip.set_position(('right', 'bottom')).set_duration(clip.duration) clip = CompositeVideoClip([clip, txt_clip]) # Define output paths output_video_path = "edited_video.mp4" output_gif_path = "edited_video.gif" if not create_gif: # Write video file with the edits clip.write_videofile(output_video_path, codec="libx264", audio_codec="aac") return output_video_path else: # Write GIF file with the edits clip.write_gif(output_gif_path) return output_gif_path iface = gr.Interface( fn=video_editor, inputs=[ gr.Video(source="upload", type="file", label="Input Video"), gr.Textbox(value="00:00:00", label="Start Time (HH:MM:SS)"), gr.Textbox(value="00:00:10", label="End Time (HH:MM:SS)"), gr.Slider(minimum=0.25, maximum=4.0, value=1, step=0.25, label="Playback Speed"), gr.Checkbox(label="Create GIF instead of video", value=False), gr.Slider(minimum=0, maximum=360, value=0, step=90, label="Rotation (Degrees)"), gr.Textbox(value="", label="Watermark Text"), gr.Slider(minimum=0.5, maximum=2.0, value=1, step=0.1, label="Brightness Factor"), gr.Slider(minimum=0.1, maximum=2.0, value=1, step=0.1, label="Contrast"), gr.Slider(minimum=0, maximum=2.0, value=1, step=0.1, label="Saturation") ], outputs=gr.Video(label="Output Video/GIF"), examples=[ ["sample_video.mp4", "00:00:02", "00:00:05", 1, False, 0, "", 1, 1, 1], ] ) iface.launch()