Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
from flask import Flask, request, send_file, jsonify
|
| 6 |
+
from flask_cors import CORS
|
| 7 |
+
|
| 8 |
+
app = Flask(__name__)
|
| 9 |
+
CORS(app)
|
| 10 |
+
|
| 11 |
+
def inpaint_video(input_path, output_path, x, y, w, h):
|
| 12 |
+
# Utilise FFmpeg delogo (très rapide)
|
| 13 |
+
cmd = [
|
| 14 |
+
'ffmpeg', '-y', '-i', input_path,
|
| 15 |
+
'-vf', f'delogo=x={x}:y={y}:w={w}:h={h}',
|
| 16 |
+
'-c:a', 'copy',
|
| 17 |
+
'-c:v', 'libx264', '-preset', 'ultrafast',
|
| 18 |
+
output_path
|
| 19 |
+
]
|
| 20 |
+
subprocess.run(cmd)
|
| 21 |
+
|
| 22 |
+
@app.route('/process', methods=['POST'])
|
| 23 |
+
def process():
|
| 24 |
+
if 'video' not in request.files:
|
| 25 |
+
return jsonify({"error": "Aucun fichier"}), 400
|
| 26 |
+
file = request.files['video']
|
| 27 |
+
x, y, w, h = int(request.form['x']), int(request.form['y']), int(request.form['w']), int(request.form['h'])
|
| 28 |
+
file.save("in.mp4")
|
| 29 |
+
inpaint_video("in.mp4", "out.mp4", x, y, w, h)
|
| 30 |
+
return send_file("out.mp4", mimetype='video/mp4')
|
| 31 |
+
|
| 32 |
+
@app.route('/', methods=['GET'])
|
| 33 |
+
def health():
|
| 34 |
+
return "Backend Viewify Ready!"
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
app.run(host="0.0.0.0", port=7860)
|