video-2-3d / app.py
Omnibus's picture
Update app.py
21fcda9
raw
history blame
1.59 kB
import gradio as gr
from modeler import SfM
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pytube import YouTube
import uuid
uid=uuid.uuid4()
def load_video_yt(vid):
yt = YouTube(vid)
vid = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download(filename=f"{uid}-tmp.mp4")
#vid_aud = yt.streams.filter(only_audio=True)[0].download(filename=f"{uid}-tmp_aud.mp4")
print (f'Video Length: {yt.length}')
return f"{uid}-tmp.mp4"
def trim_vid():
ffmpeg_extract_subclip("video1.mp4", start_time, end_time, targetname="test.mp4")
def trim_clip(clip, start_t, end_t):
clip = Path(f"{uid}-tmp_aud.mp4")
song = AudioSegment.from_file(f"{uid}-tmp_aud.mp4", format="mp4")
start_min = int(start_t.split(":",1)[0])
start_sec = int(start_t.split(":",1)[1])
end_min = int(end_t.split(":",1)[0])
end_sec = int(end_t.split(":",1)[1])
start = ((start_min*60)+start_sec)*1000
end = ((end_min*60)+end_sec)*1000
song_clip = song[start: end]
song_clip.export(f"{uid}-trim.wav", format="wav")
print("New Audio file is created and saved")
return f"{uid}-trim.wav"
def make_model(vid_path):
sfm = SfM('results/', False, 'videos/vid1.mp4', 27)
sfm.structure_from_motion()
with gr.Blocks() as app:
with gr.Row():
inp_url=gr.Textbox(label="URL")
load_yt_btn=gr.Button()
with gr.Row():
pre_vid = gr.Video()
clip_vid=gr.Video()
out=gr.Files()
load_yt_btn.click(load_video_yt, inp_url, [pre_vid])
app.launch()