Skip to content

Commit

Permalink
feat: Reuse config code and add doc
Browse files Browse the repository at this point in the history
  • Loading branch information
pando85 committed Jan 17, 2024
1 parent f964a34 commit ac22e05
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 12 deletions.
149 changes: 146 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Transcoder

Transcoder is a program designed to operate on a server with two distinct types of agents for video transcoding tasks, specifically converting a video library to the x265 format using ffmpeg. The following information provides details on how to use and configure the Transcoder system.
Transcoder is a program designed to operate on a server with two distinct types of agents for video
transcoding tasks, specifically converting a video library to the x265 format using ffmpeg. The
following information provides details on how to use and configure the Transcoder system.

## Container Images

Expand All @@ -10,7 +12,147 @@ Transcoder is a program designed to operate on a server with two distinct types

## Configuration

Refer to the `config.example.yaml` file for a configuration example.
### Environment Variables

The application supports configuration through environment variables. Below is a table of supported
environment variables and their default values:

#### Server

| Variable | Description | Default Value |
| ------------------------ | ----------------------------------------------------- | --------------------- |
| `BROKER_HOST` | Broker host address | localhost |
| `BROKER_PORT` | Broker port | 5672 |
| `BROKER_USER` | Broker username | broker |
| `BROKER_PASSWORD` | Broker password | broker |
| `BROKER_TASKENCODEQUEUE` | Broker tasks queue name for encoding | tasks |
| `BROKER_TASKPGSQUEUE` | Broker tasks queue name for PGS to SRT conversion | tasks_pgstosrt |
| `BROKER_EVENTQUEUE` | Broker tasks events queue name | task_events |
| `DATABASE_DRIVER` | Database driver | postgres |
| `DATABASE_HOST` | Database host address | localhost |
| `DATABASE_PORT` | Database port | 5432 |
| `DATABASE_USER` | Database username | postgres |
| `DATABASE_PASSWORD` | Database password | postgres |
| `DATABASE_DATABASE` | Database name | transcoder |
| `DATABASE_SSLMODE` | Database SSL mode | disable |
| `LOG_LEVEL` | Log level (debug, info, warning, error, fatal) | info |
| `SCHEDULER_DOMAIN` | Base domain for worker downloads and uploads | http://localhost:8080 |
| `SCHEDULER_SCHEDULETIME` | Scheduling loop execution interval | 5m |
| `SCHEDULER_JOBTIMEOUT` | Requeue jobs running for more than specified duration | 24h |
| `SCHEDULER_DOWNLOADPATH` | Download path for workers | /data/current |
| `SCHEDULER_UPLOADPATH` | Upload path for workers | /data/processed |
| `SCHEDULER_MINFILESIZE` | Minimum file size for worker processing | 100000000 |
| `WEB_PORT` | Web server port | 8080 |
| `WEB_TOKEN` | Web server token | admin |

#### Worker

| Variable | Description | Default Value |
| -------------------------- | ---------------------------------------------------------------- | -------------------------- |
| `BROKER_HOST` | Broker host address | localhost |
| `BROKER_PORT` | Broker port | 5672 |
| `BROKER_USER` | Broker username | broker |
| `BROKER_PASSWORD` | Broker password | broker |
| `BROKER_TASKENCODEQUEUE` | Broker tasks queue name for encoding | tasks |
| `BROKER_TASKPGSQUEUE` | Broker tasks queue name for PGS to SRT conversion | tasks_pgstosrt |
| `BROKER_EVENTQUEUE` | Broker tasks events queue name | task_events |
| `LOG_LEVEL` | Set the log level (options: "debug", "info", "warning", "error") | info |
| `WORKER_TEMPORALPATH` | Path used for temporal data | system temporary directory |
| `WORKER_NAME` | Worker name used for statistics | hostname |
| `WORKER_THREADS` | Number of worker threads | number of CPU cores |
| `WORKER_ACCEPTEDJOBS` | Type of jobs the worker will accept | ["encode"] |
| `WORKER_MAXPREFETCHJOBS` | Maximum number of jobs to prefetch | 1 |
| `WORKER_ENCODEJOBS` | Number of parallel worker jobs for encoding | 1 |
| `WORKER_PGJOBS` | Number of parallel worker jobs for PGS to SRT conversion | 0 |
| `WORKER_PRIORITY` | Only accept jobs of priority X | 3 |
| `WORKER_DOTNETPATH` | Path to the dotnet executable | "/usr/bin/dotnet" |
| `WORKER_PGSTOSRTDLLPATH` | Path to the PGSToSrt.dll library | "/app/PgsToSrt.dll" |
| `WORKER_TESSERACTDATAPATH` | Path to the tesseract data | "/tessdata" |
| `WORKER_STARTAFTER` | Accept jobs only after the specified time (format: HH:mm) | - |
| `WORKER_STOPAFTER` | Stop accepting new jobs after the specified time (format: HH:mm) | - |
| `SCHEDULER_DOMAIN` | Base domain for worker downloads and uploads | http://localhost:8080 |
| `SCHEDULER_SCHEDULETIME` | Scheduling loop execution interval | 5m |
| `SCHEDULER_JOBTIMEOUT` | Requeue jobs running for more than specified duration | 24h |
| `SCHEDULER_DOWNLOADPATH` | Download path for workers | /data/current |
| `SCHEDULER_UPLOADPATH` | Upload path for workers | /data/processed |
| `SCHEDULER_MINFILESIZE` | Minimum file size for worker processing | 100000000 |
| `WEB_PORT` | Web server port | 8080 |
| `WEB_TOKEN` | Web server token | admin |

