note.py
1.99 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
71
72
from flask import Flask, send_file,request,send_from_directory, render_template
import matlab.engine
from werkzeug.utils import secure_filename
import os
import time
import json
app = Flask(__name__)
@app.route('/', methods=['GET'])
def maiddn():
return render_template('view.html')
@app.route('/upload1', methods=['POST'])
def upload_file1():
params = json.loads(request.get_data(), encoding='utf-8')
data=params['datas']
timeData=params['timeData']
print(len(data))
print(timeData)
make_wav_file(data, timeData)
return send_file("out.wav", attachment_filename='test.wav', as_attachment=True)
@app.route('/upload', methods=['POST'])
def upload_file():
params = json.loads(request.get_data(), encoding='utf-8')
data=params['datas']
timeData=params['timeData']
print(len(data))
print(timeData)
make_wav_file(data, timeData)
time.sleep(20)
os.system("ffmpeg -i video.mp4 -i out.wav -c:v libx264 -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 -y ./static/output.mp4")
return "Success"
def make_wav_file(data, timeData):
print('convert is loading')
print(len(data))
print(timeData)
print(len(data) / timeData)
hz = int(len(data) / timeData)
print("hz=")
print(hz)
eng = matlab.engine.start_matlab()
l1=[]
for t in data:
try:
l1.append(int(t))
except:
print(t)
l2 = [n/4000 for n in l1]
data = matlab.double(l2)
filename = 'test.wav'
eng.audiowrite(filename, data, hz, nargout=0)
eng.quit()
os.system("ffmpeg -i test.wav -af volume=+10dB -y out.wav")
@app.route('/combine', methods=['POST'])
def combineMp4Wav():
print(request.files)
if 'Video' not in request.files:
print("error")
return "error"
file = request.files['Video']
file.save("video.mp4")
# os.system("ffmpeg -i video.mp4 -i test.wav -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 -y ./static/output.mp4")
return "Success"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)