Spaces:
Paused
Paused
| import gradio as gr | |
| import os | |
| from moviepy.editor import * | |
| def edit(video, start, end, width): | |
| clip = VideoFileClip(video) | |
| clip = clip.subclip(start, end) | |
| print('original', clip.w, clip.h) | |
| w = int(width) | |
| h = int(w * clip.h / clip.w) | |
| if(h % 2 != 0): h += 1 | |
| if(w % 2 != 0): w += 1 | |
| clip = clip.resize((w,h)) | |
| clip.write_videofile('ex.mp4', audio_codec='aac') | |
| print('final', clip.w, clip.h) | |
| return ['ex.mp4', os.stat('ex.mp4').st_size / 1000000] | |
| def video_upload(video): | |
| clip = VideoFileClip(video) | |
| print(video) | |
| file_size = os.stat(video).st_size / 1000000 | |
| duration = clip.duration | |
| width = clip.w | |
| return [gr.update(maximum=duration), gr.update(maximum=duration, value=duration), gr.update(value=width) , file_size ] | |
| with gr.Blocks() as demo: | |
| #gr.Markdown("""<center><h1> Video Edito </h1></center> """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| video_in = gr.Video(label='Input Video') | |
| start_slider = gr.Slider(label='Start Time', interactive=True) | |
| end_slider = gr.Slider(label='End Time', interactive=True, value=60) | |
| width_slider = gr.Slider(label='Width (pixels)', interactive=True, minimum=100, maximum=1920, value=1920) | |
| filesize_textbox = gr.Textbox(label='File Size (MB)', interactive=False) | |
| btn = gr.Button("Run") | |
| with gr.Column(): | |
| video_out = gr.Video(label='Output Video') | |
| filesize_out_textbox = gr.Textbox(label='File Size (MB)', interactive=False) | |
| btn.click(fn=edit, inputs=[video_in, start_slider, end_slider, width_slider], outputs=[video_out, filesize_out_textbox]) | |
| video_in.upload(video_upload, video_in, [start_slider, end_slider, width_slider, filesize_textbox]) | |
| demo.launch() |