Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigal committed Oct 9, 2023
0 parents commit 4467488
Show file tree
Hide file tree
Showing 20 changed files with 13,892 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/
build/
resources/ffmpeg/ffmpeg.exe
resources/ffmpeg/ffprobe.exe
Anime4K-GUI.syso
92 changes: 92 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Anime4K-GUI

This application is designed to enhance the resolution of anime videos using the [Anime4K](https://github.com/bloc97/Anime4K) shaders by bloc97, with the ability to save the upscaled version to disk.
It offers a straightforward and user-friendly graphical interface, eliminating the need for command-line interactions.
Under the hood, the application leverages the power of FFMPEG to handle video processing seamlessly. <br>

**Unlike the original Anime4K project, this application allows you to save the enhanced anime as higher-quality video files rather than real-time preview.**

## Table of Contents

- [Features](#features)
- [System Requirements](#system-requirements)
- [Usage](#usage)
- [Troubleshooting](#troubleshooting)
- [FFMPEG Distribution](#ffmpeg-distribution)
- [Special Thanks](#special-thanks)
- [Contribute](#contribute)

## Features

- Anime upscaling using the Anime4K shaders.
- Saving upscaled videos to disk rather than real-time preview.
- User-friendly graphical interface for easy operation; no command-line usage is required.
- Support for various video formats: MP4, AVI, and MKV (both input and output).
- Hardware acceleration with NVIDIA (CUDA + NVENC), AMD (OpenCL + AMF), and Intel (QSV) graphics cards.
- Tracking of GPU information (best support for NVIDIA).
- Quick and hassle-free installation.

## System Requirements

Before installing and running the application, ensure that your system meets the following requirements:

- Windows 10 or later, 64-bit (While the application may function on older versions, it is neither tested nor officially supported).
- A powerful GPU such as a GTX 970 or AMD equivalent, or newer models. For older hardware, the application will still function, but upscaling may require significantly more time.
- Knowledge about various Anime4K shaders modes - please read [documentation](https://github.com/bloc97/Anime4K/blob/master/md/GLSL_Instructions_Advanced.md#modes). This will allow you to get better results of upscaling.

Currently, NVIDIA graphics cards should be most stable as most tests were did with it. <br>
Intel Arc series won't be supported due to drivers instability and limited access to GPUs. <br>
If you have compatibility problems please create an issue with application logs and your computer's specification. <br>
<br>
In the future we plan to add support for Linux and macOS (Intel and Apple Silicon).

## Usage

Follow these steps to use the Anime4K-GUI:

1. **Download the Latest Release**
- Visit the [Releases](https://github.com/mikigal/Anime4K-GUI/releases) section on the GitHub repository.
- Download the latest release zip file.
- Unzip the downloaded archive and start the application.

2. **Add Your Anime**
- Drag and drop your input videos into the application's window.

3. **Select Upscaling Settings**
- Target settings: Output file resolution - keep in mind to select a resolution with an aspect ratio corresponding with input files. Keep in mind that some 4:3 anime may be saved in a 16:9 ratio with included black bars.
- Shaders mode: Shaders used for upscaling. Each has some positive and negative effects and should be used in different cases. <br>
**Please read Anime4K [documentation](https://github.com/bloc97/Anime4K/blob/master/md/GLSL_Instructions_Advanced.md#modes) before use.**
- Compression level: Compression level of the output file. If you don't care about the output file size, always keep this setting to Low. <br>
**Higher level will cause worse quality**
- Output format: Format for the output file - MP4 has best support on most devices.
- Disable hardware acceleration: check it **ONLY** if you have performance or compatibility issues.

4. **Upscale the Video**
- Click the "Start" button to begin the upscaling process.
- Be patient. You can check speed and current time progress per file in bottom corner.
- Output files will be saved in the input file's directory with "_upscaled" suffix in the name.

## Troubleshooting

If you encounter issues while using the application, please consult the [Issues](https://github.com/your_username/your_project/issues) section on the GitHub repository to check for solutions or report problems. <br>
Issues regarding low output quality will be instantly closed. Problems like that are related to the original Anime4K shaders - I can recommend trying other Shaders mode settings. <br>
Due to limited access to hardware, most tests were done with NVIDIA graphics cards; compatibility with other GPUs may be worse. If you have compatibility problems with your GPU, please create an issue with application logs and your computer's specifications.

## FFMPEG Distribution

Due to GitHub maximum file limit I can not provide FFMPEG's binaries in this repository. If you want to compile projekt by yourself you have to download FFMPEG build [here](https://github.com/BtbN/FFmpeg-Builds) and put `ffmpeg.exe` and `ffprobe.exe` into `resources/ffmpeg` directory

## Special Thanks

- [Ethan](https://github.com/2u75) for most of the required FFMPEG knowledge and research.
- [bloc97](https://github.com/bloc97/Anime4K) for Anime4K shaders.
- [AllenDang](https://github.com/AllenDang/giu) for Giu framework.
- [BtbN](https://github.com/BtbN/FFmpeg-Builds) for automated FFMPEG builds.
- [OpenAI](https://openai.com/) for ChatGPT, which was helpful in creating this README :)

## Contribute

Contributions are welcome! If you'd like to improve the application or report issues, please create a Pull Request.
<br>
<br>
![Screenshot](/resources/screenshot.png?raw=png)
47 changes: 47 additions & 0 deletions data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import "fmt"

type Anime struct {
Name string
Length int64
Size int64
Width int
Height int
Path string
Status AnimeStatus
}

type CompressionPreset struct {
Name string
FfmpegName string
}

type ShadersMode struct {
Name string
Path string
}

type Resolution struct {
Width int
Height int
Panoramic bool
}

type AnimeStatus string

const (
Waiting AnimeStatus = "Waiting"
Processing AnimeStatus = "Processing"
Finished AnimeStatus = "Finished"
Error AnimeStatus = "Error"
NotStarted AnimeStatus = "Not started"
)

func (res *Resolution) Format() string {
if !res.Panoramic {
return fmt.Sprintf("%dx%d (4:3)", res.Width, res.Height)
}

return fmt.Sprintf("%dx%d", res.Width, res.Height)
}
146 changes: 146 additions & 0 deletions ffmpeg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package main

import (
"bufio"
"fmt"
g "github.com/AllenDang/giu"
"github.com/jaypipes/ghw"
"io"
"strings"
)

func handleUpscalingLogs(stderr io.ReadCloser) string {
scanner := bufio.NewScanner(stderr)
scanner.Split(bufio.ScanRunes)

ffmpegLogs := ""
line := ""
for scanner.Scan() {
char := scanner.Text()
if char != "\r" {
// It's still the same line
line += char
continue
}

if !strings.HasPrefix(line, "frame=") {
ffmpegLogs += line
}

if strings.Contains(line, "speed=") {
value := strings.Split(strings.Split(line, "speed=")[1], " ")[0]

// Workaround for disappearing speed
if strings.Contains(value, ".") {
currentSpeed = fmt.Sprintf("Speed: %s", value)
g.Update()
}
}

if strings.Contains(line, "time=") {
value := strings.Split(strings.Split(strings.Split(line, "time=")[1], " ")[0], ".")[0]
currentTime = fmt.Sprintf("Time: %s", value)
g.Update()
}

line = ""
}

return ffmpegLogs
}

func buildUpscalingParams(anime Anime, resolution Resolution, shadersMode ShadersMode, compressionPreset CompressionPreset, outputPath string) []string {
params := []string{
"-hide_banner",
"-y",
}

if hwaccelValue != "" && !disableHardwareAcceleration {
params = append(params, hwaccelParam, hwaccelValue)

// Additional NVIDIA stuff
if hwaccelValue == "cuda" {
params = append(params, "-hwaccel_output_format", "cuda")
}
}

params = append(params,
"-i", fmt.Sprintf("%s", anime.Path),
"-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),
)

if cvValue != "" && !disableHardwareAcceleration {
params = append(params, "-c:v", cvValue)
}

params = append(params,
"-preset", compressionPreset.FfmpegName,
outputPath,
)

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
intel := false

gpus, err := ghw.GPU()
if err != nil {
handleSoftError("Getting GPU info error", err.Error())
return
}

logMessage(fmt.Sprintf("Detected GPUs (%d): ", len(gpus.GraphicsCards)), false)

for index, gpu := range gpus.GraphicsCards {
vendor := strings.ToLower(gpu.DeviceInfo.Vendor.Name)
if strings.Contains(vendor, "nvidia") {
nvidia = true
} else if strings.Contains(vendor, "amd") || strings.Contains(vendor, "advanced micro devices") {
amd = true
} else if strings.Contains(vendor, "intel") {
intel = true
}

logMessage(fmt.Sprintf(" %d. %s", index+1, gpu.DeviceInfo.Product.Name), false)
}

if (nvidia && intel) || (amd && intel) {
intel = false
}

if nvidia && amd { // AMD is iGPU
amd = false
}

if nvidia {
hwaccelParam = "-hwaccel_device"
hwaccelValue = "cuda"
cvValue = "h264_nvenc"
logMessage("Available GPU acceleration: CUDA + NVENC", false)
} else if amd {
hwaccelParam = "-hwaccel_device"
hwaccelValue = "opencl"
cvValue = "h264_amf"
logMessage("Available GPU acceleration: AMF", false)
} else if intel {
hwaccelParam = "-hwaccel"
hwaccelValue = "vulkan"
cvValue = "h264_qsv"
logMessage("Available GPU acceleration: QSV", false)
} else {
// Something weird happened
cvValue = ""
logMessage("There's no available GPU acceleration, application may not work correctly! Please verify your GPU drivers or report bug on GitHub", false)

}
}
33 changes: 33 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Anime4K-GUI

go 1.21

require (
github.com/AllenDang/giu v0.6.2
github.com/AllenDang/imgui-go v1.12.1-0.20221124025851-59b862ca5a0c
github.com/jaypipes/ghw v0.12.0
gopkg.in/vansante/go-ffprobe.v2 v2.1.1
)

require (
github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mazznoer/csscolorparser v0.1.3 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 // indirect
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
golang.org/x/image v0.12.0 // indirect
golang.org/x/sys v0.5.0 // indirect
gopkg.in/eapache/queue.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.0 // indirect
)
Loading

0 comments on commit 4467488

Please sign in to comment.