Skip to content

Commit

Permalink
Refactoring, removed sensors due to poor compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigal committed Dec 29, 2023
1 parent 438f312 commit 9a5555c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 129 deletions.
1 change: 0 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Under the hood, the application leverages the power of FFMPEG to handle video pr
- Hardware acceleration with NVIDIA (CUDA + NVENC), AMD (OpenCL + AMF), and Intel (QSV) graphics cards.
- Compatibility with multiple audio and subtitles streams
- Support for various video formats: MP4, AVI, and MKV (both input and output).
- Tracking of GPU statistics (best support for NVIDIA).
- Quick and hassle-free installation.

## System Requirements
Expand Down
22 changes: 16 additions & 6 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ type Anime struct {
Status AnimeStatus
}

type CompressionPreset struct {
Name string
FfmpegName string
}

type ShadersMode struct {
type Shader struct {
Name string
Path string
}
Expand Down Expand Up @@ -51,3 +46,18 @@ func (res *Resolution) Format() string {

return fmt.Sprintf("%dx%d", res.Width, res.Height)
}

func removeAnime(index int) {
anime := animeList[index]
animeList = append(animeList[:index], animeList[index+1:]...)
updateUI()
logMessage(fmt.Sprintf("Removed %s from queue", anime.Name), false)
}

func addEncoders(vendor string) {
for _, encoder := range allEncoders {
if encoder.Vendor == vendor || encoder.Vendor == "cpu" {
availableEncoders = append(availableEncoders, encoder)
}
}
}
18 changes: 2 additions & 16 deletions ffmpeg.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func handleUpscalingLogs(stderr io.ReadCloser, anime Anime) string {
return ffmpegLogs
}

func buildUpscalingParams(anime Anime, resolution Resolution, shadersMode ShadersMode, outputPath string) []string {
func buildUpscalingParams(anime Anime, resolution Resolution, shader Shader, outputPath string) []string {
videoCodec = availableEncoders[settings.Encoder].FfmpegValue

params := []string{
Expand All @@ -78,7 +78,7 @@ func buildUpscalingParams(anime Anime, resolution Resolution, shadersMode Shader
params = append(params,
"-i", fmt.Sprintf("%s", anime.Path), // Path to input file
"-init_hw_device", "vulkan",
"-vf", fmt.Sprintf("format=yuv420p,hwupload,libplacebo=w=%d:h=%d:upscaler=ewa_lanczos:custom_shader_path=%s,hwdownload,format=yuv420p", resolution.Width, resolution.Height, shadersMode.Path),
"-vf", fmt.Sprintf("format=yuv420p,hwupload,libplacebo=w=%d:h=%d:upscaler=ewa_lanczos:custom_shader_path=%s,hwdownload,format=yuv420p", resolution.Width, resolution.Height, shader.Path),

"-c:a", "copy", // Copy all audio streams without re-encoding
"-c:s", "mov_text", // Force re-encoding subtitles with mov_text codec for compatibility reasons
Expand All @@ -99,12 +99,6 @@ func buildUpscalingParams(anime Anime, resolution Resolution, shadersMode Shader
return params
}

func buildOutputPath(anime Anime, outputFormat string) string {
dotSplit := strings.Split(anime.Path, ".")
extension := dotSplit[len(dotSplit)-1]
return strings.Replace(anime.Path, "."+extension, "_upscaled."+outputFormat, -1)
}

func searchHardwareAcceleration() {
nvidia := false
amd := false
Expand Down Expand Up @@ -173,11 +167,3 @@ func searchHardwareAcceleration() {
}
}
}

func addEncoders(vendor string) {
for _, encoder := range allEncoders {
if encoder.Vendor == vendor || encoder.Vendor == "cpu" {
availableEncoders = append(availableEncoders, encoder)
}
}
}
24 changes: 4 additions & 20 deletions gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func loop(window *g.MasterWindow) {
resolutionsNames[index] = res.Format()
}

shadersNames := make([]string, len(shadersModes))
for index, shaders := range shadersModes {
shadersNames[index] = shaders.Name
shadersNames := make([]string, len(shaders))
for index, shader := range shaders {
shadersNames[index] = shader.Name
}

availableEncodersNames := make([]string, len(availableEncoders))
Expand Down Expand Up @@ -49,7 +49,7 @@ func loop(window *g.MasterWindow) {

g.Label("Shaders mode"),
g.Tooltip("Check the project's GitHub page if you're not sure what to choose"),
g.Combo("", shadersModes[settings.ShadersMode].Name, shadersNames, &settings.ShadersMode).Size(400),
g.Combo("", shaders[settings.Shaders].Name, shadersNames, &settings.Shaders).Size(400),
g.Tooltip("Check the project's GitHub page if you're not sure what to choose"),
g.Label(""),

Expand All @@ -74,15 +74,6 @@ func loop(window *g.MasterWindow) {
g.Label(""),

g.Button(buttonLabel).OnClick(handleButton).Size(360, 30),

g.Label(""),
g.Label("GPU Usage: " + gpuUsage),
g.Label("VRAM Usage: " + vramUsage),
g.Custom(func() {
if isNvidia() {
g.Label("GPU Temperature: " + gpuTemperature).Build()
}
}),
},
),
g.Layout{
Expand Down Expand Up @@ -170,13 +161,6 @@ func updateUI() {
g.Update()
}

func removeAnime(index int) {
anime := animeList[index]
animeList = append(animeList[:index], animeList[index+1:]...)
updateUI()
logMessage(fmt.Sprintf("Removed %s from queue", anime.Name), false)
}

func buildTableRows() []*g.TableRowWidget {
rows := make([]*g.TableRowWidget, len(animeList))

Expand Down
26 changes: 13 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"

Expand All @@ -27,13 +28,13 @@ var (
{3840, 2160, true},
}

shadersModes = []ShadersMode{
{"Mode A", "shaders/Anime4K_ModeA.glsl"},
{"Mode A+A", "shaders/Anime4K_ModeA+A.glsl"},
{"Mode B", "shaders/Anime4K_ModeB.glsl"},
{"Mode B+B", "shaders/Anime4K_ModeB+B.glsl"},
{"Mode C", "shaders/Anime4K_ModeC.glsl"},
{"Mode C+A", "shaders/Anime4K_ModeC+A.glsl"},
shaders = []Shader{
{"Anime4K Mode A", "shaders/Anime4K_ModeA.glsl"},
{"Anime4K Mode A+A", "shaders/Anime4K_ModeA+A.glsl"},
{"Anime4K Mode B", "shaders/Anime4K_ModeB.glsl"},
{"Anime4K Mode B+B", "shaders/Anime4K_ModeB+B.glsl"},
{"Anime4K Mode C", "shaders/Anime4K_ModeC.glsl"},
{"Anime4K Mode C+A", "shaders/Anime4K_ModeC+A.glsl"},
{"FSRCNNX", "shaders/FSRCNNX_x2_16-0-4-1.glsl"},
}

Expand Down Expand Up @@ -61,7 +62,7 @@ var (
settings = Settings{
UseSavedPosition: true,
Resolution: 5,
ShadersMode: 0,
Shaders: 0,
Encoder: 0,
OutputFormat: 0,
CompatibilityMode: false,
Expand Down Expand Up @@ -96,7 +97,6 @@ var (
func main() {
checkDebugParam()
searchHardwareAcceleration()
go monitorSensors()
loaded := loadSettings()

window := g.NewMasterWindow("Anime4K-GUI", 1600, 950, g.MasterWindowFlagsNotResizable)
Expand All @@ -116,7 +116,7 @@ func startProcessing() {
}

resolution := resolutions[settings.Resolution]
shadersMode := shadersModes[settings.ShadersMode]
shader := shaders[settings.Shaders]
outputFormat := strings.ToLower(outputFormats[settings.OutputFormat])

if len(animeList) == 0 {
Expand Down Expand Up @@ -152,8 +152,8 @@ func startProcessing() {
animeList[index].Status = Processing
g.Update()

outputPath := buildOutputPath(anime, outputFormat)
ffmpegParams := buildUpscalingParams(anime, resolution, shadersMode, outputPath)
outputPath := fmt.Sprintf("%s_upscaled.%s", strings.TrimSuffix(anime.Path, filepath.Ext(anime.Path)), strings.ToLower(outputFormat))
ffmpegParams := buildUpscalingParams(anime, resolution, shader, outputPath)

workingDirectory, err := os.Getwd()
if err != nil {
Expand All @@ -169,7 +169,7 @@ func startProcessing() {
logDebug("Input path: "+anime.Path, false)
logDebug("Output path: "+outputPath, false)
logDebug("Target resolution: "+resolution.Format(), false)
logDebug("Shaders: "+shadersMode.Path, false)
logDebug("Shaders: "+shader.Path, false)
logDebug("Output format: "+outputFormat, false)
logDebug("FFMPEG command: .\\ffmpeg.exe\\ffmpeg.exe "+strings.Join(ffmpegParams, " "), false)
g.Update()
Expand Down
72 changes: 0 additions & 72 deletions sensors.go

This file was deleted.

2 changes: 1 addition & 1 deletion settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Settings struct {
PositionX int `json:"position_x"`
PositionY int `json:"position_y"`
Resolution int32 `json:"resolution"`
ShadersMode int32 `json:"shaders_mode"`
Shaders int32 `json:"shaders"`
Encoder int32 `json:"encoder"`
OutputFormat int32 `json:"output_format"`
CompatibilityMode bool `json:"compatibility_mode"`
Expand Down

0 comments on commit 9a5555c

Please sign in to comment.