Skip to content

Commit

Permalink
Add lottie-to-webm converter
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-asriyan committed Apr 19, 2024
1 parent 013f14a commit 34b4575
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/build-linux-and-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}) &&
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cd-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- lottie-to-gif
- lottie-to-png
- lottie-to-webp
- lottie-to-webm
arch:
- amd64
- arm64
Expand Down Expand Up @@ -76,6 +77,7 @@ jobs:
- gif
- png
- webp
- webm
steps:
- name: Login to DockerHub
uses: docker/login-action@v2
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-darwin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- gif
- png
- webp
- webm
steps:
- uses: actions/checkout@v3

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- gif
- png
- webp
- webm
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- apng
- gif
- png
- webm
steps:
- uses: actions/checkout@v3

Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.dockerhub.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ docker run --rm -v <path to directory>:/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

Expand Down
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -32,6 +32,10 @@ Replace with directory with Lottie animations / Telegram stickers and run:
```bash
docker run --rm -v <path to directory>:/source edasriyan/lottie-to-webp
```
- Convert to WEBM:
```bash
docker run --rm -v <path to directory>:/source edasriyan/lottie-to-webm
```

You can provide parameters via env variables:
* `HEIGHT`: Output image height. Default: 512
Expand All @@ -50,14 +54,15 @@ 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:
- `lottie_to_apng.sh`
- `lottie_to_gif.sh`
- `lottie_to_png.sh`
- `lottie_to_webp.sh`
- `lottie_to_webm.sh`

All of them have the same CLI:
```commandline
Expand Down Expand Up @@ -133,22 +138,26 @@ Results will be saved next to each source file in the same directory.
' > _deps/rlottie-src/src/vector/vdrawhelper_neon.cpp
</details>
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
```
- To convert to APNG:
```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
Expand Down
9 changes: 9 additions & 0 deletions bin/lottie_to_webm.sh
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 34b4575

Please sign in to comment.