|
|
from flask import Flask, request, send_file
|
|
|
import os
|
|
|
import subprocess
|
|
|
from werkzeug.utils import secure_filename
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
UPLOAD_FOLDER = "uploads"
|
|
|
OUTPUT_FOLDER = "outputs"
|
|
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
|
|
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
|
|
|
|
|
|
@app.route("/sync", methods=["POST"])
|
|
|
def sync_lips():
|
|
|
if "video" not in request.files or "audio" not in request.files:
|
|
|
return {"error": "Missing video or audio file"}, 400
|
|
|
|
|
|
video = request.files["video"]
|
|
|
audio = request.files["audio"]
|
|
|
|
|
|
video_filename = secure_filename(video.filename)
|
|
|
audio_filename = secure_filename(audio.filename)
|
|
|
|
|
|
video_path = os.path.join(UPLOAD_FOLDER, video_filename)
|
|
|
audio_path = os.path.join(UPLOAD_FOLDER, audio_filename)
|
|
|
output_path = os.path.join(OUTPUT_FOLDER, f"synced_{video_filename}")
|
|
|
|
|
|
video.save(video_path)
|
|
|
audio.save(audio_path)
|
|
|
|
|
|
|
|
|
command = ["python", "scripts/inference.py", "--video", video_path, "--audio", audio_path, "--output", output_path]
|
|
|
result = subprocess.run(command, capture_output=True, text=True)
|
|
|
|
|
|
if result.returncode != 0:
|
|
|
return {"error": "Lip sync processing failed", "details": result.stderr}, 500
|
|
|
|
|
|
return send_file(output_path, mimetype="video/mp4", as_attachment=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
app.run(debug=True, host="0.0.0.0", port=5000)
|
|
|
|