Skip to content

Add high-quality GIF export support - #20

Open
ax2bboud wants to merge 1 commit into
averygan:mainfrom
ax2bboud:main
Open

Add high-quality GIF export support#20
ax2bboud wants to merge 1 commit into
averygan:mainfrom
ax2bboud:main

Conversation

@ax2bboud

Copy link
Copy Markdown

This PR introduces the ability for users to download videos directly as optimized GIFs.

Key Changes

  • Frontend (index.html):
    • Added a new GIF toggle button to the format selection group.
    • Ensures the format parameter is correctly passed to the API during the download request.
  • Backend (app.py):
    • Implemented a new processing branch for the gif format.
    • Integrated ffmpeg for transcoding with a focus on quality and efficiency:
      • Framerate: Set to 15fps for smooth motion without excessive file size.
      • Resolution: Scaled to a maximum width of 480px (aspect-ratio preserved) to keep downloads fast.
      • Quality: Uses a two-pass filter (palettegen and paletteuse) to ensure the GIF uses an optimized color palette for better visual fidelity.
    • Automated cleanup of the intermediate MP4 file once the GIF conversion is complete.

How to Test

  1. Paste a video URL (e.g., from YouTube or TikTok).
  2. Click the GIF toggle in the format options.
  3. Click Fetch, then click Download.
  4. Verify that the resulting file is a high-quality .gif.

@ax2bboud

Copy link
Copy Markdown
Author

Ideally, you'd want people to choose quality and fps options but it would take away from the simplicity of the tool.

DeBondor added a commit to DeBondor/reclip that referenced this pull request Apr 11, 2026
…an#14 — cookies, playlist, AAC, GIF, batch download

- averygan#25: cookies.txt support (COOKIES_FILE auto-detected, passed to all yt-dlp calls)
- averygan#28: YouTube playlist expansion via /api/playlist endpoint (flat-playlist -J)
- averygan#29: Force AAC audio codec (-S acodec:aac) for all video/audio downloads
- averygan#20: GIF export via ffmpeg 2-pass palettegen/paletteuse, 15fps, max 480px width
- averygan#14: Batch download via /api/batch/download + /api/batch/status, ThreadPoolExecutor(3), parallel Download All
@ax2bboud ax2bboud closed this Apr 17, 2026
@ax2bboud ax2bboud reopened this Apr 17, 2026
@averygan

averygan commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR! Logic looks good - A few things before merge:

  1. Add a timeout to the ffmpeg call. The download uses timeout=300, but the conversion has none:
    ff_res = subprocess.run(ffmpeg_cmd, capture_output=True, text=True)
    palettegen/paletteuse over a long clip is slow, and a bad input could hang the worker thread indefinitely. Please add timeout=... and handle subprocess.TimeoutExpired like the download branch does

  2. Guard against long videos. A 10-min clip at 15fps/480px produces a multi-hundred-MB GIF and a very long encode. Can we cap duration (e.g. reject over N seconds with a clear error, or trim with -t)?

  3. Surface the real ffmpeg error. "Failed to create GIF" drops ff_res.stderr. Mirroring the download branch (ff_res.stderr.strip().split("\n")[-1]) would making debugging easier

@ax2bboud

Copy link
Copy Markdown
Author

Hey @averygan ! Sorry for the late reply. I've made the changes you suggested. A few considerations:

  • This requires ffprobe on PATH (ships with the ffmpeg package on most distros, but if the deploy image only has ffmpeg, the probe will silently fail-open and the duration cap won't apply.
  • 60s is my pick for the cap; easy to tune via the MAX_GIF_DURATION constant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants