mirror of
https://github.com/k4yt3x/video2x.git
synced 2024-12-28 23:19:11 +00:00
feat(libplacebo): added more modes for Anime4K v4
Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
parent
f0f3166d92
commit
8eac1a7393
2585
models/libplacebo/anime4k-a+a.glsl
Normal file
2585
models/libplacebo/anime4k-a+a.glsl
Normal file
File diff suppressed because it is too large
Load Diff
2585
models/libplacebo/anime4k-b+b.glsl
Normal file
2585
models/libplacebo/anime4k-b+b.glsl
Normal file
File diff suppressed because it is too large
Load Diff
2309
models/libplacebo/anime4k-b.glsl
Normal file
2309
models/libplacebo/anime4k-b.glsl
Normal file
File diff suppressed because it is too large
Load Diff
1711
models/libplacebo/anime4k-c+a.glsl
Normal file
1711
models/libplacebo/anime4k-c+a.glsl
Normal file
File diff suppressed because it is too large
Load Diff
1435
models/libplacebo/anime4k-c.glsl
Normal file
1435
models/libplacebo/anime4k-c.glsl
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,46 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import shutil
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
ANIME4K_COMMIT = "master"
|
|
||||||
GITHUB_GLSL_ROOT = (
|
|
||||||
f"https://raw.githubusercontent.com/bloc97/Anime4K/{ANIME4K_COMMIT}/glsl"
|
|
||||||
)
|
|
||||||
SHADERS_DIR = Path(__file__).parent.parent / "data"
|
|
||||||
|
|
||||||
|
|
||||||
def download_and_combine_files():
|
|
||||||
|
|
||||||
modes = {
|
|
||||||
"ModeA": [
|
|
||||||
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
|
||||||
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_VL.glsl",
|
|
||||||
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_VL.glsl",
|
|
||||||
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
|
||||||
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
|
||||||
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
for mode in modes:
|
|
||||||
file_contents = ""
|
|
||||||
for file in modes[mode]:
|
|
||||||
response = requests.get(file, timeout=5)
|
|
||||||
response.raise_for_status()
|
|
||||||
file_contents += response.text + "\n"
|
|
||||||
|
|
||||||
with (SHADERS_DIR / Path(f"Anime4K_{mode}.glsl")).open("w") as output_file:
|
|
||||||
output_file.write(file_contents)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# clear shaders directory
|
|
||||||
if SHADERS_DIR.exists():
|
|
||||||
shutil.rmtree(SHADERS_DIR)
|
|
||||||
SHADERS_DIR.mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
# download and combine shaders
|
|
||||||
download_and_combine_files()
|
|
86
scripts/download_merge_anime4k_glsl.py
Executable file
86
scripts/download_merge_anime4k_glsl.py
Executable file
@ -0,0 +1,86 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import shutil
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
ANIME4K_COMMIT = "master"
|
||||||
|
GITHUB_GLSL_ROOT = (
|
||||||
|
f"https://raw.githubusercontent.com/bloc97/Anime4K/{ANIME4K_COMMIT}/glsl"
|
||||||
|
)
|
||||||
|
SHADERS_DIR = Path(__file__).parent.parent / "models" / "libplacebo"
|
||||||
|
|
||||||
|
|
||||||
|
def download_and_combine_files():
|
||||||
|
modes = {
|
||||||
|
"a": [
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
||||||
|
],
|
||||||
|
"b": [
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_Soft_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
||||||
|
],
|
||||||
|
"c": [
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale+Denoise/Anime4K_Upscale_Denoise_CNN_x2_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
||||||
|
],
|
||||||
|
"a+a": [
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_M.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
||||||
|
],
|
||||||
|
"b+b": [
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_Soft_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_Soft_M.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
||||||
|
],
|
||||||
|
"c+a": [
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Clamp_Highlights.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale+Denoise/Anime4K_Upscale_Denoise_CNN_x2_VL.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x2.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_AutoDownscalePre_x4.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_M.glsl",
|
||||||
|
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_CNN_x2_M.glsl",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
for mode in modes:
|
||||||
|
file_contents = ""
|
||||||
|
for file in modes[mode]:
|
||||||
|
response = requests.get(file, timeout=5)
|
||||||
|
response.raise_for_status()
|
||||||
|
file_contents += response.text + "\n"
|
||||||
|
|
||||||
|
with (SHADERS_DIR / Path(f"anime4k-{mode}.glsl")).open("w") as output_file:
|
||||||
|
output_file.write(file_contents)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# clear shaders directory
|
||||||
|
if SHADERS_DIR.exists():
|
||||||
|
shutil.rmtree(SHADERS_DIR)
|
||||||
|
SHADERS_DIR.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
# download and combine shaders
|
||||||
|
download_and_combine_files()
|
@ -57,7 +57,8 @@ int LibplaceboFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVB
|
|||||||
in_time_base = dec_ctx->time_base;
|
in_time_base = dec_ctx->time_base;
|
||||||
out_time_base = enc_ctx->time_base;
|
out_time_base = enc_ctx->time_base;
|
||||||
|
|
||||||
return init_libplacebo(
|
// Initialize the libplacebo filter
|
||||||
|
int ret = init_libplacebo(
|
||||||
hw_ctx,
|
hw_ctx,
|
||||||
&filter_graph,
|
&filter_graph,
|
||||||
&buffersrc_ctx,
|
&buffersrc_ctx,
|
||||||
@ -67,6 +68,14 @@ int LibplaceboFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVB
|
|||||||
out_height,
|
out_height,
|
||||||
shader_full_path
|
shader_full_path
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Set these resources to nullptr since they are already freed by `avfilter_graph_free`
|
||||||
|
if (ret < 0) {
|
||||||
|
buffersrc_ctx = nullptr;
|
||||||
|
buffersink_ctx = nullptr;
|
||||||
|
filter_graph = nullptr;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LibplaceboFilter::process_frame(AVFrame *in_frame, AVFrame **out_frame) {
|
int LibplaceboFilter::process_frame(AVFrame *in_frame, AVFrame **out_frame) {
|
||||||
|
@ -218,27 +218,35 @@ static void cleanup(
|
|||||||
) {
|
) {
|
||||||
if (ifmt_ctx) {
|
if (ifmt_ctx) {
|
||||||
avformat_close_input(&ifmt_ctx);
|
avformat_close_input(&ifmt_ctx);
|
||||||
|
ifmt_ctx = nullptr;
|
||||||
}
|
}
|
||||||
if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
|
if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
|
||||||
avio_closep(&ofmt_ctx->pb);
|
avio_closep(&ofmt_ctx->pb);
|
||||||
|
ofmt_ctx->pb = nullptr;
|
||||||
}
|
}
|
||||||
if (ofmt_ctx) {
|
if (ofmt_ctx) {
|
||||||
avformat_free_context(ofmt_ctx);
|
avformat_free_context(ofmt_ctx);
|
||||||
|
ofmt_ctx = nullptr;
|
||||||
}
|
}
|
||||||
if (dec_ctx) {
|
if (dec_ctx) {
|
||||||
avcodec_free_context(&dec_ctx);
|
avcodec_free_context(&dec_ctx);
|
||||||
|
dec_ctx = nullptr;
|
||||||
}
|
}
|
||||||
if (enc_ctx) {
|
if (enc_ctx) {
|
||||||
avcodec_free_context(&enc_ctx);
|
avcodec_free_context(&enc_ctx);
|
||||||
|
enc_ctx = nullptr;
|
||||||
}
|
}
|
||||||
if (hw_ctx) {
|
if (hw_ctx) {
|
||||||
av_buffer_unref(&hw_ctx);
|
av_buffer_unref(&hw_ctx);
|
||||||
|
hw_ctx = nullptr;
|
||||||
}
|
}
|
||||||
if (stream_map) {
|
if (stream_map) {
|
||||||
av_free(stream_map);
|
av_free(stream_map);
|
||||||
|
stream_map = nullptr;
|
||||||
}
|
}
|
||||||
if (filter) {
|
if (filter) {
|
||||||
delete filter;
|
delete filter;
|
||||||
|
filter = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,8 +443,7 @@ extern "C" int process_video(
|
|||||||
// Initialize the filter
|
// Initialize the filter
|
||||||
ret = filter->init(dec_ctx, enc_ctx, hw_ctx);
|
ret = filter->init(dec_ctx, enc_ctx, hw_ctx);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
spdlog::error("Failed to initialize filter");
|
||||||
spdlog::error("Failed to initialize filter: {}", errbuf);
|
|
||||||
cleanup(ifmt_ctx, ofmt_ctx, dec_ctx, enc_ctx, hw_ctx, stream_map, filter);
|
cleanup(ifmt_ctx, ofmt_ctx, dec_ctx, enc_ctx, hw_ctx, stream_map, filter);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ void print_help(void) {
|
|||||||
printf(" -q, --crf Constant Rate Factor (default: 20.0)\n");
|
printf(" -q, --crf Constant Rate Factor (default: 20.0)\n");
|
||||||
|
|
||||||
printf("\nlibplacebo Options:\n");
|
printf("\nlibplacebo Options:\n");
|
||||||
printf(" -s, --shader Name or path to custom GLSL shader file\n");
|
printf(" -s, --shader Name of or path to GLSL shader file\n");
|
||||||
printf(" -w, --width Output width\n");
|
printf(" -w, --width Output width\n");
|
||||||
printf(" -h, --height Output height\n");
|
printf(" -h, --height Output height\n");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user