Ss

Video Cutter

Upload Video to Cut into 5-Second Segments

from flask import Flask, request, render_template, jsoni import os from moviepy.video.io.VideoFileClip import VideoFileClip app = Flask(__name__) UPLOAD_FOLDER = 'uploads' os.makedirs(UPLOAD_FOLDER, exist_ok=True) @app.route('/') def index(): return render_template('index.html') @app.route('/upload', methods=['POST']) def upload_file(): if 'video' not in request.files: return jsonify({'message': 'No file part'}), 400 file = request.files['video'] if file.filename == '': return jsonify({'message': 'No selected file'}), 400 file_path = os.path.join(UPLOAD_FOLDER, file.filename) file.save(file_path) # Process the video cut_videos = cut_video(file_path) return jsonify({'message': 'Video processed', 'segments': cut_videos}) def cut_video(file_path): clip = VideoFileClip(file_path) duration = int(clip.duration) segments = [] for start in range(0, duration, 5): end = min(start + 5, duration) segment_path = os.path.join(UPLOAD_FOLDER, f'segment_{start}.mp4') clip.subclip(start, end).write_videofile(segment_path, codec='libx264') segments.append(segment_path) return segments if __name__ == '__main__': app.run(debug=True)

Comments

Popular posts from this blog

Quality Sleep: Unlocking the Benefits of a Restful Night for Overall Health

Class 10th NCRT BOOK QUESTIONS AND ANSWER SOLUTION ALL CHAPTERS PDF

Women's World Cup