-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
70 lines (57 loc) · 2.75 KB
/
app.py
File metadata and controls
70 lines (57 loc) · 2.75 KB
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
61
62
63
64
65
66
67
68
69
70
import os
from flask import Flask, render_template,flash, request, redirect, url_for, session, request,logging
import urllib.request
import subprocess
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from moviepy.config import get_setting
import datetime
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
session_url = ''
@app.route('/')
def index():
subprocess.run(['rm' , 'static/cropped/new.webm'])
subprocess.run(['rm' , 'static/uploads/mysample.webm'])
return render_template('home.html')
@app.route('/search',methods = ['GET','POST'])
def search():
if request.method == 'POST':
url = (request.form['url'])
print ('Downloading Started..')
up = 0
name = 'static/uploads/mysample.webm'
session_url = name
urllib.request.urlretrieve(url, name)
print ('Download Completed!')
up = 1
dur = float(subprocess.check_output(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', name]))
#dur = subprocess.run(['ffprobe', '-i', name, '-show_format' ,'|','grep duration'])
print (dur)
tem = str(dur)
return render_template('home.html',var = up,url = url,dur = tem)
@app.route('/crop',methods = ['GET','POST'])
def crop():
if request.method == 'POST':
start = (request.form['start'])
end = (request.form['end'])
print (start,end)
hrst = (datetime.timedelta(seconds=int(start)))
hrend = (datetime.timedelta(seconds=int(end)))
print(hrst , hrend)
crurl = 'static/cropped/new.webm'
try:
print('******************************')
print(session_url)
#subprocess.run(['ffmpeg_extract_subclip(', session_url ,',', start,',', end,',', 'targetname="/downloads/cropped.webm")'])
#subprocess.run(['ffmpeg_extract_subclip( session_url, start, end, targetname="/downloads/cropped.webm")'])
subprocess.run(['ffmpeg', '-i' , 'static/uploads/mysample.webm', '-ss' , str(hrst), '-to' , str(hrend), '-c:v' , 'copy' , '-c:a' , 'copy' , 'static/cropped/new.webm'])
#subprocess.run(['ffmpeg', '-i' , 'static/uploads/mysample.webm', '-ss' , str(hrst), '-to' , str(hrend), 'static/cropped/new.webm'])
dur = float(subprocess.check_output(['ffprobe', '-v', 'error', '-show_entries', 'format=duration', '-of', 'default=noprint_wrappers=1:nokey=1', 'static/cropped/new.webm']))
err = 0
except subprocess.CalledProcessError as e:
print (e.output)
err = 1
return render_template('home.html',err = err,crurl = crurl, d = dur)
if __name__ == '__main__':
app.secret_key = 'sec123'
app.run(debug=True)