-
-
Notifications
You must be signed in to change notification settings - Fork 873
Open
Description
Summary
Make thumbnail GIF generation settings configurable via Django settings, allowing users to customize duration, frame rate, and start position instead of using hardcoded values.
Problem Statement
Currently, thumbnail GIF generation in MediaCMS uses hardcoded values in files/tasks.py (lines ~319-346):
command = [
settings.FFMPEG_COMMAND,
"-y",
"-ss",
"3", # Hardcoded: start at 3 seconds
"-i",
media.media_file.path,
"-hide_banner",
"-vf",
"scale=344:-1:flags=lanczos,fps=1", # Hardcoded: 1 fps
"-t",
"25", # Hardcoded: 25 seconds duration
"-f",
"gif",
tf,
]Limitations:
- Fixed duration: Always captures 25 seconds, regardless of video length
- Cannot sample entire video: For long videos (30+ minutes), the GIF only shows content from the first 28 seconds (3s start + 25s duration)
- High frame rate: 1 fps generates 25 frames, creating large GIF files
- Not user-configurable: Requires code modification to change behavior
This contrasts with sprite generation, which already uses configurable SPRITE_NUM_SECS to sample frames across the entire video duration.
Proposed Solution
Add three new Django settings to control GIF generation:
New Settings
# cms/settings.py
# Thumbnail GIF generation settings
THUMBNAIL_GIF_START = 3 # Start position in seconds
THUMBNAIL_GIF_DURATION = 25 # Duration to capture in seconds
THUMBNAIL_GIF_FPS = 1 # Frames per secondCode Changes
File: files/tasks.py (around line 319)
# Before (hardcoded):
if profile.extension == "gif":
tf = create_temp_file(suffix=".gif")
command = [
settings.FFMPEG_COMMAND,
"-y",
"-ss",
"3",
"-i",
media.media_file.path,
"-hide_banner",
"-vf",
"scale=344:-1:flags=lanczos,fps=1",
"-t",
"25",
"-f",
"gif",
tf,
]
# After (configurable):
if profile.extension == "gif":
tf = create_temp_file(suffix=".gif")
gif_start = getattr(settings, 'THUMBNAIL_GIF_START', 3)
gif_duration = getattr(settings, 'THUMBNAIL_GIF_DURATION', 25)
gif_fps = getattr(settings, 'THUMBNAIL_GIF_FPS', 1)
command = [
settings.FFMPEG_COMMAND,
"-y",
"-ss",
str(gif_start),
"-i",
media.media_file.path,
"-hide_banner",
"-vf",
f"scale=344:-1:flags=lanczos,fps={gif_fps}",
"-t",
str(gif_duration),
"-f",
"gif",
tf,
]Benefits
1. Sample Entire Video
For long videos, users can configure to sample throughout the video:
# For a 30-minute video, take 1 frame every 60 seconds
THUMBNAIL_GIF_START = 0
THUMBNAIL_GIF_DURATION = 1800 # 30 minutes
THUMBNAIL_GIF_FPS = 0.0167 # 1/60 = 1 frame per minute = 30 frames total2. Reduce File Size
Lower frame rate for smaller GIF files:
THUMBNAIL_GIF_FPS = 0.5 # 1 frame every 2 seconds = smaller fileReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels