Skip to content

KHR0907/pytools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytools

Small Python utilities for:

  • optimizing GIF files
  • slicing a video clip into a GIF

English

Overview

This repository contains two standalone scripts:

  • gif_optimizer.py: reduces GIF file size by removing near-duplicate frames, skipping frames, resizing, and reducing colors
  • video_slicer.py: exports a selected time range from a video file as a GIF

Requirements

  • Python 3.11 or later recommended
  • Dependencies from requirements.txt

Install dependencies:

py -3.11 -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

Quick verification:

python -c "import numpy, PIL, moviepy; print('ok')"

Tools

gif_optimizer.py

Optimizes an existing GIF and writes an output file named *_optimized.gif by default.

Main options:

  • -c, --colors: reduce the color palette
  • -s, --scale: resize the GIF
  • -f, --frame-skip: keep 1 frame out of every N frames
  • --no-dedup: disable similar-frame removal
  • -t, --threshold: similarity threshold for frame deduplication
  • --target: try additional automatic reductions until the output fits a target size in KB
  • -o, --output: specify the output path

Examples:

python gif_optimizer.py input.gif
python gif_optimizer.py input.gif -c 128
python gif_optimizer.py input.gif -s 0.75
python gif_optimizer.py input.gif -f 2
python gif_optimizer.py input.gif --target 500
python gif_optimizer.py input.gif -c 128 -s 0.8 -f 2
python gif_optimizer.py input.gif -o output.gif

video_slicer.py

Exports part of a video file to a GIF using MoviePy.

Example as a Python function:

from video_slicer import slice_to_gif

slice_to_gif("clip.mp4", "result.gif", start_sec=5, end_sec=15, fps=12)

Note:

  • if you run python video_slicer.py directly, it uses the hardcoded example values in the file
  • edit those values first or import slice_to_gif() from another script

Dependencies

numpy>=2.0,<3.0
Pillow>=10.0,<12.0
moviepy>=2.0,<3.0

한국어

개요

이 저장소에는 다음 두 가지 독립 실행 스크립트가 들어 있습니다.

  • gif_optimizer.py: 유사 프레임 제거, 프레임 스킵, 리사이즈, 색상 수 축소를 통해 GIF 용량을 줄입니다.
  • video_slicer.py: 동영상의 원하는 구간만 잘라 GIF로 저장합니다.

요구 사항

  • Python 3.11 이상 권장
  • requirements.txt에 있는 패키지 설치 필요

설치:

py -3.11 -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

설치 확인:

python -c "import numpy, PIL, moviepy; print('ok')"

도구 설명

gif_optimizer.py

기존 GIF를 최적화하며, 기본적으로 *_optimized.gif 이름으로 출력 파일을 만듭니다.

주요 옵션:

  • -c, --colors: 색상 수 축소
  • -s, --scale: 이미지 크기 축소
  • -f, --frame-skip: N프레임마다 1프레임만 유지
  • --no-dedup: 유사 프레임 제거 비활성화
  • -t, --threshold: 프레임 유사도 기준값
  • --target: 목표 용량(KB)에 맞도록 추가 자동 축소 시도
  • -o, --output: 출력 경로 지정

예시:

python gif_optimizer.py input.gif
python gif_optimizer.py input.gif -c 128
python gif_optimizer.py input.gif -s 0.75
python gif_optimizer.py input.gif -f 2
python gif_optimizer.py input.gif --target 500
python gif_optimizer.py input.gif -c 128 -s 0.8 -f 2
python gif_optimizer.py input.gif -o output.gif

video_slicer.py

MoviePy를 사용해 동영상 일부 구간을 GIF로 저장합니다.

함수 사용 예시:

from video_slicer import slice_to_gif

slice_to_gif("clip.mp4", "result.gif", start_sec=5, end_sec=15, fps=12)

참고:

  • python video_slicer.py로 직접 실행하면 파일 안에 적혀 있는 예제 값으로 동작합니다.
  • 직접 실행할 경우 입력 파일명과 구간 값을 먼저 수정하거나, 다른 스크립트에서 slice_to_gif()를 import 해서 사용하는 편이 낫습니다.

의존성

numpy>=2.0,<3.0
Pillow>=10.0,<12.0
moviepy>=2.0,<3.0

About

Python scripts I made for myself

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages