Skip to content

Commit 0e8abb3

Browse files
committed
Implemented limiting CPU threads
1 parent 778dd72 commit 0e8abb3

File tree

6 files changed

+24
-1
lines changed

6 files changed

+24
-1
lines changed

README.MD

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Follow these steps to use the Anime4K-GUI:
7070
- Constant Rate Factor (CRF) - CRF is a method for controlling the output file's bitrate. The lower the value, the better the quality, but the larger the output file. The range is between 0 and 51. I recommend a value around 20.
7171
- Output format: Format for the output file. Pick MP4 for best support on most devices, MKV for the best compatibility with more complicated files (e.g. multiple streams). <br>
7272
**If Input files contain subtitles streams you must use MKV as output format due to other MK4/AVI limitations**
73+
- CPU threads: How many of CPU threads FFMPEG will use. You may limit it to make your system more responsive wile using CPU based encoder
7374
- Compatibility mode: check it only if you have compatibility issues.
7475
- Debug mode: show more detailed logs, useful for troubleshooting and debugging
7576

ffmpeg.go

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"io"
7+
"runtime"
78
"slices"
89
"strconv"
910
"strings"
@@ -129,6 +130,16 @@ func buildUpscalingParams(anime Anime, resolution Resolution, shader Shader, out
129130
}
130131
}
131132

133+
if videoCodec == "libx264" && settings.CpuThreads != int32(runtime.NumCPU()) {
134+
params = append(params, "-threads", fmt.Sprintf("%d", settings.CpuThreads))
135+
}
136+
if videoCodec == "libx265" && settings.CpuThreads != int32(runtime.NumCPU()) {
137+
params = append(params, "-x265-params", fmt.Sprintf("pools=%d", min(settings.CpuThreads, 16))) // libx265 allow max 16 threads
138+
}
139+
if videoCodec == "libsvtav1" && settings.CpuThreads != int32(runtime.NumCPU()) {
140+
params = append(params, "-svtav1-params", fmt.Sprintf("pin=%d", settings.CpuThreads))
141+
}
142+
132143
params = append(params, outputPath)
133144
return params
134145
}

gui.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"runtime"
67
"time"
78

89
g "github.com/AllenDang/giu"
@@ -12,11 +13,12 @@ import (
1213
const dragDropLabel = "\n\n\n\n\n\n\n Drag n' Drop your anime here"
1314
const shadersTooltip = "Check the project's GitHub page if you're not sure what to choose"
1415
const encoderTooltip = "Codec for encoding output file. In most cases GPU based are faster, use CPU mainly if you have slow GPU\n" +
15-
"GPU based AV1 is compatible only with RTX 4000+ and RX 6500XT+\n" +
16+
"GPU based AV1 is compatible only with RTX 4000+ and RX 7000+\n" +
1617
"HDR videos are supported only by AV1 codec"
1718
const crfTooltip = "Constant Rate Factor parameter encoder. \nDon't set it too high - file will be very big. " +
1819
"\n\nCorrect values: 0 - 51 \nIf you don't know what to enter, leave it as 20"
1920
const outputFormatTooltip = "If your input file contains subtitles streams you must use MKV as output format due to other formats limitations"
21+
const cpuThreadsTooltip = "How many of CPU threads FFMPEG will use \nYou may limit it to make your system more responsive wile using CPU based encoder"
2022
const compatibilityModeTooltip = "Should be used only for compatibility troubleshooting, disables most of features"
2123
const debugModeTooltip = "Show more detailed logs, useful for troubleshooting and debugging"
2224

@@ -80,6 +82,12 @@ func loop(window *g.MasterWindow) {
8082
g.Tooltip(outputFormatTooltip),
8183
g.Label(""),
8284

85+
g.Label("CPU threads"),
86+
g.Tooltip(cpuThreadsTooltip),
87+
g.InputInt(&settings.CpuThreads).Size(400).OnChange(func() { handleMinMax(&settings.CpuThreads, 1, 1, int32(runtime.NumCPU()), int32(runtime.NumCPU())) }),
88+
g.Tooltip(cpuThreadsTooltip),
89+
g.Label(""),
90+
8391
g.Checkbox("Compatibility mode", &settings.CompatibilityMode),
8492
g.Tooltip(compatibilityModeTooltip),
8593

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"os/exec"
88
"path/filepath"
9+
"runtime"
910
"strings"
1011
"syscall"
1112

@@ -65,6 +66,7 @@ var (
6566
Encoder: 0,
6667
Crf: 20,
6768
OutputFormat: 2,
69+
CpuThreads: int32(runtime.NumCPU()),
6870
CompatibilityMode: false,
6971
DebugMode: false,
7072
Version: version,

resources/screenshot.png

3.17 KB
Loading

settings.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type Settings struct {
1414
Encoder int32 `json:"encoder"`
1515
Crf int32 `json:"crf"`
1616
OutputFormat int32 `json:"output_format"`
17+
CpuThreads int32 `json:"cpu_threads"`
1718
CompatibilityMode bool `json:"compatibility_mode"`
1819
DebugMode bool `json:"debug_mode"`
1920
Version string `json:"version"`

0 commit comments

Comments
 (0)