sreepathi-ravikumar commited on
Commit
89193d4
·
verified ·
1 Parent(s): 3bde6e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -1,25 +1,31 @@
1
- from flask import Flask, request, send_file, jsonify
2
  from moviepy.editor import ColorClip
3
- import os
4
- import moviepy.config as mpconf
5
-
6
- mpconf.change_settings({"FFMPEG_BINARY": "ffmpeg"})
7
 
8
  app = Flask(__name__)
9
 
 
 
 
 
10
  @app.route("/generate", methods=["POST"])
11
  def generate_video():
12
  try:
13
  data = request.get_json()
14
  duration = int(data.get("duration", 5))
15
 
16
- video_path = "/app/white_video.mp4"
 
 
 
17
  clip = ColorClip(size=(640, 360), color=(255, 255, 255), duration=duration)
18
- clip.write_videofile(video_path, fps=24)
19
 
20
  return send_file(video_path, mimetype='video/mp4')
 
21
  except Exception as e:
22
- print("ERROR:", e)
23
  return jsonify({"error": str(e)}), 500
24
 
25
  if __name__ == "__main__":
 
1
+ from flask import Flask, request, jsonify, send_file
2
  from moviepy.editor import ColorClip
3
+ import traceback
4
+ import uuid
 
 
5
 
6
  app = Flask(__name__)
7
 
8
+ @app.route("/")
9
+ def home():
10
+ return "Flask Video Generator is Running"
11
+
12
  @app.route("/generate", methods=["POST"])
13
  def generate_video():
14
  try:
15
  data = request.get_json()
16
  duration = int(data.get("duration", 5))
17
 
18
+ if duration <= 0 or duration > 60:
19
+ return jsonify({"error": "Duration must be between 1 and 60 seconds"}), 400
20
+
21
+ video_path = f"./white_video_{uuid.uuid4().hex}.mp4"
22
  clip = ColorClip(size=(640, 360), color=(255, 255, 255), duration=duration)
23
+ clip.write_videofile(video_path, fps=24, codec="libx264")
24
 
25
  return send_file(video_path, mimetype='video/mp4')
26
+
27
  except Exception as e:
28
+ traceback.print_exc()
29
  return jsonify({"error": str(e)}), 500
30
 
31
  if __name__ == "__main__":