from flask import Flask, render_template_string, request, send_from_directory
import os
import subprocess
app = Flask(__name__)
# Define folders for uploads and resized videos
UPLOAD_FOLDER = 'uploads'
RESIZED_FOLDER = 'resized_videos'
# Create the folders if they don't exist
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
if not os.path.exists(RESIZED_FOLDER):
os.makedirs(RESIZED_FOLDER)
# Define HTML, CSS, and JS as strings
HTML_CONTENT = '''
Video Resizer Tool
'''
@app.route('/')
def index():
return render_template_string(HTML_CONTENT)
@app.route('/resize', methods=['POST'])
def resize_video():
file = request.files['file']
width = request.form['width']
height = request.form['height']
filename = file.filename
input_path = os.path.join(UPLOAD_FOLDER, filename)
file.save(input_path)
output_filename = f"resized_{filename}"
output_path = os.path.join(RESIZED_FOLDER, output_filename)
# Use ffmpeg to resize the video
subprocess.run(['ffmpeg', '-i', input_path, '-vf', f'scale={width}:{height}', output_path])
return send_from_directory(RESIZED_FOLDER, output_filename)
if __name__ == '__main__':
app.run(debug=True)