Skip to content

Instantly share code, notes, and snippets.

View AalbatrossGuy's full-sized avatar
🖥️
Programming Ofc

AG AalbatrossGuy

🖥️
Programming Ofc
View GitHub Profile
@AalbatrossGuy
AalbatrossGuy / create_thumbnail.py
Created May 15, 2025 05:44
How to create thumbnail of a video in python using OpenCV & moviepy
from dotenv import load_dotenv
from moviepy import VideoFileClip
import cv2
def create_thumbnail(file) -> None:
video = VideoFileClip(f"{os.getenv('path/to/video.mp4')}") # Get the video from storage.
filenoext = file.rsplit('.', 1)[0] # Get the filename without the extension ['mp4', 'mov', 'mkv', etc.]
get_frame = video.get_frame(3) # Get the 3rd frame from the video. You can choose the frame you need. Getting a single frame from the video helps in memory efficiency as the video doesn't need to be loaded in memory completely.
cv2.imwrite(f"{os.getenv('path/to/save/image.jpg')}", get_frame) # Save the frame to the desired path.
# Don't load the whole video in memory unless it's a lightweight video.
@AalbatrossGuy
AalbatrossGuy / flask-large-file-upload.py
Last active May 8, 2025 16:50
Uploading Large Files in Chunks via Flask
@app.route("/upload", methods=["GET", "POST"])
def upload():
if request.method =="POST":
for file in request.files: # Get the file using flask.request from your <input> tag
if file.startswith('file'):
get_file = request.files.get(file) # When uploading multiple files, use the loop
with open(f"{os.getenv('ROOT_DIRECTORY')}/{get_file.filename}", 'wb') as file_binary: # wb will create the file if it doesn't exist and write the chunk
for file_chunk in get_file.stream: # Get the file in a stream reader
file_binary.write(file_chunk)
return render_template("upload.html")