# app.py from flask import Flask, render_template_string, request, jsonify import os import uuid import subprocess app = Flask(__name__) UPLOAD_FOLDER = "uploads" OUTPUT_FOLDER = "static/videos" os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(OUTPUT_FOLDER, exist_ok=True) HTML = """ Photo + Audio To Video

Photo + Audio → Video

Generating Video...
Download Video
""" @app.route("/") def home(): return render_template_string(HTML) @app.route("/generate", methods=["POST"]) def generate(): if "image" not in request.files or "audio" not in request.files: return jsonify({"error":"Missing files"}) image = request.files["image"] audio = request.files["audio"] uid = str(uuid.uuid4()) image_path = os.path.join(UPLOAD_FOLDER, uid + "_" + image.filename) audio_path = os.path.join(UPLOAD_FOLDER, uid + "_" + audio.filename) output_filename = uid + ".mp4" output_path = os.path.join(OUTPUT_FOLDER, output_filename) image.save(image_path) audio.save(audio_path) """cmd = [ "ffmpeg", "-y", "-loop", "1", "-i", image_path, "-i", audio_path, "-c:v", "libx264", "-tune", "stillimage", "-c:a", "aac", "-b:a", "192k", "-pix_fmt", "yuv420p", "-shortest", output_path ]""" cmd = [ "ffmpeg", "-y", "-loop", "1", "-i", image_path, "-i", audio_path, "-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2", "-c:v", "libx264", "-tune", "stillimage", "-c:a", "aac", "-b:a", "192k", "-pix_fmt", "yuv420p", "-shortest", output_path ] try: subprocess.run( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True ) return jsonify({ "video_url": f"/static/videos/{output_filename}" }) except subprocess.CalledProcessError as e: return jsonify({ "error":"FFmpeg failed", "details": e.stderr.decode() }) if __name__ == "__main__": app.run(host="0.0.0.0", port=7860)