From 10899a30e8c092f742c0e6de7dc9b02b9597ffa5 Mon Sep 17 00:00:00 2001 From: Amber Date: Sat, 7 Mar 2026 13:11:56 -0500 Subject: [PATCH] Upgrading Python, adding --quality command, use uv instead of pipenv, change Dockerfile slightly, update README.md with changes --- .python-version | 1 + Dockerfile | 10 +++++++--- Pipfile | 11 ----------- README.md | 4 +++- pyproject.toml | 7 +++++++ uv.lock | 8 ++++++++ video_to_gif.py | 7 ++++--- 7 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 .python-version delete mode 100644 Pipfile create mode 100644 pyproject.toml create mode 100644 uv.lock diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..230693c --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.15 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8a31961..56830b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM python:3.13-slim-trixie +FROM python:3.14-slim-trixie VOLUME /home -COPY video_to_gif.py /home/video_to_gif.py +COPY video_to_gif.py pyproject.toml uv.lock .python-version /home/ WORKDIR /home @@ -13,6 +13,10 @@ RUN apt update -y && \ apt install curl -y && \ apt install build-essential -y +RUN pip install --upgrade pip && \ + pip install uv && \ + uv sync --frozen --no-dev + # https://stackoverflow.com/a/49676568 RUN curl https://sh.rustup.rs -sSf | bash -s -- -y ENV PATH="/root/.cargo/bin:${PATH}" @@ -20,4 +24,4 @@ ENV PATH="/root/.cargo/bin:${PATH}" # https://crates.io/crates/gifski RUN cargo install gifski -ENTRYPOINT ["python", "video_to_gif.py"] \ No newline at end of file +ENTRYPOINT ["uv", "run", "python", "video_to_gif.py"] \ No newline at end of file diff --git a/Pipfile b/Pipfile deleted file mode 100644 index 4eb4fed..0000000 --- a/Pipfile +++ /dev/null @@ -1,11 +0,0 @@ -[[source]] -url = "https://pypi.org/simple" -verify_ssl = true -name = "pypi" - -[packages] - -[requires] -python_version = "3.13" - -[dev-packages] diff --git a/README.md b/README.md index f6dd44d..7841911 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # video-to-gif ## video_to_gif.py usage ``` -usage: video_to_gif.py [-h] [-w WIDTH] [-r FRAMERATE] [-e] [--no_loop] [-t TAG] INPUT [INPUT ...] +usage: video_to_gif.py [-h] [-w WIDTH] [-r FRAMERATE] [-q QUALITY] [-e] [--no_loop] [-t TAG] INPUT [INPUT ...] Use ffmpeg and gifski to make GIFs from videos @@ -13,6 +13,8 @@ options: -w, --width WIDTH width of the GIF in pixels, respecting aspect ratio (default: 960) -r, --framerate FRAMERATE framerate of GIF (default: 12) + -q, --quality QUALITY + lower values reduce file size; 100 automatically assigns --extra (default: 90) -e, --extra increase quality at the expense of file size and encoding time --no_loop don't loop the animated GIF -t, --tag TAG optional tag included in file name diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7bf52dd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "video-to-gif" +version = "1.0.0" +description = "Use ffmpeg and gifski to make GIFs from videos" +readme = "README.md" +requires-python = ">=3.14" +dependencies = [] diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..c86b402 --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.14" + +[[package]] +name = "video-to-gif" +version = "1.0.0" +source = { virtual = "." } diff --git a/video_to_gif.py b/video_to_gif.py index da655da..998e65a 100644 --- a/video_to_gif.py +++ b/video_to_gif.py @@ -19,6 +19,8 @@ def get_args() -> Dict[str, Any]: help='width of the GIF in pixels, respecting aspect ratio (default: 960)') parser.add_argument('-r', '--framerate', type=str, \ default='12', help='framerate of GIF (default: 12)') + parser.add_argument('-q', '--quality', default='90', type=str, \ + help='lower values reduce file size; 100 automatically assigns --extra (default: 90)') parser.add_argument('-e', '--extra', default=False, action='store_true', \ help='increase quality at the expense of file size and encoding time') parser.add_argument('--no_loop', default=False, action='store_true', \ @@ -54,10 +56,9 @@ def generate_gif_files(inputs: List[str], args: Dict[str, Any]) -> Dict[str, Tup no_loop = args['no_loop'] extra_cmd = '' - quality = '90' - if extra: + quality = args['quality'] + if quality == '100' or extra: extra_cmd = '--extra' - quality = '100' no_loop_cmd = '' if no_loop: no_loop_cmd = '--repeat -1'