Skip to content

Commit

Permalink
Add preview conversion script
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Sep 24, 2024
1 parent d3f366e commit 520e6e8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .utils/previews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
import ffmpeg
import pathlib

import common


def convert_mp4_previews(pack_set: pathlib.Path) -> None:
previews = pack_set / "preview"

for preview in previews.glob("*.mp4"):
probe = ffmpeg.probe(preview)

for stream in probe["streams"]:
if stream["codec_type"] == "video":
break
else: # Did not break, so no video stream
print(f"Preview has no video: {preview.relative_to(common.packs_root)}")
continue

convert = ffmpeg.input(str(preview))

# Personal ease of use: when captured from qFlipper with BlueRecorder,
# this crops to fit the preview window perfectly
if stream["width"] == 862 and stream["height"] == 532:
convert = convert.crop(width=512, height=256, x=66, y=82)

convert = convert.output(str(preview.with_suffix(".gif")))
convert.run()


if __name__ == "__main__":
for pack_set in common.cli_pack_sets():
convert_mp4_previews(pack_set)
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ endif
check: venv requirements
./.venv/bin/python3 .utils/check.py $(CHECK_ARGS)

# If the first argument is "previews"...
ifeq (previews,$(firstword $(MAKECMDGOALS)))
# use the rest as arguments for "previews"
PREVIEWS_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
$(eval $(PREVIEWS_ARGS):;@:)
endif

.PHONY: previews
previews: venv requirements
./.venv/bin/python3 .utils/previews.py $(PREVIEWS_ARGS)

venv:
python3 -m venv .venv

Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ The scope of this repo is keeping the asset packs themselves updated and recompi
You can do this by:
```bash
make repack [pack-name]
# OR
python .utils/repack.py [pack-name]
```

Currently we don't have a convenient way of generating previews. For now what we do is:
- For Icons: use [qFlipper](https://flipperzero.one/update), click 'Save Screenshot'
- For Anims: use [qFlipper](https://flipperzero.one/update), record it (e.g. with [Blue Recorder](https://flathub.org/apps/sa.sy.bluerecorder)), cut it with `ffmpeg -i in.gif -vf "crop=512:256:66:82" out.gif`
- For Anims: use [qFlipper](https://flipperzero.one/update), record it, put `.mp4` in `pack-name/preview` folder, run `make previews [pack-name]` (or `python .utils/previews.py [pack-name]`) to convert to `.gif`
- To make cropping easier, you can use [Blue Recorder](https://flathub.org/apps/sa.sy.bluerecorder)'s Window capture: the above script will notice the right pixel sizes (862x532) and crop to fit qFlipper's preview
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
black==24.3.0
heatshrink2==0.13.0
pillow==10.3.0
ffmpeg-python==0.2.0

0 comments on commit 520e6e8

Please sign in to comment.