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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -1,19 +1,26 @@
1
  from flask import Flask, request, send_file, jsonify
2
  from moviepy.editor import ColorClip
3
  import os
 
 
 
4
 
5
  app = Flask(__name__)
6
 
7
  @app.route("/generate", methods=["POST"])
8
  def generate_video():
9
- data = request.get_json()
10
- duration = int(data.get("duration", 5)) # Default to 5 seconds if not given
 
11
 
12
- video_path = "white_video.mp4"
13
- clip = ColorClip(size=(640, 360), color=(255, 255, 255), duration=duration)
14
- clip.write_videofile(video_path, fps=24)
15
 
16
- return send_file(video_path, mimetype='video/mp4')
 
 
 
17
 
18
  if __name__ == "__main__":
19
  app.run(host="0.0.0.0", port=7860)
 
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__":
26
  app.run(host="0.0.0.0", port=7860)