0.0.8s
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user