forked from nlef/moonraker-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
25 changed files
with
1,790 additions
and
1,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,41 +12,44 @@ jobs: | |
name: Pre-commit | ||
strategy: | ||
matrix: | ||
python-version: ['3.8', '3.9', '3.10'] | ||
runs-on: ubuntu-latest | ||
python-version: ['3.9', '3.10', '3.11', '3.12'] | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Check out the repository | ||
uses: actions/checkout@v3.3.0 | ||
uses: actions/checkout@v4.1.1 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4.5.0 | ||
uses: actions/setup-python@v5.2.0 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: pip install -r scripts/requirements.dev.txt | ||
run: | | ||
sudo apt install ffmpeg -y | ||
pip install -r scripts/requirements.dev.txt | ||
- name: Run pre-commit on all files | ||
run: | | ||
pre-commit run --all-files --show-diff-on-failure --color=always | ||
- name: Test with pytest | ||
run: | | ||
pytest -v | ||
docker: | ||
needs: pre-commit | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- | ||
name: Set up QEMU | ||
uses: docker/setup-qemu-action@v2.1.0 | ||
uses: docker/setup-qemu-action@v3.2.0 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2.2.1 | ||
uses: docker/setup-buildx-action@v3.6.1 | ||
- | ||
name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v4.2.0 | ||
uses: docker/metadata-action@v5.5.1 | ||
with: | ||
images: lefskiy/moonraker-telegram-bot | ||
tags: | | ||
|
@@ -55,17 +58,41 @@ jobs: | |
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=sha | ||
- | ||
name: Docker meta | ||
id: meta_mjpeg | ||
uses: docker/[email protected] | ||
with: | ||
images: lefskiy/moonraker-telegram-bot | ||
flavor: | | ||
prefix=mjpeg-,onlatest=true | ||
tags: | | ||
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} | ||
type=ref,event=branch | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=sha,prefix=sha-mjpeg- | ||
- | ||
name: Login to Docker Hub | ||
uses: docker/login-action@v2.1.0 | ||
uses: docker/login-action@v3.3.0 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Build and push | ||
uses: docker/build-push-action@v3.2.0 | ||
uses: docker/build-push-action@v6.7.0 | ||
with: | ||
file: Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7 | ||
platforms: linux/amd64,linux/arm64 | ||
- | ||
name: Build and push mjpeg | ||
uses: docker/[email protected] | ||
with: | ||
file: Dockerfile-mjpeg | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta_mjpeg.outputs.tags }} | ||
labels: ${{ steps.meta_mjpeg.outputs.labels }} | ||
platforms: linux/amd64,linux/arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
FROM python:3.12.7-bookworm | ||
|
||
RUN apt update \ | ||
&& apt install -y \ | ||
ffmpeg x264 libx264-dev libuv1 \ | ||
libwebp-dev libtiff5-dev libjpeg*-turbo libjpeg*-turbo-dev libopenjp2-7-dev \ | ||
zlib1g-dev libfreetype6-dev liblcms2-dev \ | ||
build-essential python3-dev libdebuginfod-dev libunwind-dev liblz4-dev \ | ||
&& apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
|
||
WORKDIR /opt | ||
|
||
RUN groupadd moonraker-telegram-bot --gid 1000 \ | ||
&& useradd moonraker-telegram-bot --uid 1000 --gid moonraker-telegram-bot \ | ||
&& mkdir -p printer_data/logs printer_data/config timelapse timelapse_finished \ | ||
&& chown -R moonraker-telegram-bot:moonraker-telegram-bot /opt/* | ||
|
||
COPY --chown=moonraker-telegram-bot:moonraker-telegram-bot . ./moonraker-telegram-bot | ||
RUN pip3 install --no-cache-dir -r moonraker-telegram-bot/scripts/requirements.docker.opencv.txt | ||
|
||
RUN pip3 install --no-cache-dir memray==1.14.0 | ||
RUN pip3 install --no-cache-dir memory-profiler | ||
|
||
USER moonraker-telegram-bot | ||
VOLUME [ "/opt/printer_data/logs", "/opt/printer_data/config", "/opt/timelapse","/opt/timelapse_finished"] | ||
# ENTRYPOINT ["python3", "-m", "memray", "run", "--native", "--trace-python-allocators", "moonraker-telegram-bot/bot/main.py"] | ||
ENTRYPOINT ["python3", "moonraker-telegram-bot/bot/main.py"] | ||
CMD ["-c", "/opt/printer_data/config/telegram.conf", "-l", "/opt/printer_data/logs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM python:3.12.7-slim-bookworm | ||
|
||
RUN apt update \ | ||
&& apt install -y \ | ||
ffmpeg x264 libx264-dev libuv1 \ | ||
libwebp-dev libtiff5-dev libjpeg*-turbo libjpeg*-turbo-dev libopenjp2-7-dev \ | ||
zlib1g-dev libfreetype6-dev liblcms2-dev \ | ||
&& apt clean \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /opt | ||
|
||
RUN groupadd moonraker-telegram-bot --gid 1000 \ | ||
&& useradd moonraker-telegram-bot --uid 1000 --gid moonraker-telegram-bot \ | ||
&& mkdir -p printer_data/logs printer_data/config timelapse timelapse_finished \ | ||
&& chown -R moonraker-telegram-bot:moonraker-telegram-bot /opt/* | ||
|
||
COPY --chown=moonraker-telegram-bot:moonraker-telegram-bot . ./moonraker-telegram-bot | ||
RUN pip3 install --no-cache-dir -r moonraker-telegram-bot/scripts/requirements.docker.mjpeg.txt | ||
|
||
|
||
USER moonraker-telegram-bot | ||
VOLUME [ "/opt/printer_data/logs", "/opt/printer_data/config", "/opt/timelapse","/opt/timelapse_finished"] | ||
ENTRYPOINT ["python3", "moonraker-telegram-bot/bot/main.py"] | ||
CMD ["-c", "/opt/printer_data/config/telegram.conf", "-l", "/opt/printer_data/logs"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import logging | ||
|
||
from ffmpegcv.ffmpeg_reader import FFmpegReader, get_outnumpyshape, get_videofilter_cpu # type: ignore | ||
from ffmpegcv.stream_info import get_info # type: ignore | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class FFmpegReaderStreamRTCustom(FFmpegReader): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
@staticmethod | ||
def VideoReader(stream_url, codec, pix_fmt, crop_xywh, resize, resize_keepratio, resize_keepratioalign, timeout, videoinfo): | ||
vid = FFmpegReaderStreamRTCustom() | ||
videoinfo = videoinfo if videoinfo else get_info(stream_url, timeout) | ||
vid.origin_width = videoinfo.width | ||
vid.origin_height = videoinfo.height | ||
vid.fps = videoinfo.fps | ||
vid.codec = codec if codec else videoinfo.codec | ||
vid.count = videoinfo.count | ||
vid.duration = videoinfo.duration | ||
vid.pix_fmt = pix_fmt | ||
|
||
(vid.crop_width, vid.crop_height), (vid.width, vid.height), filteropt = get_videofilter_cpu( | ||
(vid.origin_width, vid.origin_height), pix_fmt, crop_xywh, resize, resize_keepratio, resize_keepratioalign | ||
) | ||
vid.size = (vid.width, vid.height) | ||
|
||
rtsp_opt = "-rtsp_transport tcp " if stream_url.startswith("rtsp://") else "" | ||
vid.ffmpeg_cmd = ( | ||
f"ffmpeg -loglevel warning " | ||
f" {rtsp_opt} " | ||
" -probesize 32 -analyzeduration 0 -fflags discardcorrupt " | ||
"-fflags nobuffer -flags low_delay -strict experimental " | ||
f" -vcodec {vid.codec} -i {stream_url}" | ||
f" {filteropt} -pix_fmt {pix_fmt} -f rawvideo pipe:" | ||
) | ||
|
||
vid.out_numpy_shape = get_outnumpyshape(vid.size, pix_fmt) | ||
return vid | ||
|
||
|
||
def FFmpegReaderStreamRTCustomInit( | ||
stream_url, codec=None, pix_fmt="bgr24", crop_xywh=None, resize=None, resize_keepratio=True, resize_keepratioalign="center", timeout=None, videoinfo=None | ||
) -> FFmpegReaderStreamRTCustom: | ||
return FFmpegReaderStreamRTCustom.VideoReader(stream_url, codec, pix_fmt, crop_xywh, resize, resize_keepratio, resize_keepratioalign, timeout=timeout, videoinfo=videoinfo) |
Oops, something went wrong.