This commit is contained in:
Hell13Cat
2026-06-02 00:44:02 +03:00
parent 4a88e4c491
commit 4cddd19c76
3 changed files with 38 additions and 4 deletions
+32 -2
View File
@@ -1,4 +1,34 @@
import PIL
import subprocess
from PIL import Image
import os
def generate_thumb():
EXTENSIONS_IMG = ('.jpg', '.jpeg', '.png', '.gif', '.webp', '.bmp')
EXTENSIONS_VID = ('.mp4', '.webm')
VALID_EXTENSIONS = EXTENSIONS_IMG + EXTENSIONS_VID
def check_ffmpeg():
try:
if os.name == 'nt': creationflags = subprocess.CREATE_NO_WINDOW
else: creationflags = 0
subprocess.run(["ffmpeg", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, creationflags=creationflags)
return True
except (FileNotFoundError, subprocess.CalledProcessError):
return False
def generate_video_thumbnail(input_path_file, output_path_file, TARGET_MIN_SIZE):
vf_scale = f"scale='if(gt(iw,ih),-1,{TARGET_MIN_SIZE})':'if(gt(iw,ih),{TARGET_MIN_SIZE},-1)'"
cmd = ["ffmpeg", "-y", "-i", input_path_file, "-ss", "00:00:00", "-vframes", "1", "-vf", vf_scale, "-q:v", "2", output_path_file]
if os.name == 'nt': creationflags = subprocess.CREATE_NO_WINDOW
else: creationflags = 0
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, creationflags=creationflags)
if result.returncode != 0:
raise Exception(f"FFmpeg error: {result.stderr.decode('utf-8', errors='ignore')}")
def video_gen():
pass
def image_and_gif_gen():
pass
def generate_thumb(source_image, thumb_folder, TARGET_MIN_SIZE):
pass