File size: 1,939 Bytes
c21bd5e
 
01b5c3c
 
d9a2e36
1589524
d9a2e36
1589524
 
01b5c3c
 
 
21fcda9
01b5c3c
21fcda9
01b5c3c
6eae906
f7b492b
 
 
df7fc6d
 
 
4872a60
 
0909044
4872a60
6eae906
01b5c3c
c21bd5e
 
1589524
2a563c7
1589524
 
c21bd5e
e4fa945
 
 
 
6eae906
e4fa945
6eae906
4872a60
 
6eae906
1589524
c21bd5e
1589524
e4fa945
6eae906
c21bd5e
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
import gradio as gr
from modeler import SfM
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from pytube import YouTube
import uuid
import os 
uid=uuid.uuid4()
if not os.path.exists(f'{uid}'):
   os.makedirs(f'{uid}')
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(vid,start_time,end_time):
    start_hr=int(start_time.split(":",2)[0])*360
    start_min=int(start_time.split(":",2)[1])*60
    start_sec=int(start_time.split(":",2)[2])
    end_hr=int(end_time.split(":",2)[0])*360
    end_min=int(end_time.split(":",2)[1])*60
    end_sec=int(end_time.split(":",2)[2])
    start=start_hr+start_min+start_sec
    end=end_hr+end_min+end_sec
    vid = f"{uid}-tmp.mp4"
    ffmpeg_extract_subclip(vid, start, end, targetname=f"{uid}-clip.mp4")
    return f"{uid}-clip.mp4"


def make_model(vid_path):
    sfm = SfM(f'{uid}/', False, f'{uid}-clip.mp4', 27)
    sfm.find_structure_from_motion()
    return f'{uid}/'
    
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(type='filepath')
        clip_vid=gr.Video()
    with gr.Row():
        start_time = gr.Textbox(label = "Start", value = "0:00:00", placeholder = "0:00:23")
        end_time = gr.Textbox(label = "End", value = "0:00:05", placeholder = "0:00:54")
        trim_clip_btn = gr.Button("Trim Clip")        
    make_btn=gr.Button()
    out=gr.Files()
    make_btn.click(make_model,clip_vid,out)
    load_yt_btn.click(load_video_yt, inp_url, [pre_vid])
    trim_clip_btn.click(trim_vid,[pre_vid,start_time,end_time],clip_vid)
app.launch()