Skip to content

Commit

Permalink
Add presets support
Browse files Browse the repository at this point in the history
  • Loading branch information
zoriya committed Mar 8, 2024
1 parent 411e05e commit e3cc80d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ CACHE_ROOT=/tmp/kyoo_cache
LIBRARY_LANGUAGES=en
# Hardware transcoding (equivalent of --profile docker compose option).
COMPOSE_PROFILES= # vaapi or qsv or nvidia
# the preset used during transcode. faster means worst quality, you can probably use a slower preset with hwaccels
# warning: using vaapi hwaccel disable presets (they are not supported).
GOCODER_PRESET=fast

# A pattern (regex) to ignore video files.
LIBRARY_IGNORE_PATTERN=.*/[dD]ownloads?/.*
Expand Down
2 changes: 1 addition & 1 deletion INSTALLING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ vainfo: Supported profile and entrypoints
VAProfileHEVCSccMain444_10 : VAEntrypointEncSliceLP
```
Kyoo will default to use your primary card (located at `/dev/dri/renderD128`). If you need to specify a secondary one, you
can use the `GOTRANSCODER_VAAPI_RENDERER` env-var to specify `/dev/dri/renderD129` or another one.
can use the `GOCODER_VAAPI_RENDERER` env-var to specify `/dev/dri/renderD129` or another one.

Then you can simply run kyoo using `docker compose --profile vaapi up -d` (notice the `--profile vaapi` added)
You can also add `COMPOSE_PROFILES=vaapi` to your `.env` instead of adding the `--profile` flag.
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ services:
devices:
- capabilities: [gpu]
environment:
- GOTRANSCODER_HWACCEL=nvidia
- GOCODER_HWACCEL=nvidia
profiles: ['nvidia']

transcoder-vaapi:
<<: *transcoder-base
devices:
- /dev/dri:/dev/dri
environment:
- GOTRANSCODER_HWACCEL=vaapi
- GOTRANSCODER_VAAPI_RENDERER=${GOTRANSCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
- GOCODER_HWACCEL=vaapi
- GOCODER_VAAPI_RENDERER=${GOCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
profiles: ['vaapi']
# qsv is the same setup as vaapi but with the hwaccel env var different
transcoder-qsv:
<<: *transcoder-base
devices:
- /dev/dri:/dev/dri
environment:
- GOTRANSCODER_HWACCEL=qsv
- GOTRANSCODER_VAAPI_RENDERER=${GOTRANSCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
- GOCODER_HWACCEL=qsv
- GOCODER_VAAPI_RENDERER=${GOCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
profiles: ['qsv']

ingress:
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,25 @@ services:
devices:
- capabilities: [gpu]
environment:
- GOTRANSCODER_HWACCEL=nvidia
- GOCODER_HWACCEL=nvidia
profiles: ['nvidia']

transcoder-vaapi:
<<: *transcoder-base
devices:
- /dev/dri:/dev/dri
environment:
- GOTRANSCODER_HWACCEL=vaapi
- GOTRANSCODER_VAAPI_RENDERER=${GOTRANSCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
- GOCODER_HWACCEL=vaapi
- GOCODER_VAAPI_RENDERER=${GOCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
profiles: ['vaapi']
# qsv is the same setup as vaapi but with the hwaccel env var different
transcoder-qsv:
<<: *transcoder-base
devices:
- /dev/dri:/dev/dri
environment:
- GOTRANSCODER_HWACCEL=qsv
- GOTRANSCODER_VAAPI_RENDERER=${GOTRANSCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
- GOCODER_HWACCEL=qsv
- GOCODER_VAAPI_RENDERER=${GOCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
profiles: ['qsv']

ingress:
Expand Down
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ services:
devices:
- capabilities: [gpu]
environment:
- GOTRANSCODER_HWACCEL=nvidia
- GOCODER_HWACCEL=nvidia
profiles: ['nvidia']

transcoder-vaapi:
<<: *transcoder-base
devices:
- /dev/dri:/dev/dri
environment:
- GOTRANSCODER_HWACCEL=vaapi
- GOTRANSCODER_VAAPI_RENDERER=${GOTRANSCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
- GOCODER_HWACCEL=vaapi
- GOCODER_VAAPI_RENDERER=${GOCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
profiles: ['vaapi']
# qsv is the same setup as vaapi but with the hwaccel env var different
transcoder-qsv:
<<: *transcoder-base
devices:
- /dev/dri:/dev/dri
environment:
- GOTRANSCODER_HWACCEL=qsv
- GOTRANSCODER_VAAPI_RENDERER=${GOTRANSCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
- GOCODER_HWACCEL=qsv
- GOCODER_VAAPI_RENDERER=${GOCODER_VAAPI_RENDERER:-/dev/dri/renderD128}
profiles: ['qsv']

ingress:
Expand Down
21 changes: 14 additions & 7 deletions transcoder/src/hwaccel.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ import (
)

func DetectHardwareAccel() HwAccelT {
name := GetEnvOr("GOTRANSCODER_HWACCEL", "disabled")
name := GetEnvOr("GOCODER_HWACCEL", "disabled")
if name == "disabled" {
name = GetEnvOr("GOTRANSCODER_HWACCEL", "disabled")
}
log.Printf("Using hardware acceleration: %s", name)

// superfast or ultrafast would produce a file extremly big so we prever to ignore them. Fast is available on all hw accel modes
// so we use that by default.
// vaapi does not have any presets so this flag is unused for vaapi hwaccel.
preset := GetEnvOr("GOCODER_PRESET", "fast")

switch name {
case "disabled":
return HwAccelT{
Name: "disabled",
DecodeFlags: []string{},
EncodeFlags: []string{
"-c:v", "libx264",
// superfast or ultrafast would produce a file extremly big so we prever veryfast or faster.
"-preset", "fast",
"-preset", preset,
// sc_threshold is a scene detection mechanisum used to create a keyframe when the scene changes
// this is on by default and inserts keyframes where we don't want to (it also breaks force_key_frames)
// we disable it to prevents whole scenes from behing removed due to the -f segment failing to find the corresonding keyframe
Expand All @@ -38,7 +45,7 @@ func DetectHardwareAccel() HwAccelT {
},
EncodeFlags: []string{
"-c:v", "h264_nvenc",
"-preset", "fast",
"-preset", preset,
// the exivalent of -sc_threshold on nvidia.
"-no-scenecut", "1",
},
Expand All @@ -51,7 +58,7 @@ func DetectHardwareAccel() HwAccelT {
Name: name,
DecodeFlags: []string{
"-hwaccel", "vaapi",
"-hwaccel_device", GetEnvOr("GOTRANSCODER_VAAPI_RENDERER", "/dev/dri/renderD128"),
"-hwaccel_device", GetEnvOr("GOCODER_VAAPI_RENDERER", "/dev/dri/renderD128"),
"-hwaccel_output_format", "vaapi",
},
EncodeFlags: []string{
Expand All @@ -69,12 +76,12 @@ func DetectHardwareAccel() HwAccelT {
Name: name,
DecodeFlags: []string{
"-hwaccel", "qsv",
// "-qsv_device", GetEnvOr("GOTRANSCODER_QSV_RENDERER", "/dev/dri/renderD128"),
// "-qsv_device", GetEnvOr("GOCODER_QSV_RENDERER", "/dev/dri/renderD128"),
"-hwaccel_output_format", "qsv",
},
EncodeFlags: []string{
"-c:v", "h264_qsv",
"-preset", "fast",
"-preset", preset,
},
ScaleFilter: "scale_qsv=%d:%d",
}
Expand Down

0 comments on commit e3cc80d

Please sign in to comment.