Skip to content

Commit

Permalink
Update GHA and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
DouweM committed Aug 5, 2023
1 parent 7616a83 commit 17c517b
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 176 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.git

# .gitignore
/.meltano/
/output/
/logs/
/.env
/.python-version
4 changes: 0 additions & 4 deletions .env.sample

This file was deleted.

85 changes: 57 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,74 @@
name: Render app to image
name: Build, Test, Push

on:
push:
schedule:
- cron: "0 0 * * 0"
- cron: "0 0 * * 0"

permissions:
contents: read
packages: write

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
render:
build-test-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
### Build
- name: Build / Checkout repository
uses: actions/checkout@v3
- name: Install FFmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Install Pixlet
run: |
export PIXLET_VERSION=$(curl https://raw.githubusercontent.com/tidbyt/community/main/PIXLET_VERSION | sed 's/v//')
echo $PIXLET_VERSION
curl -L -o pixlet.tar.gz https://github.com/tidbyt/pixlet/releases/download/v${PIXLET_VERSION}/pixlet_${PIXLET_VERSION}_linux_amd64.tar.gz
tar -xvf pixlet.tar.gz
chmod +x ./pixlet
mv pixlet /usr/local/bin/pixlet
- name: Install Python
uses: actions/setup-python@v4.7.0

- name: Build / Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build / Extract Docker metadata (tags, labels)
id: meta
uses: docker/metadata-action@v4.6.0
with:
python-version: 3.11.1
- name: Install Meltano
run: pip install meltano
- name: Install Meltano plugins
run: meltano install
- name: Render app to image
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build / Build Docker image
uses: docker/build-push-action@v4.1.1
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

### Test
- name: Test / Render app to image
env:
FFMPEG_SOURCE_URL: "rtsp://zephyr.rtsp.stream/pattern?streamKey=${{secrets.RTSP_STREAM_KEY}}"
TAP_PIXLET_MAGNIFICATION: "8"
run: |
meltano run webp
mv output/**/*.webp output/image.webp
- name: Store image
docker run -v "$(pwd)/output:/project/output" -e TAP_PIXLET_MAGNIFICATION=8 -e FFMPEG_SOURCE_URL=$FFMPEG_SOURCE_URL ${{ steps.meta.outputs.tags }}
sudo mv output/**/*.webp output/image.webp
- name: Test / Store image
uses: actions/upload-artifact@v3
with:
name: image
path: output/image.webp

### Push
- name: Push / Log in to the Container registry
uses: docker/login-action@v2.2.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push / Push Docker image
uses: docker/build-push-action@v4.1.1
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.meltano/
/.meltano
/output/
/logs/
/.env
/.python-version
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG PIXBYT_IMAGE=ghcr.io/douwem/pixbyt:main
FROM $PIXBYT_IMAGE as base

ENV APP_NAME=ffmpeg

WORKDIR /project

# Copy app files
COPY ./ ./apps/${APP_NAME}

# Install apt packages for apps
RUN cat ./apps/**/apt-packages.txt | sort | uniq > ./apps/apt-packages.txt
RUN xargs -a apps/apt-packages.txt apt-get install -y

# Install Meltano plugins for apps
RUN meltano --log-level=debug install extractors tap-pixlet--${APP_NAME}

ENTRYPOINT []
CMD meltano run ${APP_NAME}--webp
120 changes: 18 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,38 @@ Example using "SMPTE Color Bars With Timestamp" from [RTSP.stream](https://rtsp.

![Screenshot](screenshot.webp)

---

Note that this app **cannot be installed from Tidbyt's smartphone app** as it uses features that (for security reasons) are not supported in [community apps](https://tidbyt.dev/docs/publish/community-apps) that run on Tidbyt's official app server.
(Your Tidbyt does not run apps directly; it depends on a server to periodically run apps and push the resulting images to the device.)

Specifically, this app uses [Pixlib](https://github.com/DouweM/tap-pixlet/tree/main/tap_pixlet/pixlib), the unofficial standard library for [Pixlet](https://github.com/tidbyt/pixlet) (the Tidbyt app development framework), similar to how [Starlib](https://github.com/qri-io/starlib) is the unofficial standard library for [Starlark](https://github.com/google/starlark-go) (the Python-like language Tidbyt apps are written in).
It also uses [Python packages](./requirements.txt) and depends on [FFmpeg](https://ffmpeg.org/).

These features are enabled by [`tap-pixlet`](https://github.com/DouweM/tap-pixlet), an unofficial Tidbyt app runner that extends Pixlet with the Pixlib standard library and advanced abilities like reading local (image) files, reaching local network resources, and running Python scripts and packages.

To render this app to your Tidbyt or a WebP image file, follow the instructions below.
They use `tap-pixlet` to run the app, [`target-tidbyt`](https://github.com/DouweM/target-tidbyt) and [`target-webp`](https://github.com/DouweM/target-tidbyt) to push the resulting image to your Tidbyt or a WebP image file, and [Meltano](https://github.com/meltano/meltano) to tie these components together.
You can use these same components to set up your own Tidbyt app server for apps like this one, that are too advanced for the official community app server.

## Installation

1. Install [FFmpeg](https://ffmpeg.org/):

- On macOS:

```bash
brew install ffmpeg
```

- [Other operating systems](https://ffmpeg.org/download.html)

1. Install [Pixlet](https://github.com/tidbyt/pixlet):

- On macOS:

```bash
brew install tidbyt/tidbyt/pixlet
```
This app is not available through Tidbyt's mobile app as it uses features that (for security reasons) are not supported in [community apps](https://tidbyt.dev/docs/publish/community-apps) that run on Tidbyt's official app server.

- [Other operating systems](https://tidbyt.dev/docs/build/installing-pixlet)
Instead, it needs to be run using [Pixbyt](https://pixbyt.dev), a self-hosted Tidbyt app server for advanced apps.

1. Install [Meltano](https://github.com/meltano/meltano):
### 1. Set up Pixbyt

- With `pip`:
1. [Create your own Pixbyt repo](https://github.com/DouweM/pixbyt#1-create-your-own-pixbyt-repo)
2. [Configure your Tidbyt](https://github.com/DouweM/pixbyt#2-configure-your-tidbyt)

```bash
pip install meltano
```
### 2. Install the app

- [Other installation methods](https://docs.meltano.com/getting-started/installation)

1. Clone this repository and enter the new directory:
1. Add this repo as a submodule under `apps`:

```bash
git clone https://github.com/DouweM/tidbyt-ffmpeg.git
cd tidbyt-ffmpeg
git submodule add https://github.com/DouweM/tidbyt-ffmpeg.git apps/ffmpeg
```

1. Install [`tap-pixlet`](https://github.com/DouweM/tap-pixlet), [`target-tidbyt`](https://github.com/DouweM/target-tidbyt), and [`target-webp`](https://github.com/DouweM/target-tidbyt) using Meltano:
1. Add an update schedule to `apps.yml` under `schedules:`:

```bash
meltano install
```yaml
schedules:
# ...
- name: ffmpeg
interval: '*/5 * * * *' # Every 5 minutes
job: ffmpeg
```

## Configuration

1. Create your own `.env` configuration file from the sample:

```bash
cp .env.sample .env
```

1. Find your video stream URL. It needs to be supported by [FFmpeg](https://ffmpeg.org/), but most video streams are.

1. Update `.env` with your configuration:
Expand All @@ -83,56 +48,7 @@ You can use these same components to set up your own Tidbyt app server for apps

## Usage

### Render app to a WebP image file

The image will be created at `output/ffmpeg/<timestamp>.webp`.
The exact path is also printed in the command output.

#### Regular size (64x32)

```bash
meltano run webp
```

#### Magnified 8 times (512x256)

```bash
TAP_PIXLET_MAGNIFICATION=8 meltano run webp
```

### Render app to your Tidbyt

#### Configure your Tidbyt

1. If you haven't already, create your own `.env` configuration file from the sample:
```bash
cp .env.sample .env
```
1. Find your Device ID and your API Token in the Tidbyt smartphone app under Settings > General > Get API Key.
1. Update `.env` with your configuration:
```bash
TIDBYT_DEVICE_ID="<device ID>"
TIDBYT_TOKEN="<token>"
```
#### Send to foreground
The app will immediately show up on your Tidbyt.
This is useful during development.
```bash
TAP_PIXLET_BACKGROUND=false meltano run tidbyt
```
#### Send to background
The app will be added to the Tidbyt app rotation.
This is useful when you're running this command on a schedule, to make sure that the app will be up to date the next time it comes up in the app rotation.
Build and launch your Pixbyt app server:

```bash
meltano run tidbyt
```
1. [Build the app server](https://github.com/DouweM/pixbyt#4-build-the-app-server)
1. [Launch the app server](https://github.com/DouweM/pixbyt#5-launch-the-app-server)
41 changes: 0 additions & 41 deletions meltano.yml

This file was deleted.

0 comments on commit 17c517b

Please sign in to comment.