from flask import Flask, render_template_string, request, send_file from moviepy.editor import VideoFileClip import os import uuid app = Flask(__name__) UPLOAD_FOLDER = 'uploads' OUTPUT_FOLDER = 'output' os.makedirs(UPLOAD_FOLDER, exist_ok=True) os.makedirs(OUTPUT_FOLDER, exist_ok=True) HTML_TEMPLATE = """ AI Shorts Generator

🎬 Auto Shorts Generator

{% if clips %}

Generated Shorts

    {% for clip in clips %}
  • Short {{ loop.index }} Download
  • {% endfor %}
{% endif %}
""" @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": video_file = request.files["video"] duration_limit = int(request.form["length"]) filename = f"{uuid.uuid4().hex}_{video_file.filename}" filepath = os.path.join(UPLOAD_FOLDER, filename) video_file.save(filepath) clip = VideoFileClip(filepath) video_duration = int(clip.duration) clips = [] for start in range(0, video_duration, duration_limit): end = min(start + duration_limit, video_duration) subclip = clip.subclip(start, end) outname = f"{uuid.uuid4().hex}_clip.mp4" outpath = os.path.join(OUTPUT_FOLDER, outname) subclip.write_videofile(outpath, codec="libx264", audio_codec="aac", verbose=False, logger=None) clips.append(outname) return render_template_string(HTML_TEMPLATE, clips=clips) return render_template_string(HTML_TEMPLATE) @app.route("/download/") def download(filename): return send_file(os.path.join(OUTPUT_FOLDER, filename), as_attachment=True) if __name__ == "__main__": app.run(debug=True)

Comments

Popular posts from this blog

Add two

Youtube