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