From 4485e77659edc645fcaeb69511f9ce9be6401b2d Mon Sep 17 00:00:00 2001 From: ikifar2012 Date: Sun, 3 Jul 2022 02:29:00 +0000 Subject: [PATCH] first commit --- .devcontainer/Dockerfile | 21 ++++++++++ .devcontainer/devcontainer.json | 58 ++++++++++++++++++++++++++++ .env.example | 14 +++++++ .github/dependabot.yml | 12 ++++++ .github/workflows/docker-build.yml | 10 +++++ .github/workflows/docker-publish.yml | 47 ++++++++++++++++++++++ .gitignore | 2 + Dockerfile | 8 ++++ README.md | 13 +++++++ docker-compose.yml | 19 +++++++++ rootfs/ffmpeg.sh | 14 +++++++ 11 files changed, 218 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .env.example create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/docker-build.yml create mode 100644 .github/workflows/docker-publish.yml create mode 100755 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 docker-compose.yml create mode 100755 rootfs/ffmpeg.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..89d5a00 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,21 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/python-3/.devcontainer/base.Dockerfile + +# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster +ARG VARIANT="3.10-bullseye" +FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image. +# COPY requirements.txt /tmp/pip-tmp/ +# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ +# && rm -rf /tmp/pip-tmp + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..2a26239 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,58 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/python-3 +{ + "name": "Radio Coda Stream Utilities", + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "VARIANT": "3.10-bullseye", + // Options + "NODE_VERSION": "none" + } + }, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "python.defaultInterpreterPath": "/usr/local/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance", + "GitHub.copilot" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + "postCreateCommand": "pip3 install --user -r rootfs/requirements.txt", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "git": "os-provided" + } +} diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d99c548 --- /dev/null +++ b/.env.example @@ -0,0 +1,14 @@ +VBR=2500k +FPS=15 + +YOUTUBE_URL=rtmp://a.rtmp.youtube.com/live2 +KEY= + +NVIDIA_VISIBLE_DEVICES=all +NVIDIA_DRIVER_CAPABILITIES=all + +VIDEO_SOURCE=/data/bg.gif +AUDIO_SOURCE= + +NP_SOURCE=/data/song.txt +FONT=/data/BebasNeue-Regular.ttf diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5878dd9 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: + # Maintain dependencies for docker + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every weekday + interval: "daily" \ No newline at end of file diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..b0a0fb9 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,10 @@ + +name: docker-build +on: [push, pull_request] +jobs: + build-image: + runs-on: ubuntu-latest + steps: + - name: Build Docker Image + uses: actions/checkout@v3 + - run: docker build . -t latest \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..e94a292 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,47 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Create and publish a Docker image + +on: + workflow_dispatch: + release: + types: ["published"] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..cc25533 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.env +data/* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aa0ee36 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM nvidia/cuda:11.7.0-base-ubuntu20.04 +COPY rootfs / +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && apt-get install -y --no-install-recommends \ + ffmpeg +RUN ln -s /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1 /usr/lib/x86_64-linux-gnu/libnvcuvid.so +RUN ln -s /usr/lib/x86_64-linux-gnu/libnvidia-encode.so.1 /usr/lib/x86_64-linux-gnu/libnvidia-encode.so +ENTRYPOINT ["/ffmpeg.sh"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5599ffb --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Radio Coda Stream Utilities +The following repository contains the Docker image for ffmpeg which runs the Radio Coda Stream. + +This script was modified from [@ohld](https://github.com/ohld)'s article [How to create your 24/7 YouTube online radio](https://okhlopkov.medium.com/how-to-create-your-24-7-youtube-online-radio-ca9e6834c192) + +Docker image and modifications made by [@ikifar2012](https://github.com/ikifar2012) + +## Technical overview +The Docker image consists of the ffmpeg script required to run the Radio Coda Stream, it relies on the [Radio Coda Stream Utilities](https://github.com/Project-Coda/Radio-Coda-Stream-Utilities) +to provide the now playing information and [Azuracast] to provide the audio stream. + +[Azuracast]: https://github.com/AzuraCast/AzuraCast +[s6-overlay]: https://github.com/just-containers/s6-overlay \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..27dacf2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +services: + stream: + restart: always + build: . + ports: + - "5000:5000" + - "5001:5001" + - "5410:5410" # required for authnentication + volumes: + - ./data:/data + env_file: + - ./.env + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu] \ No newline at end of file diff --git a/rootfs/ffmpeg.sh b/rootfs/ffmpeg.sh new file mode 100755 index 0000000..9977b89 --- /dev/null +++ b/rootfs/ffmpeg.sh @@ -0,0 +1,14 @@ +#!/bin/bash +ldconfig && ffmpeg \ + -y -vsync 0 -hwaccel cuda -hwaccel_output_format cuda \ + -re -f lavfi -i "movie=filename=$VIDEO_SOURCE:loop=0, setpts=N/(FRAME_RATE*TB)" \ + -thread_queue_size 1024 -i "$AUDIO_SOURCE" \ + -map 0:v:0 -map 1:a:0 \ + -map_metadata:g 1:g \ + -filter:v fps=$FPS \ + -vf drawtext="fontsize=50: fontfile=$FONT: \ + box=0: boxcolor=black@0.5: boxborderw=20: \ + textfile=$NP_SOURCE: reload=1: fontcolor=white@0.8: x=50: y=th" \ + -c:v h264_nvenc -g $(($FPS * 2)) \ + -b:v $VBR \ + -f flv "$YOUTUBE_URL/$KEY" \ No newline at end of file