0
@bp_video.route('/upload', methods=['GET','POST'])
def create():
    my_file = Path(app.root_path + '/' + app.config['UPLOAD_FOLDER'] + '/videos')
    if not my_file.exists():
        os.makedirs(app.root_path + '/' + app.config['UPLOAD_FOLDER'] + '/videos')  

    if request.method == 'POST':
        if 'video' in request.files:
            file = request.files["video"]
            clip1 = VideoFileClip(file).subclip(00.01,00.10)
            clip1.write_videofile(app.root_path + '/' + app.config['UPLOAD_FOLDER'] + '/videos' + 
            'dd.mp4',codec='libx264')

Error :
AttributeError: '_io.BufferedRandom' object has no attribute 'endswith'

request.file["video"] --> FileStorage: 'aideed.mp4' ('video/mp4')

Directory file point to static file. What is wrong in my code, can anyone help?

villo
  • 54
  • 7
  • At some point you should really think about separating out the video editing out into a separate service. Otherwise your website will work for more than a handful of concurrent users. – Nils Werner Mar 06 '18 at 08:48
  • @NilsWerner Thank for your advise. I will separate a service. But my code still not working. I do a code in my local. You have any idea, which method I can use besides MoviePy. – villo Mar 06 '18 at 14:06

1 Answers1

1

You can work like this way and make sure, your input video file, must be the file that you have saved in your static upload folder:

from flask import Flask, request, session, g, redirect
from flask import url_for, abort, render_template, flash, jsonify
import os

APP_ROOT = os.path.dirname(os.path.abspath(__file__))
UPLOAD_FOLDER = os.path.join(APP_ROOT, 'static', 'videos')

# Configure Flask app and the video upload folder
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

# In controller save the file with desired name
filename = request.files['video-file']
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'video.mp4')
filename.save(full_filename)
clip1 = VideoFileClip(full_filename).subclip(00.01,00.10)
        clip1.write_videofile(app.root_path + '/' + app.config['UPLOAD_FOLDER'] 
        + '/videos' + 'dd.mp4',codec='libx264')

The whole code is taken from Saving an uploaded file to disk doesn't work in Flask

Fahad Ali
  • 19
  • 1