0

I'm working on a flask website that works with moviepy.

The basic flow is:

  1. User uploads videos(s), if more than one video uploaded these get combined into one.
  2. Save the uploaded video onto disk usig MoviePy's write_videofile().
  3. User chooses some options of what to do with the video (splitting into clips etc.).
  4. Saved video from step 2 is read back into the program, splitting operations et. are done on the video.
  5. After the operations the clip is loaded back into the disk for the user to download.

I want to skip all the writing to disk, as the video is stored as a MoviePy VideoClip within the program.

Here is some code to help you better understand my question.

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/fileUpload', methods = ["POST", "GET"])
def fileUpload():
    if request.method == "POST":
        videos = request.files.getlist('videoFiles')
        if videos:
            # THIS FUNCTION COMBINES MULTIPLE CLIPS
            fullVideo, videoDuration = vp.combineClips(videos)
            # FIRST INSTANCE OF WRITING THE VIDEO TO DISK 
            fullVideo.write_videofile("static/files/fullVideo.mp4")
            session["videoDuration"] = videoDuration

    return render_template("index.html")

@app.route('/options_selected', methods=["POST", "GET"])
def optionSelection():
    # READING THE VIDEO FROM DISK 
    video = mp.editor.VideoFileClip("static/files/fullVideo.mp4")
    if request.method == "POST":
        direction = request.form.get("direction")
        manouver = request.form.get("maneuver")
        clips = request.form.get("clips")

    # SPLITS THE VIDEO INTO CLIPS, WHICH ARE ALL MADE ONE VIDEO, TAKES IN SOME PARAMETERS
    # THAT ARE NOT RELEVANT FOR THIS QUESTION.
    trainingVideo = vp.splitVideo(video,turnFrame, manouver=manouver, numVideos=clips)

    # WRITING THE VIDEO TO DISK AGAIN 
    trainingVideo.write_videofile("static/files/final.mp4")

    return render_template("index.html", upload=True, video=True)

I have stripped a lot of code from my original file, I just want to show the basic flow of the application.

I need to use the video at different stages of the website, hence why they are all in different functions.

I want to know if there is an easier way to do this within flask. Constantly writing and reading the video into memory is extremely resource and time inefficient. Something along the lines of writing it to the flask session would be perfect, as unfortunately I can't write the whole video into session.

The video is rather large, sometimes getting over 1 hour long at 30fps 1080p.

Let me know if you need more clarification.

0 Answers0