From 34b45753daffcd5a14e47452eb0219e275172638 Mon Sep 17 00:00:00 2001 From: Ed Asriyan Date: Fri, 19 Apr 2024 22:53:43 +0400 Subject: [PATCH] Add lottie-to-webm converter --- .github/workflows/build-linux-and-docker.yml | 16 ++++++++++++++++ .github/workflows/cd-release.yml | 2 ++ .github/workflows/test-darwin.yml | 2 ++ .github/workflows/test-docker.yml | 1 + .github/workflows/test-windows.yml | 3 ++- Dockerfile | 7 ++++++- README.dockerhub.md | 2 +- README.md | 19 ++++++++++++++----- bin/lottie_to_webm.sh | 9 +++++++++ 9 files changed, 53 insertions(+), 8 deletions(-) create mode 100755 bin/lottie_to_webm.sh diff --git a/.github/workflows/build-linux-and-docker.yml b/.github/workflows/build-linux-and-docker.yml index c8afd3f..aad5ff5 100644 --- a/.github/workflows/build-linux-and-docker.yml +++ b/.github/workflows/build-linux-and-docker.yml @@ -101,6 +101,22 @@ jobs: with: image: lottie-to-webp:${{ inputs.arch }} + - name: Build lottie-to-webm + uses: docker/build-push-action@v4 + with: + context: . + tags: lottie-to-webm:${{ inputs.arch }} + platforms: ${{ inputs.arch }} + target: lottie-to-webm + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Upload lottie-to-webm as artifact + uses: ishworkh/container-image-artifact-upload@v1.0.0 + with: + image: lottie-to-webm:${{ inputs.arch }} + - name: Extract executable run: | id=$(docker create lottie-to-png:${{ inputs.arch }}) && diff --git a/.github/workflows/cd-release.yml b/.github/workflows/cd-release.yml index 0464475..4dfdc85 100644 --- a/.github/workflows/cd-release.yml +++ b/.github/workflows/cd-release.yml @@ -44,6 +44,7 @@ jobs: - lottie-to-gif - lottie-to-png - lottie-to-webp + - lottie-to-webm arch: - amd64 - arm64 @@ -76,6 +77,7 @@ jobs: - gif - png - webp + - webm steps: - name: Login to DockerHub uses: docker/login-action@v2 diff --git a/.github/workflows/test-darwin.yml b/.github/workflows/test-darwin.yml index 4d4dc54..cd4f82b 100644 --- a/.github/workflows/test-darwin.yml +++ b/.github/workflows/test-darwin.yml @@ -23,6 +23,7 @@ jobs: - gif - png - webp + - webm steps: - uses: actions/checkout@v3 @@ -31,6 +32,7 @@ jobs: [[ "${{ matrix.case }}" == "apng" ]] && brew install ffmpeg || echo ok; [[ "${{ matrix.case }}" == "gif" ]] && brew install gifski || echo ok; [[ "${{ matrix.case }}" == "webp" ]] && brew install webp || echo ok; + [[ "${{ matrix.case }}" == "webm" ]] && brew install ffmpeg || echo ok; - name: Download artifact uses: actions/download-artifact@v3 diff --git a/.github/workflows/test-docker.yml b/.github/workflows/test-docker.yml index 15da3ee..147b8cb 100644 --- a/.github/workflows/test-docker.yml +++ b/.github/workflows/test-docker.yml @@ -23,6 +23,7 @@ jobs: - gif - png - webp + - webm steps: - name: Set up QEMU uses: docker/setup-qemu-action@v2 diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index 1773080..f1152e1 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -22,6 +22,7 @@ jobs: - apng - gif - png + - webm steps: - uses: actions/checkout@v3 @@ -31,7 +32,7 @@ jobs: run: cargo install gifski - name: Install ffmpeg - if: ${{ matrix.case == 'apng' }} + if: ${{ (matrix.case == 'apng') || (matrix.case == 'webm') }} uses: FedericoCarboni/setup-ffmpeg@v2 - name: Download artifact diff --git a/Dockerfile b/Dockerfile index c2c8d1e..273a7a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,10 +37,15 @@ CMD sh -c "\ done\ " -FROM builder-lottie-to-some as lottie-to-apng +FROM builder-lottie-to-some as builder-lottie-to-ffmpegable RUN apk --no-cache add ffmpeg + +FROM builder-lottie-to-ffmpegable as lottie-to-apng ENV FORMAT=apng +FROM builder-lottie-to-ffmpegable as lottie-to-webm +ENV FORMAT=webm + FROM builder-lottie-to-some as lottie-to-png ENV FORMAT=png diff --git a/README.dockerhub.md b/README.dockerhub.md index 6116868..766e1c5 100644 --- a/README.dockerhub.md +++ b/README.dockerhub.md @@ -7,7 +7,7 @@ docker run --rm -v :/source edasriyan/lottie-to-format You can provide parameters via env variables: * `HEIGHT`: Output image height. Default: 512 * `WIDTH`: Output image width. Default: 512 -* `FPS`: Output frame rate. Default: apng,png,webp - 60; gif - 50 +* `FPS`: Output frame rate. Default: apng,png,webp,webm - 60; gif - 50 * `QUALITY`: Output quality. Default: 90 * `THREADS`: Number of threads to use. Default: number of CPUs diff --git a/README.md b/README.md index b80e2c0..b32edfe 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Lottie Animations (.json) and Telegram Stickers (*.tgs) to GIF/PNG/APNG/WEBP converter +# Lottie Animations (.json) and Telegram Stickers (*.tgs) to GIF/PNG/APNG/WEBP/WEBM converter [![CI | Build & Test](https://github.com/ed-asriyan/lottie-converter/actions/workflows/ci-build-and-test.yml/badge.svg)](https://github.com/ed-asriyan/lottie-converter/actions/workflows/ci-build-and-test.yml) [![CD | Release & Push to Dockerhub](https://github.com/ed-asriyan/lottie-converter/actions/workflows/cd-release.yml/badge.svg)](https://github.com/ed-asriyan/lottie-converter/actions/workflows/cd-release.yml) @@ -32,6 +32,10 @@ Replace with directory with Lottie animations / Telegram stickers and run: ```bash docker run --rm -v :/source edasriyan/lottie-to-webp ``` +- Convert to WEBM: + ```bash + docker run --rm -v :/source edasriyan/lottie-to-webm + ``` You can provide parameters via env variables: * `HEIGHT`: Output image height. Default: 512 @@ -50,7 +54,7 @@ Results will be saved next to each source file in the same directory. ## Using compiled executables 1. Install run-time dependencies. Make sure the path to them present in `PATH` variable: - **[gifski](https://gif.ski)** if you want to convert to GIF - - **[ffmpeg](https://ffmpeg.org)** if you want to convert to APNG + - **[ffmpeg](https://ffmpeg.org)** if you want to convert to APNG or WEBM - **[img2webp](https://developers.google.com/speed/webp/docs/img2webp)** if you want to convert to WEBP 2. Download executable from [releases section of this repo](https://github.com/ed-asriyan/lottie-converter/releases) for your OS and arch 3. In downloaded archive find the following executable scripts: @@ -58,6 +62,7 @@ Results will be saved next to each source file in the same directory. - `lottie_to_gif.sh` - `lottie_to_png.sh` - `lottie_to_webp.sh` + - `lottie_to_webm.sh` All of them have the same CLI: ```commandline @@ -133,11 +138,11 @@ Results will be saved next to each source file in the same directory. ' > _deps/rlottie-src/src/vector/vdrawhelper_neon.cpp 4. Convert! - - To convert to GIF: + - To convert to GIF: ```commandline ./bin/lottie_to_gif.sh /home/ed/Downloads/animation.json ``` - - To convert to PNG: + - To convert to PNG: ```commandline ./bin/lottie_to_png.sh /home/ed/Downloads/animation.json ``` @@ -145,10 +150,14 @@ Results will be saved next to each source file in the same directory. ```commandline ./bin/lottie_to_apng.sh /home/ed/Downloads/animation.json ``` - - To convert to WEBP: + - To convert to WEBP: ```commandline ./bin/lottie_to_webp.sh /home/ed/Downloads/animation.json ``` + - To convert to WEBM: + ```commandline + ./bin/lottie_to_webm.sh /home/ed/Downloads/animation.json + ``` Results will be saved next to each source file in the same directory. ## Notices diff --git a/bin/lottie_to_webm.sh b/bin/lottie_to_webm.sh new file mode 100755 index 0000000..6189a7b --- /dev/null +++ b/bin/lottie_to_webm.sh @@ -0,0 +1,9 @@ +HEIGHT=512 +WIDTH=512 +FPS=60 +OUTPUT_EXTENSION=.webm +QUALITY=90 + +SCRIPT_DIR=$(dirname "$0") + +source $SCRIPT_DIR/lottie_common.sh && (echo | ffmpeg -y -loglevel error -r $FPS -i $TMP_PATH/%03d.png -c:v libvpx-vp9 -pix_fmt yuva420p $OUTPUT)