### Configuration File

The application also supports configuration through a YAML file. The default configuration file
format is YAML. If you want to use a different file format, please specify it in the `CONFIG_FILE`
environment variable.

Example YAML configuration file:

#### Server

```yaml
logLevel: info

broker:
host: localhost
port: 5672
user: broker
password: broker
taskEncodeQueue: tasks
taskPGSQueue: tasks_pgstosrt
eventQueue: task_events

database:
Driver: postgres
Host: localhost
port: 5432
User: postgres
Password: postgres
Database: transcoder
SSLMode: disable

scheduler:
domain: http://localhost:8080
scheduleTime: 5m
jobTimeout: 24h
downloadPath: /data/current
uploadPath: /data/processed
minFileSize: 100000000

web:
port: 8080
token: admin
```
#### Worker
```yaml
broker:
host: localhost
port: 5672
user: broker
password: broker
taskEncodeQueue: tasks
taskPGSQueue: tasks_pgstosrt
eventQueue: task_events

logLevel: info

worker:
temporalPath: /path/to/temp/data
name: my-worker
threads: 4
acceptedJobs:
- encode
maxPrefetchJobs: 2
encodeJobs: 2
pgJobs: 1
priority: 3
dotnetPath: /usr/local/bin/dotnet
pgsToSrtDLLPath: /custom/path/PgsToSrt.dll
tesseractDataPath: /custom/tessdata
startAfter: "08:00"
stopAfter: "17:00"
```
## Client Execution
Expand Down Expand Up @@ -42,7 +184,8 @@ docker run -it -d --restart unless-stopped \
--worker.priority 9
```

**Warning:** The PGS agent must be started in advance if PGS is detected. It should run before detection to create the RabbitMQ queue.
**Warning:** The PGS agent must be started in advance if PGS is detected. It should run before
detection to create the RabbitMQ queue.

## Add Movies from Radarr

Expand Down
2 changes: 1 addition & 1 deletion cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func DatabaseFlags() {
}

func LogLevelFlags() {
pflag.String("loglevel", "info", "Set the log level (debug, info, warning, error, fatal)")
pflag.String("log-level", "info", "Set the log level (debug, info, warning, error, fatal)")
}

func SchedulerFlags() {
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
server:
image: ghcr.io/pando85/transcoder:latest-server
environment:
LOGLEVEL: DEBUG
LOG_LEVEL: DEBUG
BROKER_HOST: rabbitmq
BROKER_USER: rabbit
BROKER_PASSWORD: rabbit_password
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for attempt in $(seq 1 $MAX_ATTEMPTS); do
exit 0
else
echo "Status is not completed yet. Waiting..."
sleep 10
sleep 1
fi
done

Expand Down
12 changes: 6 additions & 6 deletions worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (
)

type CmdLineOpts struct {
Broker broker.Config `mapstructure:"broker"`
Worker task.Config `mapstructure:"worker"`
Broker broker.Config `mapstructure:"broker"`
Worker task.Config `mapstructure:"worker"`
LogLevel string `mapstructure:"loglevel"`
}

var (
opts CmdLineOpts
ApplicationFileName string
logLevel string
)

func init() {
Expand All @@ -39,7 +39,7 @@ func init() {
}

cmd.BrokerFlags()
pflag.StringVarP(&logLevel, "log-level", "l", "info", "Set the log level (debug, info, warning, error)")
cmd.LogLevelFlags()
pflag.String("worker.temporalPath", os.TempDir(), "Path used for temporal data")
pflag.String("worker.name", hostname, "Worker Name used for statistics")
pflag.Int("worker.threads", runtime.NumCPU(), "Worker Threads")
Expand All @@ -63,7 +63,7 @@ func init() {
configFilePath := os.Getenv("CONFIG_PATH")

if configFilePath == "" {
configFilePath = "/app/config.yaml"
configFilePath = "/app/config-worker.yaml"
}

viper.SetConfigFile(configFilePath)
Expand Down Expand Up @@ -100,7 +100,7 @@ func usage() {
}

func main() {
helper.SetLogLevel(logLevel)
helper.SetLogLevel(opts.LogLevel)
wg := &sync.WaitGroup{}
ctx, cancel := context.WithCancel(context.Background())
sigs := make(chan os.Signal, 1)
Expand Down

0 comments on commit ac22e05

Please sign in to comment.