[英]Trim video using MoviePy in flask project
@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')
錯誤:
AttributeError: '_io.BufferedRandom' object 沒有屬性 'endswith'
request.file["video"] --> FileStorage: 'aideed.mp4' ('video/mp4')
目錄文件指向static文件。 我的代碼有什么問題,有人可以幫忙嗎?
您可以這樣工作,並確保您的輸入視頻文件必須是您保存在 static 上傳文件夾中的文件:
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')
Saving an uploaded file to disk doesn't work in Flask將上傳的文件保存到磁盤在 Flask 中不起作用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.