diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 0000000..80bcd78 --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,14 @@ +pkgbase = compressor-git + pkgdesc = Video compressor service that watches input directory and compresses videos using ffmpeg + pkgver = r4.c3cc640 + pkgrel = 1 + url = https://github.com/meisterlala/compressor + arch = x86_64 + arch = aarch64 + license = MIT + makedepends = git + depends = ffmpeg + depends = go + backup = etc/compressor.env + +pkgname = compressor-git diff --git a/.dockerignore b/.dockerignore index 93b5832..f93056c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,4 +2,12 @@ test_input/ test_output/ .git/ .gitignore -Readme.md \ No newline at end of file +Readme.md + +*.mp4 + +/compressor +pkg/ +src/ + +*.pkg.tar.zst \ No newline at end of file diff --git a/.gitignore b/.gitignore index 95f8f7d..79047ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,7 @@ test_input/ test_output/ *.mp4 -/compressor \ No newline at end of file +/compressor +pkg/ +src/ +*.pkg.tar.zst \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index e4cd758..3e3ebdb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build stage -FROM golang:1.21-alpine AS builder +FROM golang:1.21 AS builder WORKDIR /app @@ -14,7 +14,7 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o compressor ./cmd/compressor # Runtime stage with CUDA support -FROM nvidia/cuda:11.8-runtime-ubuntu20.04 +FROM nvidia/cuda:13.0.1-runtime-ubuntu22.04 # Install ffmpeg and ca-certificates RUN apt-get update && apt-get install -y ffmpeg ca-certificates && rm -rf /var/lib/apt/lists/* diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..cad1fdd --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,23 @@ +# Maintainer: Misti +pkgname=compressor-git +pkgver=r4.c3cc640 +pkgrel=1 +pkgdesc="Video compressor service that watches input directory and compresses videos using ffmpeg" +arch=('x86_64' 'aarch64') +url="https://github.com/meisterlala/compressor" +license=('MIT') +depends=('ffmpeg') +makedepends=('go') + +pkgver() { + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +build() { + go build -o "$srcdir/compressor" ./cmd/compressor +} + +package() { + install -Dm755 "$srcdir/compressor" "$pkgdir/usr/bin/compressor" + install -Dm644 compressor.service "$pkgdir/usr/lib/systemd/user/compressor.service" +} diff --git a/Readme.md b/Readme.md index c945ca5..ad30b76 100644 --- a/Readme.md +++ b/Readme.md @@ -31,14 +31,46 @@ Environment variables drive the runtime configuration. Defaults are shown in par Placeholders are shell escaped before the command line is parsed, so paths containing spaces are handled safely. -## Running Locally +## Installation + +### Arch Linux (AUR) + +Build and install from source: + +```bash +git clone https://github.com/meisterlala/compressor.git +cd compressor +makepkg -si +``` + +This will: + +- Install the `compressor` binary to `/usr/bin` +- Install the systemd user service to `/usr/lib/systemd/user/` +- Install an example configuration file to `/etc/compressor.env` + +After installation, copy the example config and modify it: + +```bash +cp /etc/compressor.env ~/compressor.env +# Edit ~/compressor.env as needed +systemctl --user enable compressor.service +systemctl --user start compressor.service +``` + +### Manual Installation + +For development or manual installation: ```bash -go build -o compressor ./cmd/compressor -INPUT_DIR=$(pwd)/test_input OUTPUT_DIR=$(pwd)/test_output ./compressor +git clone https://github.com/meisterlala/compressor.git +cd compressor +./install.sh ``` -Place a video file in `test_input/` and watch it get processed to `test_output/`. The test directories are gitignored. +This builds the binary locally and sets up the user service. + +## Running Locally ## Container Notes diff --git a/build.ps1 b/build_docker.ps1 similarity index 74% rename from build.ps1 rename to build_docker.ps1 index 200f8f7..c340668 100644 --- a/build.ps1 +++ b/build_docker.ps1 @@ -1,6 +1,6 @@ # Build and push multi-arch Docker images param( - [string]$Registry = "meisterlala/compressor" + [string]$Registry = "registry.meisterlala.dev/compressor" ) # Enable experimental features for buildx @@ -10,10 +10,8 @@ docker buildx create --use --name multiarch 2>$null || docker buildx use multiar $fullTag = "$Registry`:latest" Write-Host "Building and pushing $fullTag for linux/amd64 and linux/arm64..." -docker buildx build --platform linux/amd64, linux/arm64 ` +docker buildx build --platform "linux/amd64,linux/arm64" ` --tag $fullTag ` --push . -Write-Host "Build and push complete!" - Write-Host "Build and push complete!" \ No newline at end of file diff --git a/compressor.service b/compressor.service new file mode 100644 index 0000000..652cb45 --- /dev/null +++ b/compressor.service @@ -0,0 +1,34 @@ +[Unit] +Description=Video Compressor Service +After=network.target + +[Service] +Type=simple +ExecStartPre=/bin/mkdir -p /srv/synchting/compressor_input +ExecStartPre=/bin/mkdir -p /srv/synchting/compressor_output +ExecStart=compressor +WorkingDirectory=/tmp +# Input/Output directories +Environment=INPUT_DIR=/srv/synchting/compressor_input +Environment=OUTPUT_DIR=/srv/synchting/compressor_output +# FFmpeg configuration +# Environment=FFMPEG_BIN=ffmpeg +# Environment=FFMPEG_COMMAND=-y -hwaccel cuda -hwaccel_device 0 -i {{input}} -c:v hevc_nvenc -qp 25 -preset p6 -gpu 0 -b_qfactor 1.1 -b_ref_mode middle -bf 3 -g 250 -i_qfactor 0.75 -max_muxing_queue_size 1024 -multipass 1 -rc vbr -rc-lookahead 20 -temporal-aq 1 -tune hq -c:a aac -af volume=2.0 {{output}} +# Environment=FFMPEG_COMMAND_CPU=-y -i {{input}} -c:v libx265 -preset slow -crf 24 -c:a aac -af volume=2.0 {{output}} +# Processing options +# Environment=DELETE_SOURCE=false +# Environment=PROCESSING_SUFFIX=.processing +# Environment=OUTPUT_EXTENSION=.mp4 +# Environment=VIDEO_EXTENSIONS=.mp4,.mkv,.mov,.avi,.flv,.wmv,.m4v,.webm,.ts +# Performance tuning +# Environment=QUEUE_SIZE=128 +# Environment=MAX_CONCURRENT=1 +# Environment=RESCAN_INTERVAL=30s +# Environment=FILE_STABILITY_DURATION=3s +# HTTP server +# Environment=PORT=8080 +Restart=always +RestartSec=5 + +[Install] +WantedBy=default.target \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..2f8221b --- /dev/null +++ b/install.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Install script for Video Compressor - builds package and enables service + +set -e + +echo "Building and installing compressor package..." +makepkg -si + +echo "Enabling and starting the user service..." +systemctl --user enable compressor.service +systemctl --user start compressor.service + +echo "Service status:" +systemctl --user status compressor.service + +echo "" +echo "Installation complete!" +echo "To check logs: journalctl --user -u compressor.service -f" +echo "To stop: systemctl --user stop compressor.service" +echo "To restart: systemctl --user restart compressor.service" +echo "" +echo "Configuration: Copy /etc/compressor.env to ~/compressor.env and edit as needed" \ No newline at end of file