mirror of
https://github.com/k4yt3x/video2x.git
synced 2026-02-06 20:44:56 +08:00
Compare commits
555 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a7558e1a8 | ||
|
|
ec4b51064a | ||
|
|
77a06e7d92 | ||
|
|
8eda3fa2d2 | ||
|
|
bcbe33d5dc | ||
|
|
850e0fde9c | ||
|
|
a63b8d85b0 | ||
|
|
1d1792d10f | ||
|
|
851f13bd4d | ||
|
|
fbe3b44139 | ||
|
|
d6f27b3f22 | ||
|
|
fb0e3a040d | ||
|
|
bb74144070 | ||
|
|
406a97f360 | ||
|
|
9c491d4277 | ||
|
|
27c76189d9 | ||
|
|
77b3df22c1 | ||
|
|
b333f88c2f | ||
|
|
8cafb29f70 | ||
|
|
afd7c8050f | ||
|
|
66c623ff49 | ||
|
|
0633b3fd62 | ||
|
|
0588908dd6 | ||
|
|
b309bec1cb | ||
|
|
94e69f9f62 | ||
|
|
a8b952c3ad | ||
|
|
c912bfaffc | ||
|
|
f5eb195d79 | ||
|
|
5156d4a825 | ||
|
|
cbffef2b23 | ||
|
|
31e606bd4c | ||
|
|
d50cf54f2a | ||
|
|
613b75ffec | ||
|
|
9d342c51a2 | ||
|
|
48119a30eb | ||
|
|
9d09d8570f | ||
|
|
ebef5f54cb | ||
|
|
747d85cf9b | ||
|
|
f89b263487 | ||
|
|
ebd5e8eb3d | ||
|
|
50d5cb16d1 | ||
|
|
8eac1a7393 | ||
|
|
f0f3166d92 | ||
|
|
482e82f9c4 | ||
|
|
58ea9e4b35 | ||
|
|
e077849a2c | ||
|
|
0fb547589d | ||
|
|
1f18b8507d | ||
|
|
eb7d411f49 | ||
|
|
640d9cd52b | ||
|
|
bc168d11ab | ||
|
|
e09f348890 | ||
|
|
f3caf22765 | ||
|
|
cd2006b4d9 | ||
|
|
ecbc512711 | ||
|
|
3fe1f6d544 | ||
|
|
ee4d6f360e | ||
|
|
7ae1943754 | ||
|
|
c2a4b25290 | ||
|
|
f79d4893db | ||
|
|
37c2c4c647 | ||
|
|
c7fa9c10e6 | ||
|
|
fa1dca8708 | ||
|
|
a7952fc493 | ||
|
|
721de8cbce | ||
|
|
7de040bbb7 | ||
|
|
b382f3973f | ||
|
|
37bdfddf55 | ||
|
|
21967209b8 | ||
|
|
b4b7cadf0d | ||
|
|
7c70032fe7 | ||
|
|
71821dbb56 | ||
|
|
22993028b4 | ||
|
|
6d934e6a98 | ||
|
|
78a2aafa0e | ||
|
|
e535cf7333 | ||
|
|
e725712be9 | ||
|
|
d66b7fa144 | ||
|
|
155a144a93 | ||
|
|
275f329f7f | ||
|
|
60ae71f3c5 | ||
|
|
cc01f2d8e2 | ||
|
|
5255e20283 | ||
|
|
c746773980 | ||
|
|
afc0df30cd | ||
|
|
bb759197d8 | ||
|
|
b4570cc106 | ||
|
|
66f4c17294 | ||
|
|
30048ae304 | ||
|
|
84b730497b | ||
|
|
db0b87597d | ||
|
|
102340e2be | ||
|
|
85437a8481 | ||
|
|
176ae90bbb | ||
|
|
44238aed35 | ||
|
|
045e643867 | ||
|
|
c92805e7bc | ||
|
|
899fe3ae2d | ||
|
|
a75c2a50ca | ||
|
|
508d6ea4d0 | ||
|
|
8976dd8199 | ||
|
|
29a55e633c | ||
|
|
f7d6dc41b3 | ||
|
|
d236131134 | ||
|
|
d669654142 | ||
|
|
4b0ab5382c | ||
|
|
737646a248 | ||
|
|
9fc0aa787e | ||
|
|
a041a60d87 | ||
|
|
020fb2dc80 | ||
|
|
9a27960bf7 | ||
|
|
862b811517 | ||
|
|
e01d24c164 | ||
|
|
0a052a3a72 | ||
|
|
f3eaa47ec6 | ||
|
|
3f457907b6 | ||
|
|
a1d750e7ca | ||
|
|
22f656b800 | ||
|
|
8eeba71ece | ||
|
|
afca10a17b | ||
|
|
f976bdc1c9 | ||
|
|
51c0c38b34 | ||
|
|
f2b2e11c41 | ||
|
|
865e3bd193 | ||
|
|
e0dc8237f5 | ||
|
|
bbc1b57445 | ||
|
|
ebbe4570d5 | ||
|
|
bcb2e97f89 | ||
|
|
ba29349e65 | ||
|
|
1b67f373d1 | ||
|
|
7215ee1921 | ||
|
|
65c0d32a51 | ||
|
|
268460fd17 | ||
|
|
d72ecb332a | ||
|
|
8ba56e58c2 | ||
|
|
fa485b6cdd | ||
|
|
625b340f3d | ||
|
|
fa3bd38217 | ||
|
|
0fca5c8e9a | ||
|
|
237f6336ec | ||
|
|
083af60c6f | ||
|
|
f7756886e7 | ||
|
|
6e72df66fc | ||
|
|
2bfcb13976 | ||
|
|
49e0375eee | ||
|
|
4459f4d3be | ||
|
|
c0fe81bd2e | ||
|
|
8cb64d3b70 | ||
|
|
0b154a715c | ||
|
|
05031b2b5a | ||
|
|
2510c8fa28 | ||
|
|
f17d75539c | ||
|
|
82512ef10c | ||
|
|
ad479e53b8 | ||
|
|
a356bfeaff | ||
|
|
dee8e23485 | ||
|
|
1fa0821057 | ||
|
|
b5ecffba81 | ||
|
|
672c9b8652 | ||
|
|
9f73e75f17 | ||
|
|
ef1a8f3e41 | ||
|
|
04f409ef80 | ||
|
|
51c8693dce | ||
|
|
bb572e2468 | ||
|
|
c07fafc0e9 | ||
|
|
595b179d3c | ||
|
|
c865d494a1 | ||
|
|
f4acb2188d | ||
|
|
01d4006c75 | ||
|
|
a7f0f34751 | ||
|
|
b6b1bf9f0e | ||
|
|
5d7a53a2fc | ||
|
|
b32e0ec132 | ||
|
|
6378a36d91 | ||
|
|
0d0fd70a24 | ||
|
|
7c0e9c45d8 | ||
|
|
7b60041529 | ||
|
|
6ffd6282e0 | ||
|
|
c37e7f0d72 | ||
|
|
ca1e593874 | ||
|
|
bfb0f339e2 | ||
|
|
3690337092 | ||
|
|
6c129a1c7a | ||
|
|
2b539c15f7 | ||
|
|
53456cd442 | ||
|
|
e1f4cdd71d | ||
|
|
ab6d2e3c9e | ||
|
|
f69c95a608 | ||
|
|
c103e45076 | ||
|
|
240d722fda | ||
|
|
14f3cd1e16 | ||
|
|
f4cc178dcd | ||
|
|
ad825bd2ba | ||
|
|
151733c8f8 | ||
|
|
544a7081ed | ||
|
|
4b3bde1615 | ||
|
|
b38cef2de2 | ||
|
|
b27da8a61a | ||
|
|
5e4170b0b7 | ||
|
|
b3539d4aa8 | ||
|
|
d09efc4748 | ||
|
|
dc532ff184 | ||
|
|
1fbb2f22f3 | ||
|
|
339815f74c | ||
|
|
fa6dc88faa | ||
|
|
ce344caa72 | ||
|
|
d8aed8065b | ||
|
|
6b83734382 | ||
|
|
2b52d4aa45 | ||
|
|
a515886ad8 | ||
|
|
a7629db518 | ||
|
|
ba336e9c75 | ||
|
|
736771b1c8 | ||
|
|
f9f736bec1 | ||
|
|
535681f3cd | ||
|
|
f283a12a0b | ||
|
|
ac80de9399 | ||
|
|
7eabac2175 | ||
|
|
e870399af1 | ||
|
|
37d567f208 | ||
|
|
7b9e811c99 | ||
|
|
0d97a11015 | ||
|
|
079a2aa64b | ||
|
|
9cdddd2e41 | ||
|
|
26d82e1582 | ||
|
|
c4e73cfbc7 | ||
|
|
2fffeeadf1 | ||
|
|
25155b3029 | ||
|
|
26795c5561 | ||
|
|
5543382d03 | ||
|
|
dc51b8b04c | ||
|
|
cde02be32b | ||
|
|
9213e3e13a | ||
|
|
b41f1f7e6c | ||
|
|
7201c036d5 | ||
|
|
da532d8e13 | ||
|
|
f97ed080e1 | ||
|
|
d67f55c824 | ||
|
|
095d40b688 | ||
|
|
bd6690fed1 | ||
|
|
bfda833bcf | ||
|
|
09345703e6 | ||
|
|
64e4a41710 | ||
|
|
f7b8b2520a | ||
|
|
fad793b18e | ||
|
|
d09d05ae9b | ||
|
|
89ca3b09d9 | ||
|
|
4694c557ec | ||
|
|
33d96bcd4e | ||
|
|
eee43def3b | ||
|
|
f4be9cc596 | ||
|
|
cc89b0aac5 | ||
|
|
9e8e95803f | ||
|
|
df0861ff5c | ||
|
|
706aeab03f | ||
|
|
f850ca80f1 | ||
|
|
608bf1a2ec | ||
|
|
b1f7290c20 | ||
|
|
65d445c293 | ||
|
|
43dbb134b6 | ||
|
|
84b0684d64 | ||
|
|
29b4153b63 | ||
|
|
3f1821f1ac | ||
|
|
4f8bb1be1c | ||
|
|
c2f1e43656 | ||
|
|
914d5cdf87 | ||
|
|
de77c90dd1 | ||
|
|
458ce82644 | ||
|
|
1d145a8690 | ||
|
|
b37acfa31d | ||
|
|
a0522311e2 | ||
|
|
7de9cc699a | ||
|
|
685648957f | ||
|
|
c2260ca709 | ||
|
|
776475265e | ||
|
|
21928f9eb4 | ||
|
|
211f024e49 | ||
|
|
bfdb051705 | ||
|
|
d824cd6516 | ||
|
|
b4f46ad31e | ||
|
|
a8d7f7ecf2 | ||
|
|
2b84e497b5 | ||
|
|
9b408a6e62 | ||
|
|
ecf94490a7 | ||
|
|
881183ed0a | ||
|
|
9389511d2d | ||
|
|
16389fc8a6 | ||
|
|
c7013b2576 | ||
|
|
a82fcc778e | ||
|
|
6dbdf93ca4 | ||
|
|
64eb03ac08 | ||
|
|
227cf54a47 | ||
|
|
107d31e5dc | ||
|
|
04562dcaa1 | ||
|
|
7059852586 | ||
|
|
8b7e9f959b | ||
|
|
19bd05149d | ||
|
|
a3706a1a17 | ||
|
|
5a7c464dea | ||
|
|
6c1b49b5ed | ||
|
|
59860dcfc3 | ||
|
|
b38ce2c56d | ||
|
|
68e6331672 | ||
|
|
188a44ce38 | ||
|
|
5621eb306a | ||
|
|
07a6356836 | ||
|
|
ef4269bbcd | ||
|
|
898d45e4b5 | ||
|
|
01493068e1 | ||
|
|
e44264bb6b | ||
|
|
06355441ea | ||
|
|
9b9da1ba5a | ||
|
|
78fa5e8c07 | ||
|
|
b2d7415a2c | ||
|
|
75d342f145 | ||
|
|
fae08dfb11 | ||
|
|
a0745e2196 | ||
|
|
986619165f | ||
|
|
78b0420e07 | ||
|
|
1eba4f2187 | ||
|
|
6e1315f2ed | ||
|
|
29a776d049 | ||
|
|
da4bfe9827 | ||
|
|
00c391b46c | ||
|
|
f5eb6514e1 | ||
|
|
3f6a3addaa | ||
|
|
8f2113ab0a | ||
|
|
60cf792c23 | ||
|
|
7e87dac15e | ||
|
|
0b15fb7bd2 | ||
|
|
765db2512b | ||
|
|
e14fbea67b | ||
|
|
491f80d2d2 | ||
|
|
2f4953e6c7 | ||
|
|
3f36cb8b43 | ||
|
|
3e57e206c6 | ||
|
|
da0e47528c | ||
|
|
f6aac30f96 | ||
|
|
7d00189f2f | ||
|
|
751150fe64 | ||
|
|
eb2b62b056 | ||
|
|
cc1b0b5464 | ||
|
|
fe7ded7e53 | ||
|
|
5f2ad35d41 | ||
|
|
d688ca490e | ||
|
|
708c983c1e | ||
|
|
9b91016d98 | ||
|
|
b024581906 | ||
|
|
8fd3292cd6 | ||
|
|
e646825c57 | ||
|
|
fdf326108f | ||
|
|
e26561c56a | ||
|
|
9d7c3963c3 | ||
|
|
ce5d4051e5 | ||
|
|
9f6f1eee5b | ||
|
|
6ae7491652 | ||
|
|
d35472fbfb | ||
|
|
7166afdc0e | ||
|
|
d3db4e8cf1 | ||
|
|
f887dfe3a7 | ||
|
|
a41df138bf | ||
|
|
41833f4068 | ||
|
|
c0955ae7e4 | ||
|
|
682aeb82ff | ||
|
|
21407c831c | ||
|
|
7e34bf7516 | ||
|
|
4c5ca73e38 | ||
|
|
387a233daf | ||
|
|
781eb6686f | ||
|
|
c73edd9001 | ||
|
|
deb742ee8d | ||
|
|
5ef6eb7e8e | ||
|
|
6c5e079a1c | ||
|
|
1e384596ee | ||
|
|
4680647f1f | ||
|
|
4015db5bcf | ||
|
|
082c6d44fa | ||
|
|
de841a4636 | ||
|
|
40711a2711 | ||
|
|
0c63768165 | ||
|
|
ac2d447391 | ||
|
|
b03747dbde | ||
|
|
89740f01dc | ||
|
|
676e70f088 | ||
|
|
f57b5e9d04 | ||
|
|
f48e23a890 | ||
|
|
826b4e9829 | ||
|
|
c56be51e21 | ||
|
|
d2b3175ccd | ||
|
|
a98d1c7277 | ||
|
|
e107ddc96e | ||
|
|
289f5441eb | ||
|
|
179bd6afc8 | ||
|
|
5af49012c8 | ||
|
|
192c6ef38b | ||
|
|
0b67ec879d | ||
|
|
288f21f7ce | ||
|
|
60af2a2782 | ||
|
|
53aa27409e | ||
|
|
ab22fb2359 | ||
|
|
fc18307b22 | ||
|
|
04d598a525 | ||
|
|
748f1e5799 | ||
|
|
c384bb91c4 | ||
|
|
0882f44e1f | ||
|
|
99abb4f6df | ||
|
|
54f8f19c7e | ||
|
|
c1c96815cf | ||
|
|
98a7fbf9cb | ||
|
|
f2ba6033b7 | ||
|
|
f92d1a41a2 | ||
|
|
1b6c4b8c49 | ||
|
|
9b4ee89aee | ||
|
|
0953fc52a1 | ||
|
|
759a3c7c96 | ||
|
|
786ccaa610 | ||
|
|
0c3c136458 | ||
|
|
1be2c1ead7 | ||
|
|
180bfcab20 | ||
|
|
0cc67857f7 | ||
|
|
e07848f4bf | ||
|
|
379d699c0d | ||
|
|
e6702d4486 | ||
|
|
8f5edb720e | ||
|
|
b27e9b1fa5 | ||
|
|
0b72236d95 | ||
|
|
fdb813d6d6 | ||
|
|
417dfc5deb | ||
|
|
12673f1c37 | ||
|
|
f7d8d551b3 | ||
|
|
9cbb213e55 | ||
|
|
181e5c94e6 | ||
|
|
37547d1233 | ||
|
|
8368cb1f49 | ||
|
|
9643c96ed7 | ||
|
|
1c5bf1604f | ||
|
|
23cfba86f8 | ||
|
|
0ef0d6e161 | ||
|
|
4e43ff9086 | ||
|
|
a93d18eb09 | ||
|
|
e305d0188e | ||
|
|
5cf3271aad | ||
|
|
bcbead4d96 | ||
|
|
a3d0465e44 | ||
|
|
995fdec5c8 | ||
|
|
5c3ea51ccb | ||
|
|
a24b321088 | ||
|
|
a83249c670 | ||
|
|
ab2f982a84 | ||
|
|
91401977da | ||
|
|
99971bceb1 | ||
|
|
0c6de8af16 | ||
|
|
4def30f516 | ||
|
|
8d553ac575 | ||
|
|
e1a1cf578b | ||
|
|
4015617152 | ||
|
|
648bf4fd3d | ||
|
|
e3ed08ff40 | ||
|
|
90f807655a | ||
|
|
ab77d62c71 | ||
|
|
a64fabae87 | ||
|
|
26558c6159 | ||
|
|
4fbbb20258 | ||
|
|
4659a9a9f5 | ||
|
|
4c48af4fa4 | ||
|
|
4a6f90a1f0 | ||
|
|
2d9c5fe751 | ||
|
|
bef3861d3c | ||
|
|
bcb54b6d2c | ||
|
|
e82a26d44f | ||
|
|
14f7f34ee3 | ||
|
|
11ba334f16 | ||
|
|
c451b14bd7 | ||
|
|
80623a6bb7 | ||
|
|
a5dd87a72c | ||
|
|
9b20ef89c9 | ||
|
|
91efe2d684 | ||
|
|
0d9d5c4f43 | ||
|
|
e0e42b11c8 | ||
|
|
790bb54598 | ||
|
|
f2943802cb | ||
|
|
d12f2a3888 | ||
|
|
871d6386a8 | ||
|
|
589a68caf7 | ||
|
|
afacc48e1e | ||
|
|
4a3553607b | ||
|
|
988600a769 | ||
|
|
36aa3bf1d4 | ||
|
|
9dde3c66f1 | ||
|
|
e9c1c22788 | ||
|
|
134e8b7080 | ||
|
|
a295b4a54f | ||
|
|
c198082190 | ||
|
|
8f2dc43af3 | ||
|
|
b0ce8f3ff9 | ||
|
|
0b1f7b8422 | ||
|
|
def20650e2 | ||
|
|
7489376404 | ||
|
|
826279ce09 | ||
|
|
88d2cd9e14 | ||
|
|
31728ff625 | ||
|
|
3168737fd4 | ||
|
|
5fbc195740 | ||
|
|
40d0d79141 | ||
|
|
37a0966bad | ||
|
|
baf4c5815f | ||
|
|
d25a478e64 | ||
|
|
ba723c6216 | ||
|
|
11ea8a7a21 | ||
|
|
3bce37416b | ||
|
|
e3cfe13b5c | ||
|
|
81d8ce78cb | ||
|
|
89fa91c8c5 | ||
|
|
c8dbb90f5b | ||
|
|
685120011b | ||
|
|
82da40327b | ||
|
|
9b4fb3258a | ||
|
|
f00a10aa91 | ||
|
|
93e8f36ffb | ||
|
|
f10e59099c | ||
|
|
82715ade18 | ||
|
|
63de63e594 | ||
|
|
8daeb862a4 | ||
|
|
be0d1f1d08 | ||
|
|
ec1327b5d8 | ||
|
|
5b3e5604cc | ||
|
|
a2fc71d6c5 | ||
|
|
ab684bcd48 | ||
|
|
d26b406813 | ||
|
|
133b837b15 | ||
|
|
9aebc77883 | ||
|
|
b8472f155a | ||
|
|
19e6d241d5 | ||
|
|
89860f22cb | ||
|
|
88299d404a | ||
|
|
0f1639ed62 | ||
|
|
3b6462d1da | ||
|
|
43a2078330 | ||
|
|
b1e844dcad | ||
|
|
becce32d3e | ||
|
|
d2ddf32527 | ||
|
|
7224c53997 | ||
|
|
2ed9bd4da6 | ||
|
|
38c52cdfd2 | ||
|
|
80579d3fa9 | ||
|
|
47f94dfd6c | ||
|
|
c470dde5da | ||
|
|
c532ac3c88 | ||
|
|
f50ceecd62 | ||
|
|
2ba0e951f9 | ||
|
|
5753ea8f52 | ||
|
|
09db8bedd0 | ||
|
|
6a100b1526 | ||
|
|
a2150a8dbc | ||
|
|
78ded08ed5 |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
models/** linguist-vendored
|
||||
2
.github/FUNDING.yml
vendored
Normal file
2
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
github: k4yt3x
|
||||
patreon: k4yt3x
|
||||
32
.github/ISSUE_TEMPLATE/bug-report.md
vendored
32
.github/ISSUE_TEMPLATE/bug-report.md
vendored
@@ -1,32 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Use this template if you believe you've encountered a bug.
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: K4YT3X
|
||||
|
||||
---
|
||||
|
||||
## Environment Information
|
||||
|
||||
|Module|Version|
|
||||
|-|-|
|
||||
|`Video2X`||
|
||||
|`FFmpeg`||
|
||||
|`waifu2x-caffe`||
|
||||
|`waifu2x-converter-cpp`||
|
||||
|`waifu2x-ncnn-vulkan`||
|
||||
|
||||
## Symptom
|
||||
|
||||
Briefly describe what's going on.
|
||||
|
||||
## Screenshots or Error Messages
|
||||
|
||||
Please paste screenshots or error messages here.
|
||||
Include as much details as you can, as this greatly helps debugging the problem.
|
||||
|
||||
Please paste your error message in the code block down below:
|
||||
|
||||
```
|
||||
```
|
||||
16
.github/ISSUE_TEMPLATE/feature_request.md
vendored
16
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,16 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Request a new feature to be added
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: K4YT3X
|
||||
|
||||
---
|
||||
|
||||
## Description
|
||||
|
||||
Briefly describe the feature you want to be added into `video2x`.
|
||||
|
||||
## Sources
|
||||
|
||||
Paste links to descriptions of related documentations, websites and etc. here.
|
||||
109
.github/workflows/build.yml
vendored
Normal file
109
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
pull_request: {}
|
||||
workflow_dispatch: {}
|
||||
|
||||
jobs:
|
||||
ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
git submodule update --init --recursive
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
libavcodec-dev \
|
||||
libavdevice-dev \
|
||||
libavfilter-dev \
|
||||
libavformat-dev \
|
||||
libavutil-dev \
|
||||
libswscale-dev \
|
||||
libvulkan-dev \
|
||||
glslang-tools \
|
||||
libomp-dev \
|
||||
libopencv-dev \
|
||||
libboost-program-options-dev
|
||||
- name: Build Video2X
|
||||
run: |
|
||||
mkdir -p /tmp/build /tmp/install
|
||||
cmake -B /tmp/build -S . -DUSE_SYSTEM_NCNN=OFF -DUSE_SYSTEM_SPDLOG=OFF \
|
||||
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
|
||||
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/tmp/install \
|
||||
-DINSTALL_BIN_DESTINATION=. -DINSTALL_INCLUDE_DESTINATION=include \
|
||||
-DINSTALL_LIB_DESTINATION=. -DINSTALL_MODEL_DESTINATION=.
|
||||
cmake --build /tmp/build --config Debug --target install --parallel
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: video2x-nightly-linux-amd64
|
||||
path: /tmp/install
|
||||
|
||||
windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install Vulkan SDK
|
||||
uses: humbletim/setup-vulkan-sdk@v1.2.0
|
||||
with:
|
||||
vulkan-query-version: 1.3.204.0
|
||||
vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang, SPIRV-Tools, SPIRV-Headers
|
||||
vulkan-use-cache: true
|
||||
- name: Install dependencies
|
||||
shell: pwsh
|
||||
run: |
|
||||
$ffmpegVersion = "7.1"
|
||||
$ncnnVersion = "20240820"
|
||||
$opencvVersion = "4.10.0"
|
||||
|
||||
git submodule update --init --recursive
|
||||
|
||||
curl -Lo ffmpeg-shared.zip "https://github.com/GyanD/codexffmpeg/releases/download/$ffmpegVersion/ffmpeg-$ffmpegVersion-full_build-shared.zip"
|
||||
Expand-Archive -Path ffmpeg-shared.zip -DestinationPath third_party
|
||||
Rename-Item -Path "third_party/ffmpeg-$ffmpegVersion-full_build-shared" -NewName ffmpeg-shared
|
||||
|
||||
curl -Lo ncnn-shared.zip "https://github.com/Tencent/ncnn/releases/download/$ncnnVersion/ncnn-$ncnnVersion-windows-vs2022-shared.zip"
|
||||
Expand-Archive -Path ncnn-shared.zip -DestinationPath third_party
|
||||
Rename-Item -Path "third_party/ncnn-$ncnnVersion-windows-vs2022-shared" -NewName ncnn-shared
|
||||
|
||||
curl -Lo opencv-shared.exe "https://github.com/opencv/opencv/releases/download/$opencvVersion/opencv-$opencvVersion-windows.exe"
|
||||
7z x opencv-shared.exe -y
|
||||
Move-Item -Path opencv -Destination third_party\opencv-shared
|
||||
- name: Build Video2X
|
||||
shell: pwsh
|
||||
run: |
|
||||
cmake -S . -B build `
|
||||
-DUSE_SYSTEM_NCNN=OFF -DUSE_SYSTEM_SPDLOG=OFF -DUSE_SYSTEM_OPENCV=OFF -DUSE_SYSTEM_BOOST=OFF `
|
||||
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=build/video2x_install
|
||||
cmake --build build --config Debug --parallel --target install
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: video2x-nightly-windows-amd64
|
||||
path: build/video2x_install
|
||||
|
||||
container:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- uses: mr-smithers-excellent/docker-build-push@v5
|
||||
name: Build the Docker image
|
||||
with:
|
||||
registry: ghcr.io
|
||||
dockerfile: packaging/docker/Dockerfile
|
||||
image: video2x
|
||||
tags: latest
|
||||
pushImage: false
|
||||
160
.github/workflows/release.yml
vendored
Normal file
160
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
name: Release
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
setup:
|
||||
name: Setup
|
||||
if: github.event.base_ref == 'refs/heads/master'
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.get_version.outputs.version }}
|
||||
steps:
|
||||
- name: Get version
|
||||
id: get_version
|
||||
run: echo version=${GITHUB_REF/refs\/tags\//} >> $GITHUB_OUTPUT
|
||||
|
||||
ubuntu-2404:
|
||||
# GitHub Actions' ubuntu-24.04 runner does not have enough RAM
|
||||
if: false
|
||||
name: Build Ubuntu 24.04 release
|
||||
needs:
|
||||
- setup
|
||||
runs-on: ubuntu-24.04
|
||||
env:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
git submodule update --init --recursive
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
libavcodec-dev \
|
||||
libavdevice-dev \
|
||||
libavfilter-dev \
|
||||
libavformat-dev \
|
||||
libavutil-dev \
|
||||
libswscale-dev \
|
||||
libvulkan-dev \
|
||||
glslang-tools \
|
||||
libomp-dev \
|
||||
libopencv-dev \
|
||||
libboost-program-options-dev
|
||||
- name: Build Video2X
|
||||
run: |
|
||||
cmake -B build -S . -DUSE_SYSTEM_NCNN=OFF -DUSE_SYSTEM_SPDLOG=OFF -DSPDLOG_NO_EXCEPTIONS=ON \
|
||||
-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \
|
||||
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/video2x-linux-ubuntu-2404-amd64/usr
|
||||
cmake --build build --config Release --target install --parallel
|
||||
mkdir -p build/video2x-linux-ubuntu-2404-amd64/DEBIAN
|
||||
cp packaging/debian/control build/video2x-linux-ubuntu-2404-amd64/DEBIAN/control
|
||||
dpkg-deb --build build/video2x-linux-ubuntu-2404-amd64
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: video2x-linux-ubuntu-2404-amd64
|
||||
path: build/video2x-linux-ubuntu-2404-amd64.deb
|
||||
|
||||
windows:
|
||||
name: Build Windows release
|
||||
needs:
|
||||
- setup
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Install Vulkan SDK
|
||||
uses: humbletim/setup-vulkan-sdk@v1.2.0
|
||||
with:
|
||||
vulkan-query-version: 1.3.204.0
|
||||
vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang, SPIRV-Tools, SPIRV-Headers
|
||||
vulkan-use-cache: true
|
||||
- name: Install dependencies
|
||||
shell: pwsh
|
||||
run: |
|
||||
$ffmpegVersion = "7.1"
|
||||
$ncnnVersion = "20240820"
|
||||
$opencvVersion = "4.10.0"
|
||||
|
||||
git submodule update --init --recursive
|
||||
|
||||
curl -Lo ffmpeg-shared.zip "https://github.com/GyanD/codexffmpeg/releases/download/$ffmpegVersion/ffmpeg-$ffmpegVersion-full_build-shared.zip"
|
||||
Expand-Archive -Path ffmpeg-shared.zip -DestinationPath third_party
|
||||
Rename-Item -Path "third_party/ffmpeg-$ffmpegVersion-full_build-shared" -NewName ffmpeg-shared
|
||||
|
||||
curl -Lo ncnn-shared.zip "https://github.com/Tencent/ncnn/releases/download/$ncnnVersion/ncnn-$ncnnVersion-windows-vs2022-shared.zip"
|
||||
Expand-Archive -Path ncnn-shared.zip -DestinationPath third_party
|
||||
Rename-Item -Path "third_party/ncnn-$ncnnVersion-windows-vs2022-shared" -NewName ncnn-shared
|
||||
|
||||
curl -Lo opencv-shared.exe "https://github.com/opencv/opencv/releases/download/$opencvVersion/opencv-$opencvVersion-windows.exe"
|
||||
7z x opencv-shared.exe -y
|
||||
Move-Item -Path opencv -Destination third_party\opencv-shared
|
||||
- name: Build Video2X
|
||||
shell: pwsh
|
||||
run: |
|
||||
cmake -S . -B build `
|
||||
-DUSE_SYSTEM_NCNN=OFF -DUSE_SYSTEM_SPDLOG=OFF -DUSE_SYSTEM_OPENCV=OFF -DUSE_SYSTEM_BOOST=OFF `
|
||||
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/video2x_install
|
||||
cmake --build build --config Release --parallel --target install
|
||||
- name: Compress artifacts
|
||||
run: |
|
||||
Compress-Archive -Path build/video2x_install/* -DestinationPath build/video2x-windows-amd64.zip
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: video2x-windows-amd64
|
||||
path: build/video2x-windows-amd64.zip
|
||||
|
||||
container:
|
||||
name: Build and upload container
|
||||
needs:
|
||||
- setup
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- uses: mr-smithers-excellent/docker-build-push@v5
|
||||
name: Build & push the Docker image
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ secrets.GHCR_USER }}
|
||||
password: ${{ secrets.GHCR_TOKEN }}
|
||||
dockerfile: packaging/docker/Dockerfile
|
||||
image: video2x
|
||||
tags: latest, ${{ needs.setup.outputs.version }}
|
||||
|
||||
create-release:
|
||||
name: Create release
|
||||
needs:
|
||||
- setup
|
||||
# - ubuntu-2404
|
||||
- windows
|
||||
- container
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
steps:
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
- name: Create release
|
||||
id: create_release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag_name: ${{ needs.setup.outputs.version }}
|
||||
name: ${{ needs.setup.outputs.version }}
|
||||
draft: true
|
||||
prerelease: false
|
||||
files: |
|
||||
video2x-windows-amd64.zip
|
||||
164
.gitignore
vendored
164
.gitignore
vendored
@@ -1,113 +1,77 @@
|
||||
# Runtime files
|
||||
upscaled/
|
||||
frames/
|
||||
waifu2x-caffe/
|
||||
testvid.mp4
|
||||
# Data files
|
||||
data/
|
||||
|
||||
# PyCharm
|
||||
.idea/
|
||||
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.Python
|
||||
# Built-binaries
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# PyInstaller
|
||||
# Usually these files are written by a python script from a template
|
||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||
*.manifest
|
||||
*.spec
|
||||
# Prerequisites
|
||||
*.d
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
*.obj
|
||||
*.elf
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
# Linker output
|
||||
*.ilk
|
||||
*.map
|
||||
*.exp
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
# Libraries
|
||||
*.lib
|
||||
*.a
|
||||
*.la
|
||||
*.lo
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
# Shared objects (inc. Windows DLLs)
|
||||
*.dll
|
||||
#*.so
|
||||
*.so.*
|
||||
*.dylib
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
*.i*86
|
||||
*.x86_64
|
||||
*.hex
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
# Debug files
|
||||
*.dSYM/
|
||||
*.su
|
||||
*.idb
|
||||
*.pdb
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
# Kernel Module Compile Results
|
||||
#*.mod*
|
||||
*.cmd
|
||||
.tmp_versions/
|
||||
modules.order
|
||||
Module.symvers
|
||||
Mkfile.old
|
||||
dkms.conf
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
# clang tooling compilation databases
|
||||
.cache/
|
||||
*.plist
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# mkdocs documentation
|
||||
/site
|
||||
|
||||
# mypy
|
||||
.mypy_cache/
|
||||
# CMake
|
||||
CMakeLists.txt.user
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
CMakeUserPresets.json
|
||||
|
||||
15
.gitmodules
vendored
Normal file
15
.gitmodules
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
[submodule "third_party/librealesrgan_ncnn_vulkan"]
|
||||
path = third_party/librealesrgan_ncnn_vulkan
|
||||
url = https://github.com/k4yt3x/librealesrgan-ncnn-vulkan.git
|
||||
[submodule "third_party/ncnn"]
|
||||
path = third_party/ncnn
|
||||
url = https://github.com/Tencent/ncnn.git
|
||||
[submodule "third_party/spdlog"]
|
||||
path = third_party/spdlog
|
||||
url = https://github.com/gabime/spdlog.git
|
||||
[submodule "third_party/opencv"]
|
||||
path = third_party/opencv
|
||||
url = https://github.com/opencv/opencv.git
|
||||
[submodule "third_party/boost"]
|
||||
path = third_party/boost
|
||||
url = https://github.com/boostorg/boost.git
|
||||
8
CHANGELOG.md
Normal file
8
CHANGELOG.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
478
CMakeLists.txt
Normal file
478
CMakeLists.txt
Normal file
@@ -0,0 +1,478 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(video2x VERSION 6.1.0 LANGUAGES CXX)
|
||||
|
||||
# Set the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
# Set the default build type to Release if not specified
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
# Set the default optimization flags for Release builds
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /GL /LTCG /MD /DNDEBUG")
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -flto")
|
||||
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -s")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -s")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Set global compile options for all targets
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
||||
add_compile_options(/W4 /permissive-)
|
||||
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
add_compile_options(-Wall -Wextra -Wpedantic -Wconversion -Wshadow)
|
||||
endif()
|
||||
|
||||
# Build options
|
||||
option(BUILD_SHARED_LIBS "Build libvideo2x as a shared library" ON)
|
||||
option(BUILD_VIDEO2X_CLI "Build the video2x executable" ON)
|
||||
option(USE_SYSTEM_OPENCV "Use system OpenCV library" ON)
|
||||
option(USE_SYSTEM_NCNN "Use system ncnn library" ON)
|
||||
option(USE_SYSTEM_SPDLOG "Use system spdlog library" ON)
|
||||
option(USE_SYSTEM_BOOST "Use system Boost library" ON)
|
||||
|
||||
# Generate the version header file
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/libvideo2x/version.h.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libvideo2x/version.h"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
# Find the required packages
|
||||
set(ALL_INCLUDE_DIRS)
|
||||
set(ALL_LIBRARIES)
|
||||
|
||||
# Platform-specific dependencies
|
||||
if(WIN32)
|
||||
# Define base paths for FFmpeg and ncnn
|
||||
set(FFMPEG_BASE_PATH ${PROJECT_SOURCE_DIR}/third_party/ffmpeg-shared)
|
||||
set(NCNN_BASE_PATH ${PROJECT_SOURCE_DIR}/third_party/ncnn-shared/x64)
|
||||
set(OPENCV_BASE_PATH ${PROJECT_SOURCE_DIR}/third_party/opencv-shared)
|
||||
|
||||
# FFmpeg
|
||||
set(FFMPEG_LIB
|
||||
${FFMPEG_BASE_PATH}/lib/avcodec.lib
|
||||
${FFMPEG_BASE_PATH}/lib/avdevice.lib
|
||||
${FFMPEG_BASE_PATH}/lib/avfilter.lib
|
||||
${FFMPEG_BASE_PATH}/lib/avformat.lib
|
||||
${FFMPEG_BASE_PATH}/lib/avutil.lib
|
||||
${FFMPEG_BASE_PATH}/lib/swscale.lib
|
||||
)
|
||||
list(APPEND ALL_LIBRARIES ${FFMPEG_LIB})
|
||||
list(APPEND ALL_INCLUDE_DIRS ${FFMPEG_BASE_PATH}/include)
|
||||
|
||||
# ncnn
|
||||
# TODO: Figure out why this file is not being copied to the install directory
|
||||
set(SPIRV_BUILD_PATH
|
||||
${CMAKE_BINARY_DIR}/realesrgan-prefix/src/realesrgan-build/ncnn/glslang/SPIRV
|
||||
)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(SPIRV_LIB ${SPIRV_BUILD_PATH}/Release/SPIRV.lib)
|
||||
else()
|
||||
set(SPIRV_LIB ${SPIRV_BUILD_PATH}/Debug/SPIRVd.lib)
|
||||
endif()
|
||||
|
||||
list(APPEND ALL_LIBRARIES
|
||||
${NCNN_BASE_PATH}/lib/ncnn.lib
|
||||
${SPIRV_LIB}
|
||||
)
|
||||
list(APPEND ALL_INCLUDE_DIRS ${NCNN_BASE_PATH}/include/ncnn)
|
||||
|
||||
# OpenCV
|
||||
# list(APPEND ALL_LIBRARIES ${OPENCV_BASE_PATH}/build/x64/vc16/lib/opencv_world4100.lib)
|
||||
list(APPEND ALL_INCLUDE_DIRS ${OPENCV_BASE_PATH}/build/include)
|
||||
else()
|
||||
# FFmpeg
|
||||
find_package(PkgConfig REQUIRED)
|
||||
set(FFMPEG_REQUIRED_PKGS REQUIRED
|
||||
libavcodec
|
||||
libavdevice
|
||||
libavfilter
|
||||
libavformat
|
||||
libavutil
|
||||
libswscale
|
||||
)
|
||||
|
||||
# Loop through each package to find and collect include dirs and libraries
|
||||
set(FFMPEG_LIB)
|
||||
foreach(PKG ${FFMPEG_REQUIRED_PKGS})
|
||||
pkg_check_modules(${PKG} REQUIRED ${PKG})
|
||||
list(APPEND ALL_INCLUDE_DIRS ${${PKG}_INCLUDE_DIRS})
|
||||
list(APPEND FFMPEG_LIB ${${PKG}_LIBRARIES})
|
||||
endforeach()
|
||||
list(APPEND ALL_LIBRARIES ${FFMPEG_LIB})
|
||||
|
||||
# OpenCV
|
||||
if (USE_SYSTEM_OPENCV)
|
||||
find_package(OpenCV REQUIRED)
|
||||
list(APPEND ALL_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS}/opencv2)
|
||||
# list(APPEND ALL_LIBRARIES opencv_core opencv_videoio)
|
||||
else()
|
||||
option(BUILD_opencv_calib3d "" OFF)
|
||||
option(BUILD_opencv_core "" ON)
|
||||
option(BUILD_opencv_dnn "" OFF)
|
||||
option(BUILD_opencv_features2d "" OFF)
|
||||
option(BUILD_opencv_flann "" OFF)
|
||||
option(BUILD_opencv_gapi "" OFF)
|
||||
option(BUILD_opencv_highgui "" OFF)
|
||||
option(BUILD_opencv_imgcodecs "" OFF)
|
||||
option(BUILD_opencv_imgproc "" OFF)
|
||||
option(BUILD_opencv_java "" OFF)
|
||||
option(BUILD_opencv_js "" OFF)
|
||||
option(BUILD_opencv_ml "" OFF)
|
||||
option(BUILD_opencv_objc "" OFF)
|
||||
option(BUILD_opencv_objdetect "" OFF)
|
||||
option(BUILD_opencv_photo "" OFF)
|
||||
option(BUILD_opencv_python "" OFF)
|
||||
option(BUILD_opencv_python2 "" OFF)
|
||||
option(BUILD_opencv_python3 "" OFF)
|
||||
option(BUILD_opencv_stitching "" OFF)
|
||||
option(BUILD_opencv_ts "" OFF)
|
||||
option(BUILD_opencv_video "" OFF)
|
||||
option(BUILD_opencv_videoio "" ON)
|
||||
option(BUILD_opencv_world "" OFF)
|
||||
|
||||
option(WITH_PNG "" OFF)
|
||||
option(WITH_JPEG "" OFF)
|
||||
option(WITH_TIFF "" OFF)
|
||||
option(WITH_WEBP "" OFF)
|
||||
option(WITH_OPENJPEG "" OFF)
|
||||
option(WITH_JASPER "" OFF)
|
||||
option(WITH_OPENEXR "" OFF)
|
||||
option(WITH_IMGCODEC "" OFF)
|
||||
|
||||
add_subdirectory(third_party/opencv)
|
||||
list(APPEND ALL_INCLUDE_DIRS
|
||||
${PROJECT_SOURCE_DIR}/third_party/opencv/include
|
||||
${PROJECT_SOURCE_DIR}/third_party/opencv/modules/core/include
|
||||
${PROJECT_SOURCE_DIR}/third_party/opencv/modules/videoio/include
|
||||
)
|
||||
# list(APPEND ALL_LIBRARIES opencv_core opencv_videoio)
|
||||
endif() # USE_SYSTEM_OPENCV
|
||||
endif() # WIN32
|
||||
|
||||
# Find ncnn package
|
||||
if(USE_SYSTEM_NCNN)
|
||||
find_package(ncnn REQUIRED)
|
||||
else()
|
||||
option(NCNN_INSTALL_SDK "" OFF)
|
||||
option(NCNN_PIXEL_ROTATE "" OFF)
|
||||
option(NCNN_VULKAN "" ON)
|
||||
option(NCNN_VULKAN_ONLINE_SPIRV "" ON)
|
||||
option(NCNN_BUILD_BENCHMARK "" OFF)
|
||||
option(NCNN_BUILD_TESTS "" OFF)
|
||||
option(NCNN_BUILD_TOOLS "" OFF)
|
||||
option(NCNN_BUILD_EXAMPLES "" OFF)
|
||||
option(NCNN_DISABLE_RTTI "" ON)
|
||||
option(NCNN_DISABLE_EXCEPTION "" ON)
|
||||
option(NCNN_BUILD_SHARED_LIBS "" OFF)
|
||||
option(SKIP_GLSLANG_INSTALL "" ON)
|
||||
|
||||
option(WITH_LAYER_absval "" OFF)
|
||||
option(WITH_LAYER_argmax "" OFF)
|
||||
option(WITH_LAYER_batchnorm "" OFF)
|
||||
option(WITH_LAYER_bias "" OFF)
|
||||
option(WITH_LAYER_bnll "" OFF)
|
||||
option(WITH_LAYER_concat "" ON)
|
||||
option(WITH_LAYER_convolution "" ON)
|
||||
option(WITH_LAYER_crop "" ON)
|
||||
option(WITH_LAYER_deconvolution "" OFF)
|
||||
option(WITH_LAYER_dropout "" OFF)
|
||||
option(WITH_LAYER_eltwise "" ON)
|
||||
option(WITH_LAYER_elu "" OFF)
|
||||
option(WITH_LAYER_embed "" OFF)
|
||||
option(WITH_LAYER_exp "" OFF)
|
||||
option(WITH_LAYER_flatten "" ON)
|
||||
option(WITH_LAYER_innerproduct "" ON)
|
||||
option(WITH_LAYER_input "" ON)
|
||||
option(WITH_LAYER_log "" OFF)
|
||||
option(WITH_LAYER_lrn "" OFF)
|
||||
option(WITH_LAYER_memorydata "" OFF)
|
||||
option(WITH_LAYER_mvn "" OFF)
|
||||
option(WITH_LAYER_pooling "" OFF)
|
||||
option(WITH_LAYER_power "" OFF)
|
||||
option(WITH_LAYER_prelu "" ON)
|
||||
option(WITH_LAYER_proposal "" OFF)
|
||||
option(WITH_LAYER_reduction "" OFF)
|
||||
option(WITH_LAYER_relu "" ON)
|
||||
option(WITH_LAYER_reshape "" OFF)
|
||||
option(WITH_LAYER_roipooling "" OFF)
|
||||
option(WITH_LAYER_scale "" OFF)
|
||||
option(WITH_LAYER_sigmoid "" OFF)
|
||||
option(WITH_LAYER_slice "" OFF)
|
||||
option(WITH_LAYER_softmax "" OFF)
|
||||
option(WITH_LAYER_split "" ON)
|
||||
option(WITH_LAYER_spp "" OFF)
|
||||
option(WITH_LAYER_tanh "" OFF)
|
||||
option(WITH_LAYER_threshold "" OFF)
|
||||
option(WITH_LAYER_tile "" OFF)
|
||||
option(WITH_LAYER_rnn "" OFF)
|
||||
option(WITH_LAYER_lstm "" OFF)
|
||||
option(WITH_LAYER_binaryop "" ON)
|
||||
option(WITH_LAYER_unaryop "" OFF)
|
||||
option(WITH_LAYER_convolutiondepthwise "" OFF)
|
||||
option(WITH_LAYER_padding "" ON)
|
||||
option(WITH_LAYER_squeeze "" OFF)
|
||||
option(WITH_LAYER_expanddims "" OFF)
|
||||
option(WITH_LAYER_normalize "" OFF)
|
||||
option(WITH_LAYER_permute "" OFF)
|
||||
option(WITH_LAYER_priorbox "" OFF)
|
||||
option(WITH_LAYER_detectionoutput "" OFF)
|
||||
option(WITH_LAYER_interp "" ON)
|
||||
option(WITH_LAYER_deconvolutiondepthwise "" OFF)
|
||||
option(WITH_LAYER_shufflechannel "" OFF)
|
||||
option(WITH_LAYER_instancenorm "" OFF)
|
||||
option(WITH_LAYER_clip "" OFF)
|
||||
option(WITH_LAYER_reorg "" OFF)
|
||||
option(WITH_LAYER_yolodetectionoutput "" OFF)
|
||||
option(WITH_LAYER_quantize "" OFF)
|
||||
option(WITH_LAYER_dequantize "" OFF)
|
||||
option(WITH_LAYER_yolov3detectionoutput "" OFF)
|
||||
option(WITH_LAYER_psroipooling "" OFF)
|
||||
option(WITH_LAYER_roialign "" OFF)
|
||||
option(WITH_LAYER_packing "" ON)
|
||||
option(WITH_LAYER_requantize "" OFF)
|
||||
option(WITH_LAYER_cast "" ON)
|
||||
option(WITH_LAYER_hardsigmoid "" OFF)
|
||||
option(WITH_LAYER_selu "" OFF)
|
||||
option(WITH_LAYER_hardswish "" OFF)
|
||||
option(WITH_LAYER_noop "" OFF)
|
||||
option(WITH_LAYER_pixelshuffle "" ON)
|
||||
option(WITH_LAYER_deepcopy "" OFF)
|
||||
option(WITH_LAYER_mish "" OFF)
|
||||
option(WITH_LAYER_statisticspooling "" OFF)
|
||||
option(WITH_LAYER_swish "" OFF)
|
||||
option(WITH_LAYER_gemm "" OFF)
|
||||
option(WITH_LAYER_groupnorm "" OFF)
|
||||
option(WITH_LAYER_layernorm "" OFF)
|
||||
option(WITH_LAYER_softplus "" OFF)
|
||||
|
||||
add_subdirectory(third_party/ncnn)
|
||||
endif()
|
||||
|
||||
# spdlog
|
||||
if (USE_SYSTEM_SPDLOG)
|
||||
find_package(spdlog REQUIRED)
|
||||
list(APPEND ALL_INCLUDE_DIRS ${spdlog_INCLUDE_DIRS})
|
||||
set(SPDLOG_LIB spdlog::spdlog)
|
||||
else()
|
||||
add_subdirectory(third_party/spdlog)
|
||||
set(SPDLOG_LIB spdlog::spdlog_header_only)
|
||||
endif()
|
||||
list(APPEND ALL_LIBRARIES ${SPDLOG_LIB})
|
||||
|
||||
# Boost
|
||||
if (USE_SYSTEM_BOOST)
|
||||
find_package(Boost REQUIRED COMPONENTS program_options)
|
||||
list(APPEND ALL_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
|
||||
else()
|
||||
option(Boost_USE_STATIC_LIBS "" ON)
|
||||
option(Boost_USE_STATIC_RUNTIME "" ON)
|
||||
option(Boost_COMPONENTS "program_options")
|
||||
|
||||
add_subdirectory(third_party/boost)
|
||||
include_directories(${PROJECT_SOURCE_DIR}/third_party/boost/libs/program_options/include)
|
||||
set(BOOST_BASE_PATH ${CMAKE_BINARY_DIR}/third_party/boost/libs/program_options/${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
set(BOOST_LIB Boost::program_options)
|
||||
|
||||
if (BUILD_VIDEO2X_CLI)
|
||||
find_package(Vulkan REQUIRED)
|
||||
set(VULKAN_LIB Vulkan::Vulkan)
|
||||
endif()
|
||||
|
||||
# Include ExternalProject module
|
||||
include(ExternalProject)
|
||||
|
||||
# Add librealesrgan-ncnn-vulkan as an external project
|
||||
ExternalProject_Add(
|
||||
realesrgan
|
||||
SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/librealesrgan_ncnn_vulkan/src
|
||||
CMAKE_ARGS
|
||||
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/realesrgan_install
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DUSE_SYSTEM_NCNN=${USE_SYSTEM_NCNN}
|
||||
BUILD_ALWAYS ON
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}
|
||||
)
|
||||
|
||||
# Remove duplicate entries
|
||||
list(REMOVE_DUPLICATES ALL_INCLUDE_DIRS)
|
||||
list(REMOVE_DUPLICATES ALL_LIBRARIES)
|
||||
|
||||
# Create the shared library 'libvideo2x'
|
||||
add_library(libvideo2x
|
||||
src/conversions.cpp
|
||||
src/decoder.cpp
|
||||
src/encoder.cpp
|
||||
src/fsutils.cpp
|
||||
src/libplacebo_filter.cpp
|
||||
src/libplacebo.cpp
|
||||
src/libvideo2x.cpp
|
||||
src/realesrgan_filter.cpp
|
||||
)
|
||||
target_compile_definitions(libvideo2x PRIVATE LIBVIDEO2X_EXPORTS)
|
||||
if(WIN32)
|
||||
set_target_properties(libvideo2x PROPERTIES OUTPUT_NAME libvideo2x)
|
||||
else()
|
||||
set_target_properties(libvideo2x PROPERTIES OUTPUT_NAME video2x)
|
||||
endif()
|
||||
|
||||
# Ensure libvideo2x depends on realesrgan being built and installed
|
||||
add_dependencies(libvideo2x realesrgan)
|
||||
|
||||
# Include directories for the shared library
|
||||
target_include_directories(libvideo2x PRIVATE
|
||||
${ALL_INCLUDE_DIRS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/include/libvideo2x
|
||||
${PROJECT_SOURCE_DIR}/third_party/librealesrgan_ncnn_vulkan/src
|
||||
)
|
||||
|
||||
# Compile options for the shared library
|
||||
target_compile_options(libvideo2x PRIVATE
|
||||
-fPIC
|
||||
$<$<CONFIG:Release>:-Ofast>
|
||||
$<$<CONFIG:Debug>:-g -DDEBUG>
|
||||
)
|
||||
|
||||
# Define the path to the built libresrgan-ncnn-vulkan library
|
||||
if(WIN32)
|
||||
set(REALESRGAN_LIB ${CMAKE_BINARY_DIR}/realesrgan_install/lib/librealesrgan-ncnn-vulkan.lib)
|
||||
list(APPEND ALL_LIBRARIES ${REALESRGAN_LIB})
|
||||
else()
|
||||
set(REALESRGAN_LIB ${CMAKE_BINARY_DIR}/realesrgan_install/lib/librealesrgan-ncnn-vulkan.so)
|
||||
list(APPEND ALL_LIBRARIES ${REALESRGAN_LIB})
|
||||
endif()
|
||||
|
||||
# Link the shared library with the dependencies
|
||||
target_link_libraries(libvideo2x PRIVATE ${ALL_LIBRARIES})
|
||||
|
||||
if(NOT WIN32)
|
||||
if (USE_SYSTEM_NCNN)
|
||||
target_link_libraries(libvideo2x PUBLIC ncnn)
|
||||
else()
|
||||
target_link_libraries(libvideo2x PRIVATE ncnn)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Create the executable 'video2x'
|
||||
if (BUILD_VIDEO2X_CLI)
|
||||
add_executable(video2x src/video2x.cpp src/timer.cpp)
|
||||
set_target_properties(video2x PROPERTIES OUTPUT_NAME video2x)
|
||||
|
||||
# Include directories for the executable
|
||||
target_include_directories(video2x PRIVATE
|
||||
${ALL_INCLUDE_DIRS}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${PROJECT_SOURCE_DIR}/include
|
||||
${PROJECT_SOURCE_DIR}/include/libvideo2x
|
||||
)
|
||||
|
||||
# Compile options for the executable
|
||||
target_compile_options(video2x PRIVATE $<$<CONFIG:Debug>:-g -DDEBUG>)
|
||||
|
||||
# Link the executable with the shared library
|
||||
target_link_libraries(video2x PRIVATE
|
||||
libvideo2x
|
||||
${FFMPEG_LIB}
|
||||
${SPDLOG_LIB}
|
||||
${BOOST_LIB}
|
||||
${VULKAN_LIB}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Define the default installation directories
|
||||
if(WIN32)
|
||||
set(BIN_DESTINATION_DEFAULT ".")
|
||||
set(INCLUDE_DESTINATION_DEFAULT "include/libvideo2x")
|
||||
set(LIB_DESTINATION_DEFAULT ".")
|
||||
set(MODEL_DESTINATION_DEFAULT ".")
|
||||
else()
|
||||
set(BIN_DESTINATION_DEFAULT "bin")
|
||||
set(INCLUDE_DESTINATION_DEFAULT "include/libvideo2x")
|
||||
set(LIB_DESTINATION_DEFAULT "lib")
|
||||
set(MODEL_DESTINATION_DEFAULT "share/video2x")
|
||||
endif()
|
||||
|
||||
# Explicitly set the output paths since OpenCV changes these variables
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||
|
||||
# Set the installation directories
|
||||
set(INSTALL_BIN_DESTINATION ${BIN_DESTINATION_DEFAULT} CACHE STRING "")
|
||||
set(INSTALL_INCLUDE_DESTINATION ${INCLUDE_DESTINATION_DEFAULT} CACHE STRING "")
|
||||
set(INSTALL_LIB_DESTINATION ${LIB_DESTINATION_DEFAULT} CACHE STRING "")
|
||||
set(INSTALL_MODEL_DESTINATION ${MODEL_DESTINATION_DEFAULT} CACHE STRING "")
|
||||
|
||||
# Common installation rules for libvideo2x and models
|
||||
install(TARGETS libvideo2x
|
||||
LIBRARY DESTINATION ${INSTALL_LIB_DESTINATION}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
ARCHIVE DESTINATION ${INSTALL_LIB_DESTINATION}
|
||||
RUNTIME DESTINATION ${INSTALL_BIN_DESTINATION}
|
||||
)
|
||||
|
||||
# Install model files
|
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/models DESTINATION ${INSTALL_MODEL_DESTINATION})
|
||||
|
||||
# Install the executable if BUILD_VIDEO2X_CLI is enabled
|
||||
if(BUILD_VIDEO2X_CLI)
|
||||
install(TARGETS video2x RUNTIME DESTINATION ${INSTALL_BIN_DESTINATION})
|
||||
endif()
|
||||
|
||||
# Install the header files
|
||||
install(FILES
|
||||
${PROJECT_SOURCE_DIR}/include/libvideo2x/libvideo2x.h
|
||||
${PROJECT_SOURCE_DIR}/include/libvideo2x/char_defs.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libvideo2x/version.h
|
||||
DESTINATION ${INSTALL_INCLUDE_DESTINATION}
|
||||
)
|
||||
|
||||
# Platform-specific installation rules
|
||||
if(WIN32)
|
||||
# Install Windows-specific dependencies
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
set(BOOST_DLL_PATH ${BOOST_BASE_PATH}/boost_program_options-vc143-mt-x64-1_86.dll)
|
||||
else()
|
||||
set(BOOST_DLL_PATH ${BOOST_BASE_PATH}/boost_program_options-vc143-mt-gd-x64-1_86.dll)
|
||||
endif()
|
||||
|
||||
install(FILES
|
||||
${CMAKE_BINARY_DIR}/realesrgan_install/bin/librealesrgan-ncnn-vulkan.dll
|
||||
${FFMPEG_BASE_PATH}/bin/swscale-8.dll
|
||||
${FFMPEG_BASE_PATH}/bin/avcodec-61.dll
|
||||
${FFMPEG_BASE_PATH}/bin/avdevice-61.dll
|
||||
${FFMPEG_BASE_PATH}/bin/avfilter-10.dll
|
||||
${FFMPEG_BASE_PATH}/bin/avformat-61.dll
|
||||
${FFMPEG_BASE_PATH}/bin/avutil-59.dll
|
||||
${FFMPEG_BASE_PATH}/bin/postproc-58.dll
|
||||
${FFMPEG_BASE_PATH}/bin/swresample-5.dll
|
||||
# ${OPENCV_BASE_PATH}/build/x64/vc16/bin/opencv_world4100.dll
|
||||
# ${OPENCV_BASE_PATH}/build/x64/vc16/bin/opencv_videoio_msmf4100_64.dll
|
||||
${NCNN_BASE_PATH}/bin/ncnn.dll
|
||||
${BOOST_DLL_PATH}
|
||||
DESTINATION ${INSTALL_BIN_DESTINATION}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
else()
|
||||
# Install Unix-specific dependencies
|
||||
install(FILES ${REALESRGAN_LIB}
|
||||
DESTINATION ${INSTALL_LIB_DESTINATION}
|
||||
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
|
||||
GROUP_READ GROUP_EXECUTE
|
||||
WORLD_READ WORLD_EXECUTE
|
||||
)
|
||||
endif()
|
||||
147
LICENSE
147
LICENSE
@@ -1,23 +1,21 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
@@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
@@ -72,7 +60,7 @@ modification follow.
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
@@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
@@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
157
Makefile
Normal file
157
Makefile
Normal file
@@ -0,0 +1,157 @@
|
||||
.PHONY: build static debug windows windows-debug debian ubuntu clean \
|
||||
test-realesrgan test-libplacebo \
|
||||
memcheck-realesrgan memcheck-libplacebo \
|
||||
heaptrack-realesrgan heaptrack-libplacebo
|
||||
|
||||
BINDIR=build
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
|
||||
TEST_VIDEO=data/standard-test.mp4
|
||||
TEST_OUTPUT=data/output.mp4
|
||||
|
||||
build:
|
||||
cmake -S . -B $(BINDIR) \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DCMAKE_C_COMPILER=$(CC) \
|
||||
-DCMAKE_CXX_COMPILER=$(CXX) \
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build $(BINDIR) --config Release --parallel
|
||||
cp $(BINDIR)/compile_commands.json .
|
||||
|
||||
static:
|
||||
cmake -S . -B $(BINDIR) \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DCMAKE_C_COMPILER=$(CC) \
|
||||
-DCMAKE_CXX_COMPILER=$(CXX) \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
cmake --build $(BINDIR) --config Release --parallel
|
||||
cp $(BINDIR)/compile_commands.json .
|
||||
|
||||
debug:
|
||||
cmake -S . -B $(BINDIR) \
|
||||
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
|
||||
-DCMAKE_C_COMPILER=$(CC) \
|
||||
-DCMAKE_CXX_COMPILER=$(CXX) \
|
||||
-DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build $(BINDIR) --config Debug --parallel
|
||||
cp $(BINDIR)/compile_commands.json .
|
||||
|
||||
windows:
|
||||
cmake -S . -B $(BINDIR) \
|
||||
-DUSE_SYSTEM_NCNN=OFF \
|
||||
-DUSE_SYSTEM_OPENCV=OFF \
|
||||
-DUSE_SYSTEM_SPDLOG=OFF \
|
||||
-DUSE_SYSTEM_BOOST=OFF \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=build/libvideo2x-shared
|
||||
cmake --build $(BINDIR) --config Release --parallel --target install
|
||||
|
||||
windows-debug:
|
||||
cmake -S . -B $(BINDIR) \
|
||||
-DUSE_SYSTEM_NCNN=OFF \
|
||||
-DUSE_SYSTEM_OPENCV=OFF \
|
||||
-DUSE_SYSTEM_SPDLOG=OFF \
|
||||
-DUSE_SYSTEM_BOOST=OFF \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_INSTALL_PREFIX=build/libvideo2x-shared
|
||||
cmake --build $(BINDIR) --config Debug --parallel --target install
|
||||
|
||||
debian:
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential cmake clang pkg-config \
|
||||
libavcodec-dev \
|
||||
libavdevice-dev \
|
||||
libavfilter-dev \
|
||||
libavformat-dev \
|
||||
libavutil-dev \
|
||||
libswscale-dev \
|
||||
libvulkan-dev \
|
||||
glslang-tools \
|
||||
libomp-dev \
|
||||
libspdlog-dev \
|
||||
libopencv-dev \
|
||||
libboost-program-options-dev
|
||||
cmake -B /tmp/build -S . -DUSE_SYSTEM_NCNN=OFF \
|
||||
-DCMAKE_C_COMPILER=$(CC) -DCMAKE_CXX_COMPILER=$(CXX) \
|
||||
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install \
|
||||
-DINSTALL_BIN_DESTINATION=. -DINSTALL_INCLUDE_DESTINATION=include \
|
||||
-DINSTALL_LIB_DESTINATION=. -DINSTALL_MODEL_DESTINATION=.
|
||||
cmake --build /tmp/build --config Release --target install --parallel
|
||||
|
||||
ubuntu:
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
apt-get update
|
||||
apt-get install -y --no-install-recommends \
|
||||
build-essential cmake pkg-config \
|
||||
libavcodec-dev \
|
||||
libavdevice-dev \
|
||||
libavfilter-dev \
|
||||
libavformat-dev \
|
||||
libavutil-dev \
|
||||
libswscale-dev \
|
||||
libvulkan-dev \
|
||||
glslang-tools \
|
||||
libomp-dev \
|
||||
libopencv-dev \
|
||||
libboost-program-options-dev
|
||||
cmake -B build -S . -DUSE_SYSTEM_NCNN=OFF -DUSE_SYSTEM_SPDLOG=OFF -DSPDLOG_NO_EXCEPTIONS=ON \
|
||||
-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \
|
||||
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=build/video2x_package/usr
|
||||
cmake --build build --config Release --target install --parallel
|
||||
mkdir -p build/video2x_package/DEBIAN
|
||||
cp packaging/debian/control build/video2x_package/DEBIAN/control
|
||||
dpkg-deb --build build/video2x_package
|
||||
|
||||
clean:
|
||||
rm -vrf $(BINDIR) data/output*.* heaptrack*.zst valgrind.log
|
||||
|
||||
test-realesrgan:
|
||||
LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
|
||||
-f realesrgan -r 4 -m realesr-animevideov3
|
||||
|
||||
test-libplacebo:
|
||||
LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
|
||||
-f libplacebo -w 1920 -h 1080 -s anime4k-v4-a
|
||||
|
||||
memcheck-realesrgan:
|
||||
LD_LIBRARY_PATH=$(BINDIR) valgrind \
|
||||
--tool=memcheck \
|
||||
--leak-check=full \
|
||||
--show-leak-kinds=all \
|
||||
--track-origins=yes \
|
||||
--show-reachable=yes \
|
||||
--verbose --log-file="valgrind.log" \
|
||||
$(BINDIR)/video2x \
|
||||
-i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
|
||||
-f realesrgan -r 2 -m realesr-animevideov3 \
|
||||
-p veryfast -b 1000000 -q 30
|
||||
|
||||
memcheck-libplacebo:
|
||||
LD_LIBRARY_PATH=$(BINDIR) valgrind \
|
||||
--tool=memcheck \
|
||||
--leak-check=full \
|
||||
--show-leak-kinds=all \
|
||||
--track-origins=yes \
|
||||
--show-reachable=yes \
|
||||
--verbose --log-file="valgrind.log" \
|
||||
$(BINDIR)/video2x \
|
||||
-i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
|
||||
-f libplacebo -w 1920 -h 1080 -s anime4k-v4-a \
|
||||
-p veryfast -b 1000000 -q 30
|
||||
|
||||
heaptrack-realesrgan:
|
||||
LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \
|
||||
$(BINDIR)/video2x \
|
||||
-i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
|
||||
-f realesrgan -r 4 -m realesr-animevideov3 \
|
||||
-p veryfast -b 1000000 -q 30
|
||||
|
||||
heaptrack-libplacebo:
|
||||
LD_LIBRARY_PATH=$(BINDIR) HEAPTRACK_ENABLE_DEBUGINFOD=1 heaptrack \
|
||||
$(BINDIR)/video2x \
|
||||
-i $(TEST_VIDEO) -o $(TEST_OUTPUT) \
|
||||
-f libplacebo -w 1920 -h 1080 -s anime4k-v4-a \
|
||||
-p veryfast -b 1000000 -q 30
|
||||
11
NOTICE
Normal file
11
NOTICE
Normal file
@@ -0,0 +1,11 @@
|
||||
Video2X
|
||||
Copyright (C) 2018-2024 K4YT3X and contributors.
|
||||
|
||||
This product depends on FFmpeg, which is available under the GNU Lesser General Public License 2.1.
|
||||
The source code can be found at https://github.com/FFmpeg/FFmpeg.
|
||||
|
||||
This product depends on Real-ESRGAN ncnn Vulkan, which is available under the MIT License.
|
||||
The source code can be found at https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan.
|
||||
|
||||
This product depends on ncnn, which is available under the BSD 3-Clause License.
|
||||
The source code can be found at https://github.com/Tencent/ncnn.
|
||||
313
README.md
313
README.md
@@ -1,272 +1,125 @@
|
||||
# Video2X Lossless Video Enlarger
|
||||
<p align="center">
|
||||
<img src="https://github.com/user-attachments/assets/5cd63373-e806-474f-94ec-6e04963bf90f"/>
|
||||
</br>
|
||||
<img src="https://img.shields.io/github/v/release/k4yt3x/video2x?style=flat-square"/>
|
||||
<img src="https://img.shields.io/github/actions/workflow/status/k4yt3x/video2x/build.yml?label=Build&style=flat-square"/>
|
||||
<img src="https://img.shields.io/github/downloads/k4yt3x/video2x/total?style=flat-square"/>
|
||||
<img src="https://img.shields.io/github/license/k4yt3x/video2x?style=flat-square"/>
|
||||
<img src="https://img.shields.io/badge/dynamic/json?color=%23e85b46&label=Patreon&query=data.attributes.patron_count&suffix=%20patrons&url=https%3A%2F%2Fwww.patreon.com%2Fapi%2Fcampaigns%2F4507807&style=flat-square"/>
|
||||
</p>
|
||||
|
||||
### Official Discussion Group (Telegram): https://t.me/video2x
|
||||
> [!IMPORTANT]
|
||||
> Versions 4 and 5 have reached end-of-life (EOL) status. Due to limited development resources, issues related to any version earlier than 6 will no longer be addressed.
|
||||
|
||||
## Download Builds (Windows)
|
||||
## 🌟 Version 6.0.0
|
||||
|
||||
You can go to the [releases page](https://github.com/k4yt3x/video2x/releases) to download the latest builds of `Video2X`. The exe files will require no Python or Python module installation.
|
||||
**[Download Windows Installer](https://github.com/k4yt3x/video2x/releases/download/6.0.0/video2x-qt6-windows-amd64-installer.exe)**
|
||||
|
||||
The **`full`** package provides all packages that will possibly be needed by `Video2X`, including `FFmpeg`, `waifu2x-caffe`, `waifu2x-converter-cpp`, `waifu2x-ncnn-vulkan`, and `Anime4K`. The config file (`video2x.json`) is also already configured for the environment. All you need to do is just to launch `video2x.exe`.
|
||||
**TL;DR: Version 6.0.0 is a complete rewrite of the Video2X project in C/C++, featuring a faster, more efficient architecture, cross-platform support, vastly improved output quality, and a new GUI and installer for easy setup on Windows.**
|
||||
|
||||
The **`light`** package provides only the most basic functions of `Video2X`. Only `video2x.exe`, `video2x_setup.exe` and `video2x.json` are included. To setup dependencies (e.g. `FFmpeg` and `Waifu2X`) automatically, simply launch `video2x_setup.exe`.
|
||||

|
||||
|
||||
## Prerequisites
|
||||
Version 6.0.0 is a complete rewrite of this project in C/C++. It:
|
||||
|
||||
Component names that are **bolded** can be automatically downloaded and configured with the `video2x_setup.py` script.
|
||||
- genuinely works this time, with much less hassle compared to the 5.0.0 beta;
|
||||
- is blazing fast, thanks to the new optimized pipeline and the efficiency of C/C++;
|
||||
- is cross-platform, available now for both Windows and Linux;
|
||||
- offers significantly better output quality with Anime4K v4 and RealESRGAN;
|
||||
- supports Anime4K v4 and all custom MPV-compatible GLSL shaders;
|
||||
- includes support for RealESRGAN (all three models) via ncnn and Vulkan;
|
||||
- requires zero additional disk space during processing, just space for the final output; and
|
||||
- exports a standard C function for easy integration into other projects! (documentations are on the way)
|
||||
|
||||
1. Operating System: Windows / Linux
|
||||
2. AMD GPU / Nvidia GPU
|
||||
3. AMD GPU driver / Nvidia GPU driver / Nvidia CUDNN
|
||||
4. [**FFmpeg**](https://ffmpeg.zeranoe.com/builds/)
|
||||
5. One of the following drivers
|
||||
- [**waifu2x-caffe**](https://github.com/lltcggie/waifu2x-caffe/releases)
|
||||
- [**waifu2x-converter-cpp**](https://github.com/DeadSix27/waifu2x-converter-cpp/releases)
|
||||
- [**waifu2x-ncnn-vulkan**](https://github.com/nihui/waifu2x-ncnn-vulkan)
|
||||
- [**Anime4K**](https://github.com/bloc97/Anime4K)
|
||||
Support for RealCUGAN and frame interpolation with RIFE are coming soon.
|
||||
|
||||
## Recent Changes
|
||||
## [🪟 Download for Windows](https://github.com/k4yt3x/video2x/releases/latest)
|
||||
|
||||
### 3.0.0 (November 26, 2019)
|
||||
You can download the latest Windows release from the [releases page](https://github.com/k4yt3x/video2x/releases/latest). For basic GUI usage, refer to the [GUI wiki page](https://github.com/k4yt3x/video2x/wiki/GUI). If you're unable to download directly from GitHub, try the [mirror](https://files.k4yt3x.com/Projects/Video2X/latest). The GUI currently supports the following languages:
|
||||
|
||||
- Linux compatibility
|
||||
- Configuration file changed to YAML format
|
||||
- You may still use a JSON-formatted config file. To do so, please specify `-c video2x.json`.
|
||||
- Other code clean-up and optimization
|
||||
- English (United States)
|
||||
- 简体中文(中国)
|
||||
- 日本語(日本)
|
||||
- Português (Portugal)
|
||||
|
||||
### 2.10.0 (August 16, 2019)
|
||||
## [🐧 Install on Linux](https://aur.archlinux.org/packages/video2x-git)
|
||||
|
||||
- **Added support for [Anime4K](https://github.com/bloc97/Anime4K)**
|
||||
You can install Video2X on Arch Linux using the [video2x-git](https://aur.archlinux.org/packages/video2x-git) package or download pre-compiled binaries from the [releases page](https://github.com/k4yt3x/video2x/releases/latest). If you'd like to build from source, refer to the [PKGBUILD](packaging/arch/PKGBUILD) file for a general overview of the required packages and commands. If you'd prefer not to compile the program from source, consider using the container image below.
|
||||
|
||||
### 2.9.0 (July 27, 2019)
|
||||
## [📦 Container Image](https://github.com/k4yt3x/video2x/pkgs/container/video2x)
|
||||
|
||||
- Changed file handling method from `os` to `pathlib`
|
||||
- Removed f_string dependency and support for legacy versions of Python
|
||||
- Organized file import statements
|
||||
Video2X container images are available on the GitHub Container Registry for easy deployment on Linux and macOS. If you already have Docker/Podman installed, only one command is needed to start upscaling a video. For more information on how to use Video2X's Docker image, please refer to the [documentations](https://github.com/K4YT3X/video2x/wiki/Container).
|
||||
|
||||
### Setup Script 1.6.0 (November 26, 2019)
|
||||
## [📔 Google Colab](https://colab.research.google.com/drive/1gWEwcA9y57EsxwOjmLNmNMXPsafw0kGo) (Outdated: 5.0.0-beta7)
|
||||
|
||||
- Added compatibility for new YAML configuration file
|
||||
- Added better exception handling
|
||||
You can use Video2X on [Google Colab](https://colab.research.google.com/) **for free** if you don't have a powerful GPU of your own. You can borrow a powerful GPU (NVIDIA T4, L4, or A100) on Google's server for free for a maximum of 12 hours per session. **Please use the free resource fairly** and do not create sessions back-to-back and run upscaling 24/7. This might result in you getting banned. You can get [Colab Pro/Pro+](https://colab.research.google.com/signup/pricing) if you'd like to use better GPUs and get longer runtimes. Usage instructions are embedded in the [Colab Notebook](https://colab.research.google.com/drive/1gWEwcA9y57EsxwOjmLNmNMXPsafw0kGo).
|
||||
|
||||
## Description
|
||||
## [💬 Telegram Discussion Group](https://t.me/video2x)
|
||||
|
||||
Video2X is an automation software based on waifu2x image enlarging engine. It extracts frames from a video, enlarge it by a number of times without losing any details or quality, keeping lines smooth and edges sharp.
|
||||
Join our Telegram discussion group to ask any questions you have about Video2X, chat directly with the developers, or discuss about super resolution technologies and the future of Video2X in general.
|
||||
|
||||
For short: **Video2X enlarges your video without losing details**
|
||||
## [📖 Documentations](https://github.com/k4yt3x/video2x/wiki)
|
||||
|
||||
Watch for the sharper edges in this screenshot around the shadows:
|
||||
Video2X's documentations are hosted on this repository's [Wiki page](https://github.com/k4yt3x/video2x/wiki). It includes comprehensive explanations for how to use the [GUI](https://github.com/k4yt3x/video2x/wiki/GUI), the [CLI](https://github.com/k4yt3x/video2x/wiki/CLI), the [container image](https://github.com/K4YT3X/video2x/wiki/Container), the [library](https://github.com/k4yt3x/video2x/wiki/Library), and more. The Wiki is open to edits by the community, so you, yes you, can also correct errors or add new contents to the documentations.
|
||||
|
||||

|
||||
## Introduction
|
||||
|
||||
**You can also watch the YouTube video Demo: https://www.youtube.com/watch?v=PG94iPoeoZk**
|
||||
Video2X is a machine-learning-powered framework for video upscaling and frame interpolation, built around three main components:
|
||||
|
||||
Clip is from trailer of animated movie "千と千尋の神隠し". Copyright belongs to "株式会社スタジオジブリ (STUDIO GHIBLI INC.)". Will delete immediately if use of clip is in violation of copyright.
|
||||
- [libvideo2x](https://github.com/k4yt3x/video2x/blob/master/src/libvideo2x.cpp): The core C++ library providing upscaling and frame interpolation capabilities.
|
||||
- [Video2X CLI](https://github.com/k4yt3x/video2x/blob/master/src/video2x.c): A command-line interface that utilizes `libvideo2x` for video processing.
|
||||
- [Video2X Qt6](https://github.com/k4yt3x/video2x-qt6): A Qt6-based graphical interface that utilizes `libvideo2x` for video processing.
|
||||
|
||||
## Screenshot
|
||||
### Video Demos
|
||||
|
||||

|
||||
\
|
||||
_Upscale demo: Spirited Away's movie trailer_
|
||||
|
||||

|
||||
- **Spirited Away**: [YouTube](https://youtu.be/mGEfasQl2Zo) | [Bilibili](https://www.bilibili.com/video/BV1V5411471i/)
|
||||
- 360P to 4K
|
||||
- The [original video](https://www.youtube.com/watch?v=ByXuk9QqQkk)'s copyright belongs to 株式会社スタジオジブリ
|
||||
- **Bad Apple!!**: [YouTube](https://youtu.be/A81rW_FI3cw) | [Bilibili](https://www.bilibili.com/video/BV16K411K7ue)
|
||||
- 384P 30 FPS to 4K 120 FPS with waifu2x and DAIN
|
||||
- The [original video](https://www.nicovideo.jp/watch/sm8628149)'s copyright belongs to あにら
|
||||
- **The Pet Girl of Sakurasou**: [YouTube](https://youtu.be/M0vDI1HH2_Y) | [Bilibili](https://www.bilibili.com/video/BV14k4y167KP/)
|
||||
- 240P 29.97 to 1080P 60 FPS with waifu2x and DAIN
|
||||
- The original video's copyright belongs to ASCII Media Works
|
||||
|
||||
---
|
||||
### Standard Test Clip
|
||||
|
||||
## Documentations
|
||||
The following clip can be used to test if your setup works properly. This is also the standard clip used for running performance benchmarks.
|
||||
|
||||
### [Video2X Wiki](https://github.com/k4yt3x/video2x/wiki)
|
||||
- [Standard Test Clip (240P)](https://files.k4yt3x.com/Resources/Videos/standard-test.mp4) 4.54 MiB
|
||||
- [waifu2x Upscaled Sample (1080P)](https://files.k4yt3x.com/Resources/Videos/standard-waifu2x.mp4) 4.54 MiB
|
||||
- [Ground Truth (1080P)](https://files.k4yt3x.com/Resources/Videos/standard-original.mp4) 22.2 MiB
|
||||
|
||||
You can find all detailed user-facing and developer-facing documentations in the [Video2X Wiki](https://github.com/k4yt3x/video2x/wiki). It covers everything from step-by-step instructions for beginners, to the code structure of this program for advanced users and developers. If this README page doesn't answer all your questions, the wiki page is where you should head to.
|
||||
|
||||
### [Step-By-Step Tutorial](https://github.com/k4yt3x/video2x/wiki/Step-By-Step-Tutorial)
|
||||
|
||||
For those who want a detailed walk-through of how to use `Video2X`, you can head to the [Step-By-Step Tutorial](https://github.com/k4yt3x/video2x/wiki/Step-By-Step-Tutorial) wiki page. It includes almost every step you need to perform in order to enlarge your first video.
|
||||
|
||||
### [Waifu2X Drivers](https://github.com/k4yt3x/video2x/wiki/Waifu2X-Drivers)
|
||||
|
||||
Go to the [Waifu2X Drivers](https://github.com/k4yt3x/video2x/wiki/Waifu2X-Drivers) wiki page if you want to see a detailed description on the different types of `waifu2x` drivers implemented by `Video2X`. This wiki page contains detailed difference between different drivers, and how to download and set each of them up for `Video2X`.
|
||||
|
||||
### [Q&A](https://github.com/k4yt3x/video2x/wiki/Q&A)
|
||||
|
||||
If you have any questions, first try visiting our [Q&A](https://github.com/k4yt3x/video2x/wiki/Q&A) page to see if your question is answered there. If not, open an issue and we will respond to your questions ASAP.
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- **Python 3**
|
||||
Download: https://www.python.org/downloads/windows/
|
||||
- **FFmpeg Windows Build**
|
||||
Download: https://ffmpeg.org/download.html
|
||||
- **waifu2x-caffe** (for Nvidia CUDA/CUDNN)
|
||||
Download: https://github.com/lltcggie/waifu2x-caffe/releases
|
||||
- **waifu2x-converter-cpp** (required for AMD, OpenCL and OpenGL processing)
|
||||
Download: https://github.com/DeadSix27/waifu2x-converter-cpp/releases
|
||||
- **waifu2x-ncnn-vulkan**
|
||||
Download: https://github.com/nihui/waifu2x-ncnn-vulkan/releases
|
||||
- **Anime4K**
|
||||
Download: https://github.com/bloc97/Anime4K/releases
|
||||
|
||||
### Installing Dependencies
|
||||
|
||||
First, clone the video2x repository.
|
||||
|
||||
```shell
|
||||
git clone https://github.com/k4yt3x/video2x.git
|
||||
cd video2x/bin
|
||||
```
|
||||
|
||||
Then you may run the `video2x_setup.py` script to install and configure the dependencies automatically. This script is designed and tested on Windows 10.
|
||||
|
||||
This script will install the newest version of `ffmpeg`, any one or all `waifu2x-caffe`, `waifu2x-converter-cpp`, and `waifu2x-ncnn-vulkan` to `%LOCALAPPDATA%\\video2x` and all required python libraries.
|
||||
|
||||
```shell
|
||||
python video2x_setup.py
|
||||
```
|
||||
|
||||
Alternatively, you can also install the dependencies manually. Please refer to the prerequisites section to see what's needed.
|
||||
|
||||
Then you'll need to install python dependencies before start using video2x. Install simply by executing the following command.
|
||||
|
||||
```shell
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
**Note that all command line arguments/options overwrite configuration file settings.**
|
||||
|
||||
### Sample Videos
|
||||
|
||||
If you can't find a video clip to begin with, or if you want to see a before-after comparison, we have prepared some sample clips for you. The quick start guide down below will also be based on the name of the sample clips.
|
||||
|
||||

|
||||
|
||||
- [Sample Video Original (240P) 1.7MB](https://files.flexio.org/Resources/Videos/sample_input.mp4)
|
||||
- [Sample Video Upscaled (1080P) 4.8MB](https://files.flexio.org/Resources/Videos/sample_output.mp4)
|
||||
|
||||
Clip is from anime "さくら荘のペットな彼女". Copyright belongs to "株式会社アニプレックス (Aniplex Inc.)". Will delete immediately if use of clip is in violation of copyright.
|
||||
|
||||
### Nvidia CUDA (waifu2x-caffe)
|
||||
|
||||
Enlarge the video to 1920x1080 using CUDA. You may also use the `-r/--ratio` option.
|
||||
|
||||
```shell
|
||||
python video2x.py -i sample_input.mp4 -o sample_output.mp4 -m gpu --width=1920 --height=1080
|
||||
```
|
||||
|
||||
### Nvidia CUDNN
|
||||
|
||||
Enlarge the video to 1920x1080 using CUDNN. You may also use the `-r/--ratio` option.
|
||||
|
||||
```shell
|
||||
python video2x.py -i sample_input.mp4 -o sample_output.mp4 -m cudnn --width=1920 --height=1080
|
||||
```
|
||||
|
||||
### AMD or Nvidia (waifu2x-converter-cpp OpenCL)
|
||||
|
||||
Enlarge the video by 2 times using OpenCL. Note that `waifu2x-converter-cpp` doesn't support width and height. You'll also have to explicitly specify that the driver to be used is `waifu2x_converter`.
|
||||
|
||||
```shell
|
||||
python video2x.py -i sample_input.mp4 -o sample_output.mp4 -m gpu -r 2 -d waifu2x_converter
|
||||
```
|
||||
|
||||
### AMD or Nvidia (waifu2x-ncnn-vulkan Vulkan)
|
||||
|
||||
```shell
|
||||
python video2x.py -i sample_input.mp4 -o sample_output.mp4 -m gpu -r 2 -d waifu2x_ncnn_vulkan
|
||||
```
|
||||
|
||||
### Anime4K
|
||||
|
||||
Enlarge the video by 2 times using Anime4K. **Remember to install and configure [JRE 12](https://www.oracle.com/technetwork/java/javase/downloads/java-archive-javase12-5440181.html) path in the configuration file.**
|
||||
|
||||
```shell
|
||||
python video2x.py -i sample_input.mp4 -o sample_output.mp4 -r 2 -d anime4k
|
||||
```
|
||||
|
||||
### CPU
|
||||
|
||||
Enlarge the video to 1920x1080 using the CPU. You may also use the `-r/--ratio` option. **waifu2x-based upscalers potentially run much slower than using a GPU, but Anime4K is more CPU-dependant**. The configuration file for this method is similar to the previous methods.
|
||||
|
||||
```shell
|
||||
python video2x.py -i sample_input.mp4 -o sample_output.mp4 -m cpu --width=1920 --height=1080
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# Full Usage
|
||||
|
||||
## General Options
|
||||
|
||||
### -h, --help
|
||||
show this help message and exit
|
||||
|
||||
## File Options
|
||||
|
||||
### -i INPUT, --input INPUT
|
||||
Source video file/directory (default: None)
|
||||
|
||||
### -o OUTPUT, --output OUTPUT
|
||||
Output video file/directory (default: None)
|
||||
|
||||
## Upscaling Options
|
||||
|
||||
### -m {cpu,gpu,cudnn}, --method {cpu,gpu,cudnn}
|
||||
Upscaling method (default: gpu)
|
||||
|
||||
### -d {waifu2x_caffe,waifu2x_converter}, --driver {waifu2x_caffe,waifu2x_converter}
|
||||
Waifu2x driver (default: waifu2x_caffe)
|
||||
|
||||
### -y MODEL_DIR, --model_dir MODEL_DIR
|
||||
Folder containing model JSON files
|
||||
|
||||
### -t THREADS, --threads THREADS
|
||||
Number of threads to use for upscaling (default: 5)
|
||||
|
||||
### -c CONFIG, --config CONFIG
|
||||
Video2X config file location (default: video2x\bin\video2x.json)
|
||||
|
||||
### -b, --batch
|
||||
Enable batch mode (select all default values to questions)
|
||||
|
||||
## Scaling Options
|
||||
|
||||
### --width WIDTH
|
||||
Output video width
|
||||
|
||||
### --height HEIGHT
|
||||
Output video height
|
||||
|
||||
### -r RATIO, --ratio RATIO
|
||||
Scaling ratio
|
||||
|
||||
---
|
||||
The original clip came from the anime "さくら荘のペットな彼女."\
|
||||
Copyright of this clip belongs to 株式会社アニプレックス.
|
||||
|
||||
## License
|
||||
|
||||
Licensed under the GNU General Public License Version 3 (GNU GPL v3)
|
||||
https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
This project is licensed under [GNU AGPL version 3](https://www.gnu.org/licenses/agpl-3.0.txt).\
|
||||
Copyright (C) 2018-2024 K4YT3X and [contributors](https://github.com/k4yt3x/video2x/graphs/contributors).
|
||||
|
||||

|
||||

|
||||
|
||||
(C) 2018-2020 K4YT3X
|
||||
This project includes or depends on these following projects:
|
||||
|
||||
## Credits
|
||||
| Project | License |
|
||||
| ------------------------------------------------------------------------------------- | --------------- |
|
||||
| [bloc97/Anime4K](https://github.com/bloc97/Anime4K) | MIT License |
|
||||
| [FFmpeg/FFmpeg](https://www.ffmpeg.org/) | LGPLv2.1, GPLv2 |
|
||||
| [xinntao/Real-ESRGAN-ncnn-vulkan](https://github.com/xinntao/Real-ESRGAN-ncnn-vulkan) | MIT License |
|
||||
| [Tencent/ncnn](https://github.com/Tencent/ncnn) | BSD 3-Clause |
|
||||
|
||||
This project relies on the following software and projects.
|
||||
|
||||
- [FFmpeg]('https://www.ffmpeg.org/')
|
||||
- [waifu2x-caffe](https://github.com/lltcggie/waifu2x-caffe)
|
||||
- [waifu2x-converter-cpp](https://github.com/DeadSix27/waifu2x-converter-cpp)
|
||||
- [waifu2x-ncnn-vulkan](https://github.com/nihui/waifu2x-ncnn-vulkan)
|
||||
- [Anime4K](https://github.com/bloc97/Anime4K)
|
||||
More licensing information can be found in the [NOTICE](NOTICE) file.
|
||||
|
||||
## Special Thanks
|
||||
|
||||
Appreciations given to the following code contributors:
|
||||
Special thanks to the following individuals for their significant contributions to the project, listed in alphabetical order.
|
||||
|
||||
- @BrianPetkovsek
|
||||
- @SAT3LL
|
||||
|
||||
## Related Resources
|
||||
|
||||
- [Dandere2x](https://github.com/CardinalPanda/dandere2x): `Dandere2x` is a lossy video upscaler also built around `waifu2x`, but with video compression techniques to shorten the time needed to process a video.
|
||||
- [@ArchieMeng](https://github.com/archiemeng)
|
||||
- [@BrianPetkovsek](https://github.com/BrianPetkovsek)
|
||||
- [@ddouglas87](https://github.com/ddouglas87)
|
||||
- [@lhanjian](https://github.com/lhanjian)
|
||||
- [@nihui](https://github.com/nihui)
|
||||
- [@sat3ll](https://github.com/sat3ll)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
theme: jekyll-theme-slate
|
||||
22
include/libvideo2x/char_defs.h
Normal file
22
include/libvideo2x/char_defs.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef CHAR_DEFS_H
|
||||
#define CHAR_DEFS_H
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef wchar_t CharType;
|
||||
#define STR(x) L##x
|
||||
#else
|
||||
typedef char CharType;
|
||||
#define STR(x) x
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef std::wstring StringType;
|
||||
#else
|
||||
typedef std::string StringType;
|
||||
#endif
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // CHAR_DEFS_H
|
||||
20
include/libvideo2x/conversions.h
Normal file
20
include/libvideo2x/conversions.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef CONVERSIONS_H
|
||||
#define CONVERSIONS_H
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/frame.h>
|
||||
#include <libswscale/swscale.h>
|
||||
}
|
||||
|
||||
#include <mat.h>
|
||||
|
||||
// Convert AVFrame to another pixel format
|
||||
AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt);
|
||||
|
||||
// Convert AVFrame to ncnn::Mat
|
||||
ncnn::Mat avframe_to_ncnn_mat(AVFrame *frame);
|
||||
|
||||
// Convert ncnn::Mat to AVFrame
|
||||
AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt);
|
||||
|
||||
#endif // CONVERSIONS_H
|
||||
20
include/libvideo2x/decoder.h
Normal file
20
include/libvideo2x/decoder.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef DECODER_H
|
||||
#define DECODER_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
int init_decoder(
|
||||
AVHWDeviceType hw_type,
|
||||
AVBufferRef *hw_ctx,
|
||||
std::filesystem::path in_fpath,
|
||||
AVFormatContext **fmt_ctx,
|
||||
AVCodecContext **dec_ctx,
|
||||
int *vstream_idx
|
||||
);
|
||||
|
||||
#endif // DECODER_H
|
||||
35
include/libvideo2x/encoder.h
Normal file
35
include/libvideo2x/encoder.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef ENCODER_H
|
||||
#define ENCODER_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/opt.h>
|
||||
}
|
||||
|
||||
#include "libvideo2x.h"
|
||||
|
||||
int init_encoder(
|
||||
AVBufferRef *hw_ctx,
|
||||
std::filesystem::path out_fpath,
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVFormatContext **ofmt_ctx,
|
||||
AVCodecContext **enc_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
EncoderConfig *encoder_config,
|
||||
int vstream_idx,
|
||||
int **stream_map
|
||||
);
|
||||
|
||||
int write_frame(
|
||||
AVFrame *frame,
|
||||
AVCodecContext *enc_ctx,
|
||||
AVFormatContext *ofmt_ctx,
|
||||
int vstream_idx
|
||||
);
|
||||
|
||||
int flush_encoder(AVCodecContext *enc_ctx, AVFormatContext *ofmt_ctx);
|
||||
|
||||
#endif // ENCODER_H
|
||||
21
include/libvideo2x/filter.h
Normal file
21
include/libvideo2x/filter.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef FILTER_H
|
||||
#define FILTER_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavfilter/avfilter.h>
|
||||
#include <libavutil/buffer.h>
|
||||
}
|
||||
|
||||
// Abstract base class for filters
|
||||
class Filter {
|
||||
public:
|
||||
virtual ~Filter() = default;
|
||||
virtual int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) = 0;
|
||||
virtual int process_frame(AVFrame *in_frame, AVFrame **out_frame) = 0;
|
||||
virtual int flush(std::vector<AVFrame *> &_) { return 0; }
|
||||
};
|
||||
|
||||
#endif // FILTER_H
|
||||
19
include/libvideo2x/fsutils.h
Normal file
19
include/libvideo2x/fsutils.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef FSUTILS_H
|
||||
#define FSUTILS_H
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "char_defs.h"
|
||||
|
||||
bool filepath_is_readable(const std::filesystem::path &path);
|
||||
|
||||
std::filesystem::path find_resource_file(const std::filesystem::path &path);
|
||||
|
||||
std::string path_to_u8string(const std::filesystem::path &path);
|
||||
|
||||
StringType path_to_string_type(const std::filesystem::path &path);
|
||||
|
||||
StringType to_string_type(int value);
|
||||
|
||||
#endif // FSUTILS_H
|
||||
22
include/libvideo2x/libplacebo.h
Normal file
22
include/libvideo2x/libplacebo.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#ifndef PLACEBO_H
|
||||
#define PLACEBO_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavfilter/avfilter.h>
|
||||
}
|
||||
|
||||
int init_libplacebo(
|
||||
AVFilterGraph **filter_graph,
|
||||
AVFilterContext **buffersrc_ctx,
|
||||
AVFilterContext **buffersink_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
int out_width,
|
||||
int out_height,
|
||||
uint32_t vk_device_index,
|
||||
const std::filesystem::path &shader_path
|
||||
);
|
||||
|
||||
#endif // PLACEBO_H
|
||||
49
include/libvideo2x/libplacebo_filter.h
Normal file
49
include/libvideo2x/libplacebo_filter.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef LIBPLACEBO_FILTER_H
|
||||
#define LIBPLACEBO_FILTER_H
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavfilter/buffersink.h>
|
||||
#include <libavfilter/buffersrc.h>
|
||||
}
|
||||
|
||||
#include "filter.h"
|
||||
|
||||
// LibplaceboFilter class definition
|
||||
class LibplaceboFilter : public Filter {
|
||||
private:
|
||||
AVFilterGraph *filter_graph;
|
||||
AVFilterContext *buffersrc_ctx;
|
||||
AVFilterContext *buffersink_ctx;
|
||||
uint32_t vk_device_index;
|
||||
const std::filesystem::path shader_path;
|
||||
int out_width;
|
||||
int out_height;
|
||||
AVRational in_time_base;
|
||||
AVRational out_time_base;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
LibplaceboFilter(
|
||||
uint32_t vk_device_index,
|
||||
const std::filesystem::path &shader_path,
|
||||
int width,
|
||||
int height
|
||||
);
|
||||
|
||||
// Destructor
|
||||
virtual ~LibplaceboFilter() override;
|
||||
|
||||
// Initializes the filter with decoder and encoder contexts
|
||||
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
|
||||
|
||||
// Processes an input frame and returns the processed frame
|
||||
int process_frame(AVFrame *in_frame, AVFrame **out_frame) override;
|
||||
|
||||
// Flushes any remaining frames
|
||||
int flush(std::vector<AVFrame *> &flushed_frames) override;
|
||||
};
|
||||
|
||||
#endif // LIBPLACEBO_FILTER_H
|
||||
125
include/libvideo2x/libvideo2x.h
Normal file
125
include/libvideo2x/libvideo2x.h
Normal file
@@ -0,0 +1,125 @@
|
||||
#ifndef LIBVIDEO2X_H
|
||||
#define LIBVIDEO2X_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "char_defs.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef LIBVIDEO2X_EXPORTS
|
||||
#define LIBVIDEO2X_API __declspec(dllexport)
|
||||
#else
|
||||
#define LIBVIDEO2X_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define LIBVIDEO2X_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Enum to specify filter type
|
||||
enum FilterType {
|
||||
FILTER_LIBPLACEBO,
|
||||
FILTER_REALESRGAN
|
||||
};
|
||||
|
||||
// Enum to specify log level
|
||||
enum Libvideo2xLogLevel {
|
||||
LIBVIDEO2X_LOG_LEVEL_TRACE,
|
||||
LIBVIDEO2X_LOG_LEVEL_DEBUG,
|
||||
LIBVIDEO2X_LOG_LEVEL_INFO,
|
||||
LIBVIDEO2X_LOG_LEVEL_WARNING,
|
||||
LIBVIDEO2X_LOG_LEVEL_ERROR,
|
||||
LIBVIDEO2X_LOG_LEVEL_CRITICAL,
|
||||
LIBVIDEO2X_LOG_LEVEL_OFF
|
||||
};
|
||||
|
||||
// Configuration for Libplacebo filter
|
||||
struct LibplaceboConfig {
|
||||
int out_width;
|
||||
int out_height;
|
||||
const CharType *shader_path;
|
||||
};
|
||||
|
||||
// Configuration for RealESRGAN filter
|
||||
struct RealESRGANConfig {
|
||||
bool tta_mode;
|
||||
int scaling_factor;
|
||||
const CharType *model_name;
|
||||
};
|
||||
|
||||
// Unified filter configuration
|
||||
struct FilterConfig {
|
||||
enum FilterType filter_type;
|
||||
union {
|
||||
struct LibplaceboConfig libplacebo;
|
||||
struct RealESRGANConfig realesrgan;
|
||||
} config;
|
||||
};
|
||||
|
||||
// Encoder configuration
|
||||
struct EncoderConfig {
|
||||
int out_width;
|
||||
int out_height;
|
||||
bool copy_streams;
|
||||
enum AVCodecID codec;
|
||||
enum AVPixelFormat pix_fmt;
|
||||
const char *preset;
|
||||
int64_t bit_rate;
|
||||
float crf;
|
||||
};
|
||||
|
||||
// Video processing context
|
||||
struct VideoProcessingContext {
|
||||
int64_t processed_frames;
|
||||
int64_t total_frames;
|
||||
time_t start_time;
|
||||
bool pause;
|
||||
bool abort;
|
||||
bool completed;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Process a video file using the selected filter and encoder settings.
|
||||
*
|
||||
* @param[in] in_fname Path to the input video file
|
||||
* @param[in] out_fname Path to the output video file
|
||||
* @param[in] log_level Log level
|
||||
* @param[in] benchmark Flag to enable benchmarking mode
|
||||
* @param[in] vk_device_index Vulkan device index
|
||||
* @param[in] hw_type Hardware device type
|
||||
* @param[in] filter_config Filter configurations
|
||||
* @param[in] encoder_config Encoder configurations
|
||||
* @param[in,out] proc_ctx Video processing context
|
||||
* @return int 0 on success, non-zero value on error
|
||||
*/
|
||||
LIBVIDEO2X_API int process_video(
|
||||
const CharType *in_fname,
|
||||
const CharType *out_fname,
|
||||
enum Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
uint32_t vk_device_index,
|
||||
enum AVHWDeviceType hw_device_type,
|
||||
const struct FilterConfig *filter_config,
|
||||
struct EncoderConfig *encoder_config,
|
||||
struct VideoProcessingContext *proc_ctx
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // LIBVIDEO2X_H
|
||||
43
include/libvideo2x/realesrgan_filter.h
Normal file
43
include/libvideo2x/realesrgan_filter.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef REALSRGAN_FILTER_H
|
||||
#define REALSRGAN_FILTER_H
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
}
|
||||
|
||||
#include "char_defs.h"
|
||||
#include "filter.h"
|
||||
#include "realesrgan.h"
|
||||
|
||||
// RealesrganFilter class definition
|
||||
class RealesrganFilter : public Filter {
|
||||
private:
|
||||
RealESRGAN *realesrgan;
|
||||
int gpuid;
|
||||
bool tta_mode;
|
||||
int scaling_factor;
|
||||
const StringType model_name;
|
||||
AVRational in_time_base;
|
||||
AVRational out_time_base;
|
||||
AVPixelFormat out_pix_fmt;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
RealesrganFilter(
|
||||
int gpuid = 0,
|
||||
bool tta_mode = false,
|
||||
int scaling_factor = 4,
|
||||
const StringType model_name = STR("realesr-animevideov3")
|
||||
);
|
||||
|
||||
// Destructor
|
||||
virtual ~RealesrganFilter() override;
|
||||
|
||||
// Initializes the filter with decoder and encoder contexts
|
||||
int init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *hw_ctx) override;
|
||||
|
||||
// Processes an input frame and returns the processed frame
|
||||
int process_frame(AVFrame *in_frame, AVFrame **out_frame) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
34
include/libvideo2x/timer.h
Normal file
34
include/libvideo2x/timer.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <thread>
|
||||
|
||||
class Timer {
|
||||
public:
|
||||
Timer();
|
||||
~Timer();
|
||||
|
||||
void start();
|
||||
void pause();
|
||||
void resume();
|
||||
void stop();
|
||||
|
||||
bool is_running() const;
|
||||
bool is_paused() const;
|
||||
int64_t get_elapsed_time() const;
|
||||
|
||||
private:
|
||||
std::atomic<bool> running;
|
||||
std::atomic<bool> paused;
|
||||
std::thread timer_thread;
|
||||
int64_t elapsed_time;
|
||||
std::chrono::steady_clock::time_point start_time;
|
||||
std::chrono::steady_clock::time_point pause_start_time;
|
||||
|
||||
void update_elapsed_time();
|
||||
};
|
||||
|
||||
#endif // TIMER_H
|
||||
6
include/libvideo2x/version.h.in
Normal file
6
include/libvideo2x/version.h.in
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef VERSION_H
|
||||
#define VERSION_H
|
||||
|
||||
#define LIBVIDEO2X_VERSION_STRING "@PROJECT_VERSION@"
|
||||
|
||||
#endif // VERSION_H
|
||||
2585
models/libplacebo/anime4k-v4-a+a.glsl
vendored
Normal file
2585
models/libplacebo/anime4k-v4-a+a.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2309
models/libplacebo/anime4k-v4-a.glsl
vendored
Normal file
2309
models/libplacebo/anime4k-v4-a.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2585
models/libplacebo/anime4k-v4-b+b.glsl
vendored
Normal file
2585
models/libplacebo/anime4k-v4-b+b.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2309
models/libplacebo/anime4k-v4-b.glsl
vendored
Normal file
2309
models/libplacebo/anime4k-v4-b.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1711
models/libplacebo/anime4k-v4-c+a.glsl
vendored
Normal file
1711
models/libplacebo/anime4k-v4-c+a.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1435
models/libplacebo/anime4k-v4-c.glsl
vendored
Normal file
1435
models/libplacebo/anime4k-v4-c.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
9173
models/libplacebo/anime4k-v4.1-gan.glsl
vendored
Normal file
9173
models/libplacebo/anime4k-v4.1-gan.glsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
BIN
models/realesrgan/realesr-animevideov3-x2.bin
vendored
Normal file
BIN
models/realesrgan/realesr-animevideov3-x2.bin
vendored
Normal file
Binary file not shown.
43
models/realesrgan/realesr-animevideov3-x2.param
vendored
Normal file
43
models/realesrgan/realesr-animevideov3-x2.param
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
7767517
|
||||
41 42
|
||||
Input input.1 0 1 data
|
||||
Split splitncnn_input0 1 2 data input.1_splitncnn_0 input.1_splitncnn_1
|
||||
Convolution Conv_0 1 1 input.1_splitncnn_1 54 0=64 1=3 4=1 5=1 6=1728
|
||||
PReLU PRelu_1 1 1 54 56 0=64
|
||||
Convolution Conv_2 1 1 56 57 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_3 1 1 57 59 0=64
|
||||
Convolution Conv_4 1 1 59 60 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_5 1 1 60 62 0=64
|
||||
Convolution Conv_6 1 1 62 63 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_7 1 1 63 65 0=64
|
||||
Convolution Conv_8 1 1 65 66 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_9 1 1 66 68 0=64
|
||||
Convolution Conv_10 1 1 68 69 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_11 1 1 69 71 0=64
|
||||
Convolution Conv_12 1 1 71 72 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_13 1 1 72 74 0=64
|
||||
Convolution Conv_14 1 1 74 75 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_15 1 1 75 77 0=64
|
||||
Convolution Conv_16 1 1 77 78 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_17 1 1 78 80 0=64
|
||||
Convolution Conv_18 1 1 80 81 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_19 1 1 81 83 0=64
|
||||
Convolution Conv_20 1 1 83 84 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_21 1 1 84 86 0=64
|
||||
Convolution Conv_22 1 1 86 87 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_23 1 1 87 89 0=64
|
||||
Convolution Conv_24 1 1 89 90 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_25 1 1 90 92 0=64
|
||||
Convolution Conv_26 1 1 92 93 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_27 1 1 93 95 0=64
|
||||
Convolution Conv_28 1 1 95 96 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_29 1 1 96 98 0=64
|
||||
Convolution Conv_30 1 1 98 99 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_31 1 1 99 101 0=64
|
||||
Convolution Conv_32 1 1 101 102 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_33 1 1 102 104 0=64
|
||||
Convolution Conv_34 1 1 104 105 0=48 1=3 4=1 5=1 6=27648
|
||||
PixelShuffle DepthToSpace_35 1 1 105 106 0=4
|
||||
Interp Resize_37 1 1 input.1_splitncnn_0 111 0=1 1=4.000000e+00 2=4.000000e+00
|
||||
BinaryOp Add_38 2 1 106 111 112
|
||||
Interp Resize_40 1 1 112 output 0=3 1=5.000000e-01 2=5.000000e-01
|
||||
BIN
models/realesrgan/realesr-animevideov3-x3.bin
vendored
Normal file
BIN
models/realesrgan/realesr-animevideov3-x3.bin
vendored
Normal file
Binary file not shown.
43
models/realesrgan/realesr-animevideov3-x3.param
vendored
Normal file
43
models/realesrgan/realesr-animevideov3-x3.param
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
7767517
|
||||
41 42
|
||||
Input input.1 0 1 data
|
||||
Split splitncnn_input0 1 2 data input.1_splitncnn_0 input.1_splitncnn_1
|
||||
Convolution Conv_0 1 1 input.1_splitncnn_1 54 0=64 1=3 4=1 5=1 6=1728
|
||||
PReLU PRelu_1 1 1 54 56 0=64
|
||||
Convolution Conv_2 1 1 56 57 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_3 1 1 57 59 0=64
|
||||
Convolution Conv_4 1 1 59 60 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_5 1 1 60 62 0=64
|
||||
Convolution Conv_6 1 1 62 63 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_7 1 1 63 65 0=64
|
||||
Convolution Conv_8 1 1 65 66 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_9 1 1 66 68 0=64
|
||||
Convolution Conv_10 1 1 68 69 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_11 1 1 69 71 0=64
|
||||
Convolution Conv_12 1 1 71 72 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_13 1 1 72 74 0=64
|
||||
Convolution Conv_14 1 1 74 75 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_15 1 1 75 77 0=64
|
||||
Convolution Conv_16 1 1 77 78 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_17 1 1 78 80 0=64
|
||||
Convolution Conv_18 1 1 80 81 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_19 1 1 81 83 0=64
|
||||
Convolution Conv_20 1 1 83 84 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_21 1 1 84 86 0=64
|
||||
Convolution Conv_22 1 1 86 87 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_23 1 1 87 89 0=64
|
||||
Convolution Conv_24 1 1 89 90 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_25 1 1 90 92 0=64
|
||||
Convolution Conv_26 1 1 92 93 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_27 1 1 93 95 0=64
|
||||
Convolution Conv_28 1 1 95 96 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_29 1 1 96 98 0=64
|
||||
Convolution Conv_30 1 1 98 99 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_31 1 1 99 101 0=64
|
||||
Convolution Conv_32 1 1 101 102 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_33 1 1 102 104 0=64
|
||||
Convolution Conv_34 1 1 104 105 0=48 1=3 4=1 5=1 6=27648
|
||||
PixelShuffle DepthToSpace_35 1 1 105 106 0=4
|
||||
Interp Resize_37 1 1 input.1_splitncnn_0 111 0=1 1=4.000000e+00 2=4.000000e+00
|
||||
BinaryOp Add_38 2 1 106 111 112
|
||||
Interp Resize_40 1 1 112 output 0=3 1=7.500000e-01 2=7.500000e-01
|
||||
BIN
models/realesrgan/realesr-animevideov3-x4.bin
vendored
Normal file
BIN
models/realesrgan/realesr-animevideov3-x4.bin
vendored
Normal file
Binary file not shown.
42
models/realesrgan/realesr-animevideov3-x4.param
vendored
Normal file
42
models/realesrgan/realesr-animevideov3-x4.param
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
7767517
|
||||
40 41
|
||||
Input input.1 0 1 data
|
||||
Split splitncnn_input0 1 2 data input.1_splitncnn_0 input.1_splitncnn_1
|
||||
Convolution Conv_0 1 1 input.1_splitncnn_1 54 0=64 1=3 4=1 5=1 6=1728
|
||||
PReLU PRelu_1 1 1 54 56 0=64
|
||||
Convolution Conv_2 1 1 56 57 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_3 1 1 57 59 0=64
|
||||
Convolution Conv_4 1 1 59 60 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_5 1 1 60 62 0=64
|
||||
Convolution Conv_6 1 1 62 63 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_7 1 1 63 65 0=64
|
||||
Convolution Conv_8 1 1 65 66 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_9 1 1 66 68 0=64
|
||||
Convolution Conv_10 1 1 68 69 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_11 1 1 69 71 0=64
|
||||
Convolution Conv_12 1 1 71 72 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_13 1 1 72 74 0=64
|
||||
Convolution Conv_14 1 1 74 75 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_15 1 1 75 77 0=64
|
||||
Convolution Conv_16 1 1 77 78 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_17 1 1 78 80 0=64
|
||||
Convolution Conv_18 1 1 80 81 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_19 1 1 81 83 0=64
|
||||
Convolution Conv_20 1 1 83 84 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_21 1 1 84 86 0=64
|
||||
Convolution Conv_22 1 1 86 87 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_23 1 1 87 89 0=64
|
||||
Convolution Conv_24 1 1 89 90 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_25 1 1 90 92 0=64
|
||||
Convolution Conv_26 1 1 92 93 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_27 1 1 93 95 0=64
|
||||
Convolution Conv_28 1 1 95 96 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_29 1 1 96 98 0=64
|
||||
Convolution Conv_30 1 1 98 99 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_31 1 1 99 101 0=64
|
||||
Convolution Conv_32 1 1 101 102 0=64 1=3 4=1 5=1 6=36864
|
||||
PReLU PRelu_33 1 1 102 104 0=64
|
||||
Convolution Conv_34 1 1 104 105 0=48 1=3 4=1 5=1 6=27648
|
||||
PixelShuffle DepthToSpace_35 1 1 105 106 0=4
|
||||
Interp Resize_37 1 1 input.1_splitncnn_0 111 0=1 1=4.000000e+00 2=4.000000e+00
|
||||
BinaryOp Add_38 2 1 106 111 output
|
||||
BIN
models/realesrgan/realesrgan-plus-anime-x4.bin
vendored
Normal file
BIN
models/realesrgan/realesrgan-plus-anime-x4.bin
vendored
Normal file
Binary file not shown.
270
models/realesrgan/realesrgan-plus-anime-x4.param
vendored
Normal file
270
models/realesrgan/realesrgan-plus-anime-x4.param
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
7767517
|
||||
268 473
|
||||
Input input.1 0 1 data
|
||||
Convolution Conv_0 1 1 data 193 0=64 1=3 4=1 5=1 6=1728
|
||||
Split splitncnn_0 1 8 193 193_splitncnn_0 193_splitncnn_1 193_splitncnn_2 193_splitncnn_3 193_splitncnn_4 193_splitncnn_5 193_splitncnn_6 193_splitncnn_7
|
||||
Convolution Conv_1 1 1 193_splitncnn_7 195 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_1 1 4 195 195_splitncnn_0 195_splitncnn_1 195_splitncnn_2 195_splitncnn_3
|
||||
Concat Concat_3 2 1 193_splitncnn_6 195_splitncnn_3 196
|
||||
Convolution Conv_4 1 1 196 198 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_2 1 3 198 198_splitncnn_0 198_splitncnn_1 198_splitncnn_2
|
||||
Concat Concat_6 3 1 193_splitncnn_5 195_splitncnn_2 198_splitncnn_2 199
|
||||
Convolution Conv_7 1 1 199 201 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_3 1 2 201 201_splitncnn_0 201_splitncnn_1
|
||||
Concat Concat_9 4 1 193_splitncnn_4 195_splitncnn_1 198_splitncnn_1 201_splitncnn_1 202
|
||||
Convolution Conv_10 1 1 202 204 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_12 5 1 193_splitncnn_3 195_splitncnn_0 198_splitncnn_0 201_splitncnn_0 204 205
|
||||
Convolution Conv_13 1 1 205 206 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_16 2 1 206 193_splitncnn_2 209 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_4 1 6 209 209_splitncnn_0 209_splitncnn_1 209_splitncnn_2 209_splitncnn_3 209_splitncnn_4 209_splitncnn_5
|
||||
Convolution Conv_17 1 1 209_splitncnn_5 211 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_5 1 4 211 211_splitncnn_0 211_splitncnn_1 211_splitncnn_2 211_splitncnn_3
|
||||
Concat Concat_19 2 1 209_splitncnn_4 211_splitncnn_3 212
|
||||
Convolution Conv_20 1 1 212 214 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_6 1 3 214 214_splitncnn_0 214_splitncnn_1 214_splitncnn_2
|
||||
Concat Concat_22 3 1 209_splitncnn_3 211_splitncnn_2 214_splitncnn_2 215
|
||||
Convolution Conv_23 1 1 215 217 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_7 1 2 217 217_splitncnn_0 217_splitncnn_1
|
||||
Concat Concat_25 4 1 209_splitncnn_2 211_splitncnn_1 214_splitncnn_1 217_splitncnn_1 218
|
||||
Convolution Conv_26 1 1 218 220 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_28 5 1 209_splitncnn_1 211_splitncnn_0 214_splitncnn_0 217_splitncnn_0 220 221
|
||||
Convolution Conv_29 1 1 221 222 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_32 2 1 222 209_splitncnn_0 225 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_8 1 6 225 225_splitncnn_0 225_splitncnn_1 225_splitncnn_2 225_splitncnn_3 225_splitncnn_4 225_splitncnn_5
|
||||
Convolution Conv_33 1 1 225_splitncnn_5 227 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_9 1 4 227 227_splitncnn_0 227_splitncnn_1 227_splitncnn_2 227_splitncnn_3
|
||||
Concat Concat_35 2 1 225_splitncnn_4 227_splitncnn_3 228
|
||||
Convolution Conv_36 1 1 228 230 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_10 1 3 230 230_splitncnn_0 230_splitncnn_1 230_splitncnn_2
|
||||
Concat Concat_38 3 1 225_splitncnn_3 227_splitncnn_2 230_splitncnn_2 231
|
||||
Convolution Conv_39 1 1 231 233 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_11 1 2 233 233_splitncnn_0 233_splitncnn_1
|
||||
Concat Concat_41 4 1 225_splitncnn_2 227_splitncnn_1 230_splitncnn_1 233_splitncnn_1 234
|
||||
Convolution Conv_42 1 1 234 236 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_44 5 1 225_splitncnn_1 227_splitncnn_0 230_splitncnn_0 233_splitncnn_0 236 237
|
||||
Convolution Conv_45 1 1 237 238 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_48 2 1 238 225_splitncnn_0 241 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Eltwise Add_51 2 1 241 193_splitncnn_1 244 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_12 1 7 244 244_splitncnn_0 244_splitncnn_1 244_splitncnn_2 244_splitncnn_3 244_splitncnn_4 244_splitncnn_5 244_splitncnn_6
|
||||
Convolution Conv_52 1 1 244_splitncnn_6 246 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_13 1 4 246 246_splitncnn_0 246_splitncnn_1 246_splitncnn_2 246_splitncnn_3
|
||||
Concat Concat_54 2 1 244_splitncnn_5 246_splitncnn_3 247
|
||||
Convolution Conv_55 1 1 247 249 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_14 1 3 249 249_splitncnn_0 249_splitncnn_1 249_splitncnn_2
|
||||
Concat Concat_57 3 1 244_splitncnn_4 246_splitncnn_2 249_splitncnn_2 250
|
||||
Convolution Conv_58 1 1 250 252 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_15 1 2 252 252_splitncnn_0 252_splitncnn_1
|
||||
Concat Concat_60 4 1 244_splitncnn_3 246_splitncnn_1 249_splitncnn_1 252_splitncnn_1 253
|
||||
Convolution Conv_61 1 1 253 255 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_63 5 1 244_splitncnn_2 246_splitncnn_0 249_splitncnn_0 252_splitncnn_0 255 256
|
||||
Convolution Conv_64 1 1 256 257 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_67 2 1 257 244_splitncnn_1 260 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_16 1 6 260 260_splitncnn_0 260_splitncnn_1 260_splitncnn_2 260_splitncnn_3 260_splitncnn_4 260_splitncnn_5
|
||||
Convolution Conv_68 1 1 260_splitncnn_5 262 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_17 1 4 262 262_splitncnn_0 262_splitncnn_1 262_splitncnn_2 262_splitncnn_3
|
||||
Concat Concat_70 2 1 260_splitncnn_4 262_splitncnn_3 263
|
||||
Convolution Conv_71 1 1 263 265 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_18 1 3 265 265_splitncnn_0 265_splitncnn_1 265_splitncnn_2
|
||||
Concat Concat_73 3 1 260_splitncnn_3 262_splitncnn_2 265_splitncnn_2 266
|
||||
Convolution Conv_74 1 1 266 268 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_19 1 2 268 268_splitncnn_0 268_splitncnn_1
|
||||
Concat Concat_76 4 1 260_splitncnn_2 262_splitncnn_1 265_splitncnn_1 268_splitncnn_1 269
|
||||
Convolution Conv_77 1 1 269 271 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_79 5 1 260_splitncnn_1 262_splitncnn_0 265_splitncnn_0 268_splitncnn_0 271 272
|
||||
Convolution Conv_80 1 1 272 273 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_83 2 1 273 260_splitncnn_0 276 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_20 1 6 276 276_splitncnn_0 276_splitncnn_1 276_splitncnn_2 276_splitncnn_3 276_splitncnn_4 276_splitncnn_5
|
||||
Convolution Conv_84 1 1 276_splitncnn_5 278 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_21 1 4 278 278_splitncnn_0 278_splitncnn_1 278_splitncnn_2 278_splitncnn_3
|
||||
Concat Concat_86 2 1 276_splitncnn_4 278_splitncnn_3 279
|
||||
Convolution Conv_87 1 1 279 281 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_22 1 3 281 281_splitncnn_0 281_splitncnn_1 281_splitncnn_2
|
||||
Concat Concat_89 3 1 276_splitncnn_3 278_splitncnn_2 281_splitncnn_2 282
|
||||
Convolution Conv_90 1 1 282 284 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_23 1 2 284 284_splitncnn_0 284_splitncnn_1
|
||||
Concat Concat_92 4 1 276_splitncnn_2 278_splitncnn_1 281_splitncnn_1 284_splitncnn_1 285
|
||||
Convolution Conv_93 1 1 285 287 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_95 5 1 276_splitncnn_1 278_splitncnn_0 281_splitncnn_0 284_splitncnn_0 287 288
|
||||
Convolution Conv_96 1 1 288 289 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_99 2 1 289 276_splitncnn_0 292 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Eltwise Add_102 2 1 292 244_splitncnn_0 295 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_24 1 7 295 295_splitncnn_0 295_splitncnn_1 295_splitncnn_2 295_splitncnn_3 295_splitncnn_4 295_splitncnn_5 295_splitncnn_6
|
||||
Convolution Conv_103 1 1 295_splitncnn_6 297 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_25 1 4 297 297_splitncnn_0 297_splitncnn_1 297_splitncnn_2 297_splitncnn_3
|
||||
Concat Concat_105 2 1 295_splitncnn_5 297_splitncnn_3 298
|
||||
Convolution Conv_106 1 1 298 300 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_26 1 3 300 300_splitncnn_0 300_splitncnn_1 300_splitncnn_2
|
||||
Concat Concat_108 3 1 295_splitncnn_4 297_splitncnn_2 300_splitncnn_2 301
|
||||
Convolution Conv_109 1 1 301 303 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_27 1 2 303 303_splitncnn_0 303_splitncnn_1
|
||||
Concat Concat_111 4 1 295_splitncnn_3 297_splitncnn_1 300_splitncnn_1 303_splitncnn_1 304
|
||||
Convolution Conv_112 1 1 304 306 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_114 5 1 295_splitncnn_2 297_splitncnn_0 300_splitncnn_0 303_splitncnn_0 306 307
|
||||
Convolution Conv_115 1 1 307 308 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_118 2 1 308 295_splitncnn_1 311 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_28 1 6 311 311_splitncnn_0 311_splitncnn_1 311_splitncnn_2 311_splitncnn_3 311_splitncnn_4 311_splitncnn_5
|
||||
Convolution Conv_119 1 1 311_splitncnn_5 313 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_29 1 4 313 313_splitncnn_0 313_splitncnn_1 313_splitncnn_2 313_splitncnn_3
|
||||
Concat Concat_121 2 1 311_splitncnn_4 313_splitncnn_3 314
|
||||
Convolution Conv_122 1 1 314 316 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_30 1 3 316 316_splitncnn_0 316_splitncnn_1 316_splitncnn_2
|
||||
Concat Concat_124 3 1 311_splitncnn_3 313_splitncnn_2 316_splitncnn_2 317
|
||||
Convolution Conv_125 1 1 317 319 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_31 1 2 319 319_splitncnn_0 319_splitncnn_1
|
||||
Concat Concat_127 4 1 311_splitncnn_2 313_splitncnn_1 316_splitncnn_1 319_splitncnn_1 320
|
||||
Convolution Conv_128 1 1 320 322 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_130 5 1 311_splitncnn_1 313_splitncnn_0 316_splitncnn_0 319_splitncnn_0 322 323
|
||||
Convolution Conv_131 1 1 323 324 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_134 2 1 324 311_splitncnn_0 327 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_32 1 6 327 327_splitncnn_0 327_splitncnn_1 327_splitncnn_2 327_splitncnn_3 327_splitncnn_4 327_splitncnn_5
|
||||
Convolution Conv_135 1 1 327_splitncnn_5 329 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_33 1 4 329 329_splitncnn_0 329_splitncnn_1 329_splitncnn_2 329_splitncnn_3
|
||||
Concat Concat_137 2 1 327_splitncnn_4 329_splitncnn_3 330
|
||||
Convolution Conv_138 1 1 330 332 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_34 1 3 332 332_splitncnn_0 332_splitncnn_1 332_splitncnn_2
|
||||
Concat Concat_140 3 1 327_splitncnn_3 329_splitncnn_2 332_splitncnn_2 333
|
||||
Convolution Conv_141 1 1 333 335 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_35 1 2 335 335_splitncnn_0 335_splitncnn_1
|
||||
Concat Concat_143 4 1 327_splitncnn_2 329_splitncnn_1 332_splitncnn_1 335_splitncnn_1 336
|
||||
Convolution Conv_144 1 1 336 338 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_146 5 1 327_splitncnn_1 329_splitncnn_0 332_splitncnn_0 335_splitncnn_0 338 339
|
||||
Convolution Conv_147 1 1 339 340 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_150 2 1 340 327_splitncnn_0 343 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Eltwise Add_153 2 1 343 295_splitncnn_0 346 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_36 1 7 346 346_splitncnn_0 346_splitncnn_1 346_splitncnn_2 346_splitncnn_3 346_splitncnn_4 346_splitncnn_5 346_splitncnn_6
|
||||
Convolution Conv_154 1 1 346_splitncnn_6 348 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_37 1 4 348 348_splitncnn_0 348_splitncnn_1 348_splitncnn_2 348_splitncnn_3
|
||||
Concat Concat_156 2 1 346_splitncnn_5 348_splitncnn_3 349
|
||||
Convolution Conv_157 1 1 349 351 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_38 1 3 351 351_splitncnn_0 351_splitncnn_1 351_splitncnn_2
|
||||
Concat Concat_159 3 1 346_splitncnn_4 348_splitncnn_2 351_splitncnn_2 352
|
||||
Convolution Conv_160 1 1 352 354 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_39 1 2 354 354_splitncnn_0 354_splitncnn_1
|
||||
Concat Concat_162 4 1 346_splitncnn_3 348_splitncnn_1 351_splitncnn_1 354_splitncnn_1 355
|
||||
Convolution Conv_163 1 1 355 357 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_165 5 1 346_splitncnn_2 348_splitncnn_0 351_splitncnn_0 354_splitncnn_0 357 358
|
||||
Convolution Conv_166 1 1 358 359 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_169 2 1 359 346_splitncnn_1 362 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_40 1 6 362 362_splitncnn_0 362_splitncnn_1 362_splitncnn_2 362_splitncnn_3 362_splitncnn_4 362_splitncnn_5
|
||||
Convolution Conv_170 1 1 362_splitncnn_5 364 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_41 1 4 364 364_splitncnn_0 364_splitncnn_1 364_splitncnn_2 364_splitncnn_3
|
||||
Concat Concat_172 2 1 362_splitncnn_4 364_splitncnn_3 365
|
||||
Convolution Conv_173 1 1 365 367 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_42 1 3 367 367_splitncnn_0 367_splitncnn_1 367_splitncnn_2
|
||||
Concat Concat_175 3 1 362_splitncnn_3 364_splitncnn_2 367_splitncnn_2 368
|
||||
Convolution Conv_176 1 1 368 370 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_43 1 2 370 370_splitncnn_0 370_splitncnn_1
|
||||
Concat Concat_178 4 1 362_splitncnn_2 364_splitncnn_1 367_splitncnn_1 370_splitncnn_1 371
|
||||
Convolution Conv_179 1 1 371 373 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_181 5 1 362_splitncnn_1 364_splitncnn_0 367_splitncnn_0 370_splitncnn_0 373 374
|
||||
Convolution Conv_182 1 1 374 375 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_185 2 1 375 362_splitncnn_0 378 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_44 1 6 378 378_splitncnn_0 378_splitncnn_1 378_splitncnn_2 378_splitncnn_3 378_splitncnn_4 378_splitncnn_5
|
||||
Convolution Conv_186 1 1 378_splitncnn_5 380 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_45 1 4 380 380_splitncnn_0 380_splitncnn_1 380_splitncnn_2 380_splitncnn_3
|
||||
Concat Concat_188 2 1 378_splitncnn_4 380_splitncnn_3 381
|
||||
Convolution Conv_189 1 1 381 383 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_46 1 3 383 383_splitncnn_0 383_splitncnn_1 383_splitncnn_2
|
||||
Concat Concat_191 3 1 378_splitncnn_3 380_splitncnn_2 383_splitncnn_2 384
|
||||
Convolution Conv_192 1 1 384 386 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_47 1 2 386 386_splitncnn_0 386_splitncnn_1
|
||||
Concat Concat_194 4 1 378_splitncnn_2 380_splitncnn_1 383_splitncnn_1 386_splitncnn_1 387
|
||||
Convolution Conv_195 1 1 387 389 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_197 5 1 378_splitncnn_1 380_splitncnn_0 383_splitncnn_0 386_splitncnn_0 389 390
|
||||
Convolution Conv_198 1 1 390 391 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_201 2 1 391 378_splitncnn_0 394 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Eltwise Add_204 2 1 394 346_splitncnn_0 397 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_48 1 7 397 397_splitncnn_0 397_splitncnn_1 397_splitncnn_2 397_splitncnn_3 397_splitncnn_4 397_splitncnn_5 397_splitncnn_6
|
||||
Convolution Conv_205 1 1 397_splitncnn_6 399 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_49 1 4 399 399_splitncnn_0 399_splitncnn_1 399_splitncnn_2 399_splitncnn_3
|
||||
Concat Concat_207 2 1 397_splitncnn_5 399_splitncnn_3 400
|
||||
Convolution Conv_208 1 1 400 402 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_50 1 3 402 402_splitncnn_0 402_splitncnn_1 402_splitncnn_2
|
||||
Concat Concat_210 3 1 397_splitncnn_4 399_splitncnn_2 402_splitncnn_2 403
|
||||
Convolution Conv_211 1 1 403 405 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_51 1 2 405 405_splitncnn_0 405_splitncnn_1
|
||||
Concat Concat_213 4 1 397_splitncnn_3 399_splitncnn_1 402_splitncnn_1 405_splitncnn_1 406
|
||||
Convolution Conv_214 1 1 406 408 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_216 5 1 397_splitncnn_2 399_splitncnn_0 402_splitncnn_0 405_splitncnn_0 408 409
|
||||
Convolution Conv_217 1 1 409 410 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_220 2 1 410 397_splitncnn_1 413 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_52 1 6 413 413_splitncnn_0 413_splitncnn_1 413_splitncnn_2 413_splitncnn_3 413_splitncnn_4 413_splitncnn_5
|
||||
Convolution Conv_221 1 1 413_splitncnn_5 415 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_53 1 4 415 415_splitncnn_0 415_splitncnn_1 415_splitncnn_2 415_splitncnn_3
|
||||
Concat Concat_223 2 1 413_splitncnn_4 415_splitncnn_3 416
|
||||
Convolution Conv_224 1 1 416 418 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_54 1 3 418 418_splitncnn_0 418_splitncnn_1 418_splitncnn_2
|
||||
Concat Concat_226 3 1 413_splitncnn_3 415_splitncnn_2 418_splitncnn_2 419
|
||||
Convolution Conv_227 1 1 419 421 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_55 1 2 421 421_splitncnn_0 421_splitncnn_1
|
||||
Concat Concat_229 4 1 413_splitncnn_2 415_splitncnn_1 418_splitncnn_1 421_splitncnn_1 422
|
||||
Convolution Conv_230 1 1 422 424 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_232 5 1 413_splitncnn_1 415_splitncnn_0 418_splitncnn_0 421_splitncnn_0 424 425
|
||||
Convolution Conv_233 1 1 425 426 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_236 2 1 426 413_splitncnn_0 429 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_56 1 6 429 429_splitncnn_0 429_splitncnn_1 429_splitncnn_2 429_splitncnn_3 429_splitncnn_4 429_splitncnn_5
|
||||
Convolution Conv_237 1 1 429_splitncnn_5 431 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_57 1 4 431 431_splitncnn_0 431_splitncnn_1 431_splitncnn_2 431_splitncnn_3
|
||||
Concat Concat_239 2 1 429_splitncnn_4 431_splitncnn_3 432
|
||||
Convolution Conv_240 1 1 432 434 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_58 1 3 434 434_splitncnn_0 434_splitncnn_1 434_splitncnn_2
|
||||
Concat Concat_242 3 1 429_splitncnn_3 431_splitncnn_2 434_splitncnn_2 435
|
||||
Convolution Conv_243 1 1 435 437 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_59 1 2 437 437_splitncnn_0 437_splitncnn_1
|
||||
Concat Concat_245 4 1 429_splitncnn_2 431_splitncnn_1 434_splitncnn_1 437_splitncnn_1 438
|
||||
Convolution Conv_246 1 1 438 440 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_248 5 1 429_splitncnn_1 431_splitncnn_0 434_splitncnn_0 437_splitncnn_0 440 441
|
||||
Convolution Conv_249 1 1 441 442 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_252 2 1 442 429_splitncnn_0 445 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Eltwise Add_255 2 1 445 397_splitncnn_0 448 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_60 1 7 448 448_splitncnn_0 448_splitncnn_1 448_splitncnn_2 448_splitncnn_3 448_splitncnn_4 448_splitncnn_5 448_splitncnn_6
|
||||
Convolution Conv_256 1 1 448_splitncnn_6 450 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_61 1 4 450 450_splitncnn_0 450_splitncnn_1 450_splitncnn_2 450_splitncnn_3
|
||||
Concat Concat_258 2 1 448_splitncnn_5 450_splitncnn_3 451
|
||||
Convolution Conv_259 1 1 451 453 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_62 1 3 453 453_splitncnn_0 453_splitncnn_1 453_splitncnn_2
|
||||
Concat Concat_261 3 1 448_splitncnn_4 450_splitncnn_2 453_splitncnn_2 454
|
||||
Convolution Conv_262 1 1 454 456 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_63 1 2 456 456_splitncnn_0 456_splitncnn_1
|
||||
Concat Concat_264 4 1 448_splitncnn_3 450_splitncnn_1 453_splitncnn_1 456_splitncnn_1 457
|
||||
Convolution Conv_265 1 1 457 459 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_267 5 1 448_splitncnn_2 450_splitncnn_0 453_splitncnn_0 456_splitncnn_0 459 460
|
||||
Convolution Conv_268 1 1 460 461 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_271 2 1 461 448_splitncnn_1 464 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_64 1 6 464 464_splitncnn_0 464_splitncnn_1 464_splitncnn_2 464_splitncnn_3 464_splitncnn_4 464_splitncnn_5
|
||||
Convolution Conv_272 1 1 464_splitncnn_5 466 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_65 1 4 466 466_splitncnn_0 466_splitncnn_1 466_splitncnn_2 466_splitncnn_3
|
||||
Concat Concat_274 2 1 464_splitncnn_4 466_splitncnn_3 467
|
||||
Convolution Conv_275 1 1 467 469 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_66 1 3 469 469_splitncnn_0 469_splitncnn_1 469_splitncnn_2
|
||||
Concat Concat_277 3 1 464_splitncnn_3 466_splitncnn_2 469_splitncnn_2 470
|
||||
Convolution Conv_278 1 1 470 472 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_67 1 2 472 472_splitncnn_0 472_splitncnn_1
|
||||
Concat Concat_280 4 1 464_splitncnn_2 466_splitncnn_1 469_splitncnn_1 472_splitncnn_1 473
|
||||
Convolution Conv_281 1 1 473 475 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_283 5 1 464_splitncnn_1 466_splitncnn_0 469_splitncnn_0 472_splitncnn_0 475 476
|
||||
Convolution Conv_284 1 1 476 477 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_287 2 1 477 464_splitncnn_0 480 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Split splitncnn_68 1 6 480 480_splitncnn_0 480_splitncnn_1 480_splitncnn_2 480_splitncnn_3 480_splitncnn_4 480_splitncnn_5
|
||||
Convolution Conv_288 1 1 480_splitncnn_5 482 0=32 1=3 4=1 5=1 6=18432 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_69 1 4 482 482_splitncnn_0 482_splitncnn_1 482_splitncnn_2 482_splitncnn_3
|
||||
Concat Concat_290 2 1 480_splitncnn_4 482_splitncnn_3 483
|
||||
Convolution Conv_291 1 1 483 485 0=32 1=3 4=1 5=1 6=27648 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_70 1 3 485 485_splitncnn_0 485_splitncnn_1 485_splitncnn_2
|
||||
Concat Concat_293 3 1 480_splitncnn_3 482_splitncnn_2 485_splitncnn_2 486
|
||||
Convolution Conv_294 1 1 486 488 0=32 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Split splitncnn_71 1 2 488 488_splitncnn_0 488_splitncnn_1
|
||||
Concat Concat_296 4 1 480_splitncnn_2 482_splitncnn_1 485_splitncnn_1 488_splitncnn_1 489
|
||||
Convolution Conv_297 1 1 489 491 0=32 1=3 4=1 5=1 6=46080 9=2 -23310=1,2.000000e-01
|
||||
Concat Concat_299 5 1 480_splitncnn_1 482_splitncnn_0 485_splitncnn_0 488_splitncnn_0 491 492
|
||||
Convolution Conv_300 1 1 492 493 0=64 1=3 4=1 5=1 6=110592
|
||||
Eltwise Add_303 2 1 493 480_splitncnn_0 496 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Eltwise Add_306 2 1 496 448_splitncnn_0 499 0=1 -23301=2,2.000000e-01,1.000000e+00
|
||||
Convolution Conv_307 1 1 499 500 0=64 1=3 4=1 5=1 6=36864
|
||||
BinaryOp Add_308 2 1 193_splitncnn_0 500 501
|
||||
Interp Resize_310 1 1 501 506 0=1 1=2.000000e+00 2=2.000000e+00
|
||||
Convolution Conv_311 1 1 506 508 0=64 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Interp Resize_314 1 1 508 513 0=1 1=2.000000e+00 2=2.000000e+00
|
||||
Convolution Conv_315 1 1 513 515 0=64 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Convolution Conv_317 1 1 515 517 0=64 1=3 4=1 5=1 6=36864 9=2 -23310=1,2.000000e-01
|
||||
Convolution Conv_319 1 1 517 output 0=3 1=3 4=1 5=1 6=1728
|
||||
BIN
models/realesrgan/realesrgan-plus-x4.bin
vendored
Normal file
BIN
models/realesrgan/realesrgan-plus-x4.bin
vendored
Normal file
Binary file not shown.
1001
models/realesrgan/realesrgan-plus-x4.param
vendored
Normal file
1001
models/realesrgan/realesrgan-plus-x4.param
vendored
Normal file
File diff suppressed because it is too large
Load Diff
27
packaging/arch/PKGBUILD
Normal file
27
packaging/arch/PKGBUILD
Normal file
@@ -0,0 +1,27 @@
|
||||
pkgname=video2x
|
||||
pkgver=r874.66c623f
|
||||
pkgrel=1
|
||||
pkgdesc="A machine learning-based lossless video super resolution framework"
|
||||
arch=('x86_64')
|
||||
url="https://github.com/k4yt3x/video2x"
|
||||
license=('AGPL3')
|
||||
depends=('ffmpeg' 'ncnn' 'vulkan-driver' 'opencv' 'spdlog' 'boost-libs')
|
||||
makedepends=('git' 'cmake' 'make' 'clang' 'pkgconf' 'vulkan-headers' 'openmp' 'boost')
|
||||
|
||||
pkgver() {
|
||||
printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
|
||||
}
|
||||
|
||||
prepare() {
|
||||
git submodule update --init --recursive
|
||||
}
|
||||
|
||||
build() {
|
||||
cmake -B build -S .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
|
||||
cmake --build build --config Release --parallel
|
||||
}
|
||||
|
||||
package() {
|
||||
DESTDIR="$pkgdir" cmake --install build
|
||||
}
|
||||
|
||||
8
packaging/debian/control
Normal file
8
packaging/debian/control
Normal file
@@ -0,0 +1,8 @@
|
||||
Package: video2x
|
||||
Version: 6.1.0
|
||||
Section: video
|
||||
Priority: optional
|
||||
Architecture: amd64
|
||||
Maintainer: K4YT3X <i@k4yt3x.com>
|
||||
Depends: ffmpeg, libboost-program-options1.83.0
|
||||
Description: A machine learning-based lossless video super resolution framework.
|
||||
46
packaging/docker/Dockerfile
Normal file
46
packaging/docker/Dockerfile
Normal file
@@ -0,0 +1,46 @@
|
||||
# Name: Video2X Dockerfile
|
||||
# Creator: K4YT3X
|
||||
# Date Created: February 3, 2022
|
||||
# Last Modified: November 1, 2024
|
||||
|
||||
# stage 1: build the python components into wheels
|
||||
FROM docker.io/archlinux:latest AS builder
|
||||
|
||||
# Install dependencies and create a non-root user
|
||||
RUN pacman -Syy --noconfirm \
|
||||
base-devel git cmake make clang pkgconf sudo \
|
||||
ffmpeg ncnn vulkan-headers openmp spdlog opencv boost \
|
||||
nvidia-utils vulkan-radeon vulkan-intel vulkan-swrast \
|
||||
&& useradd -m builder \
|
||||
&& echo 'builder ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/builder
|
||||
|
||||
# Switch to the non-root user and copy the source code
|
||||
USER builder
|
||||
COPY --chown=builder:builder . /video2x
|
||||
WORKDIR /video2x
|
||||
|
||||
# Build the package
|
||||
RUN cp packaging/arch/PKGBUILD . \
|
||||
&& makepkg -s --noconfirm \
|
||||
&& find /video2x -maxdepth 1 -name 'video2x-*.pkg.tar.zst' ! -name '*-debug-*' | head -n 1 | \
|
||||
xargs -I {} cp {} /tmp/video2x.pkg.tar.zst
|
||||
|
||||
# stage 2: install wheels into the final image
|
||||
FROM docker.io/archlinux:latest
|
||||
LABEL maintainer="K4YT3X <i@k4yt3x.com>" \
|
||||
org.opencontainers.image.source="https://github.com/k4yt3x/video2x" \
|
||||
org.opencontainers.image.description="A lossless video super resolution framework"
|
||||
|
||||
ENV VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/nvidia_icd.json\
|
||||
:/usr/share/vulkan/icd.d/radeon_icd.x86_64.json\
|
||||
:/usr/share/vulkan/icd.d/intel_icd.x86_64.json\
|
||||
:/usr/share/vulkan/icd.d/lvp_icd.x86_64.json
|
||||
|
||||
COPY --from=builder /tmp/video2x.pkg.tar.zst /video2x.pkg.tar.zst
|
||||
RUN pacman -Sy --noconfirm nvidia-utils vulkan-radeon vulkan-intel vulkan-swrast \
|
||||
ffmpeg ncnn spdlog opencv boost-libs \
|
||||
&& pacman -U --noconfirm /video2x.pkg.tar.zst \
|
||||
&& rm -rf /video2x.pkg.tar.zst /var/cache/pacman/pkg/*
|
||||
|
||||
WORKDIR /host
|
||||
ENTRYPOINT ["/usr/bin/video2x"]
|
||||
98
scripts/download_merge_anime4k_glsl.py
Executable file
98
scripts/download_merge_anime4k_glsl.py
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/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",
|
||||
],
|
||||
"gan": [
|
||||
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_GAN_UUL.glsl",
|
||||
f"{GITHUB_GLSL_ROOT}/Upscale/Anime4K_Upscale_GAN_x4_UUL.glsl",
|
||||
f"{GITHUB_GLSL_ROOT}/Restore/Anime4K_Restore_CNN_Soft_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"
|
||||
|
||||
version = "v4"
|
||||
if mode == "gan":
|
||||
version = "v4.1"
|
||||
|
||||
with (SHADERS_DIR / Path(f"anime4k-{version}-{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()
|
||||
@@ -1,92 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Anime4K Driver
|
||||
Author: K4YT3X
|
||||
Date Created: August 15, 2019
|
||||
Last Modified: November 15, 2019
|
||||
|
||||
Description: This class is a high-level wrapper
|
||||
for Anime4k.
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
|
||||
|
||||
class Anime4k:
|
||||
"""This class communicates with Anime4K engine
|
||||
|
||||
An object will be created for this class, containing information
|
||||
about the binary address and the processing method. When being called
|
||||
by the main program, other detailed information will be passed to
|
||||
the upscale function.
|
||||
"""
|
||||
|
||||
def __init__(self, driver_settings):
|
||||
self.driver_settings = driver_settings
|
||||
self.print_lock = threading.Lock()
|
||||
|
||||
def upscale(self, input_directory, output_directory, scale_ratio, upscaler_exceptions, push_strength=None, push_grad_strength=None):
|
||||
""" Anime4K wrapper
|
||||
|
||||
Arguments:
|
||||
file_in {string} -- input file path
|
||||
file_out {string} -- output file path
|
||||
|
||||
Keyword Arguments:
|
||||
scale {int} -- scale ratio (default: {None})
|
||||
push_strength {int} -- residual push strength (default: {None})
|
||||
push_grad_strength {int} -- residual gradient push strength (default: {None})
|
||||
|
||||
Returns:
|
||||
subprocess.Popen.returncode -- command line return value of execution
|
||||
"""
|
||||
try:
|
||||
# return value is the sum of all execution return codes
|
||||
return_value = 0
|
||||
|
||||
# get a list lof all image files in input_directory
|
||||
extracted_frame_files = [f for f in input_directory.iterdir() if str(f).lower().endswith('.png') or str(f).lower().endswith('.jpg')]
|
||||
|
||||
# upscale each image in input_directory
|
||||
for image in extracted_frame_files:
|
||||
|
||||
execute = [
|
||||
self.driver_settings['java_path'],
|
||||
'-jar',
|
||||
self.driver_settings['path'],
|
||||
str(image.absolute()),
|
||||
str(output_directory / image.name),
|
||||
str(scale_ratio)
|
||||
]
|
||||
|
||||
# optional arguments
|
||||
kwargs = [
|
||||
'push_strength',
|
||||
'push_grad_strength'
|
||||
]
|
||||
|
||||
# if optional argument specified, append value to execution list
|
||||
for arg in kwargs:
|
||||
if locals()[arg] is not None:
|
||||
execute.extend([locals([arg])])
|
||||
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'Executing: {execute}', )
|
||||
self.print_lock.release()
|
||||
return_value += subprocess.run(execute, check=True).returncode
|
||||
|
||||
# print thread exiting message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting')
|
||||
self.print_lock.release()
|
||||
|
||||
# return command execution return code
|
||||
return return_value
|
||||
except Exception as e:
|
||||
upscaler_exceptions.append(e)
|
||||
197
src/conversions.cpp
Normal file
197
src/conversions.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
#include "conversions.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
// Convert AVFrame format
|
||||
AVFrame *convert_avframe_pix_fmt(AVFrame *src_frame, AVPixelFormat pix_fmt) {
|
||||
AVFrame *dst_frame = av_frame_alloc();
|
||||
if (dst_frame == nullptr) {
|
||||
spdlog::error("Failed to allocate destination AVFrame.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dst_frame->format = pix_fmt;
|
||||
dst_frame->width = src_frame->width;
|
||||
dst_frame->height = src_frame->height;
|
||||
|
||||
// Allocate memory for the converted frame
|
||||
if (av_frame_get_buffer(dst_frame, 32) < 0) {
|
||||
spdlog::error("Failed to allocate memory for AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create a SwsContext for pixel format conversion
|
||||
SwsContext *sws_ctx = sws_getContext(
|
||||
src_frame->width,
|
||||
src_frame->height,
|
||||
static_cast<AVPixelFormat>(src_frame->format),
|
||||
dst_frame->width,
|
||||
dst_frame->height,
|
||||
pix_fmt,
|
||||
SWS_BILINEAR,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (sws_ctx == nullptr) {
|
||||
spdlog::error("Failed to initialize swscale context.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Perform the conversion
|
||||
sws_scale(
|
||||
sws_ctx,
|
||||
src_frame->data,
|
||||
src_frame->linesize,
|
||||
0,
|
||||
src_frame->height,
|
||||
dst_frame->data,
|
||||
dst_frame->linesize
|
||||
);
|
||||
|
||||
// Clean up
|
||||
sws_freeContext(sws_ctx);
|
||||
|
||||
return dst_frame;
|
||||
}
|
||||
|
||||
// Convert AVFrame to ncnn::Mat by copying the data
|
||||
ncnn::Mat avframe_to_ncnn_mat(AVFrame *frame) {
|
||||
AVFrame *converted_frame = nullptr;
|
||||
|
||||
// Convert to BGR24 format if necessary
|
||||
if (frame->format != AV_PIX_FMT_BGR24) {
|
||||
converted_frame = convert_avframe_pix_fmt(frame, AV_PIX_FMT_BGR24);
|
||||
if (!converted_frame) {
|
||||
spdlog::error("Failed to convert AVFrame to BGR24.");
|
||||
return ncnn::Mat();
|
||||
}
|
||||
} else {
|
||||
// If the frame is already in BGR24, use it directly
|
||||
converted_frame = frame;
|
||||
}
|
||||
|
||||
// Allocate a new ncnn::Mat and copy the data
|
||||
int width = converted_frame->width;
|
||||
int height = converted_frame->height;
|
||||
ncnn::Mat ncnn_image = ncnn::Mat(width, height, static_cast<size_t>(3), 3);
|
||||
|
||||
// Manually copy the pixel data from AVFrame to the new ncnn::Mat
|
||||
const uint8_t *src_data = converted_frame->data[0];
|
||||
for (int y = 0; y < height; y++) {
|
||||
uint8_t *dst_row = ncnn_image.row<uint8_t>(y);
|
||||
const uint8_t *src_row = src_data + y * converted_frame->linesize[0];
|
||||
|
||||
// Copy 3 channels (BGR) per pixel
|
||||
memcpy(dst_row, src_row, static_cast<size_t>(width) * 3);
|
||||
}
|
||||
|
||||
// If we allocated a converted frame, free it
|
||||
if (converted_frame != frame) {
|
||||
av_frame_free(&converted_frame);
|
||||
}
|
||||
|
||||
return ncnn_image;
|
||||
}
|
||||
|
||||
// Convert ncnn::Mat to AVFrame with a specified pixel format (this part is unchanged)
|
||||
AVFrame *ncnn_mat_to_avframe(const ncnn::Mat &mat, AVPixelFormat pix_fmt) {
|
||||
int ret;
|
||||
|
||||
// Step 1: Allocate a destination AVFrame for the specified pixel format
|
||||
AVFrame *dst_frame = av_frame_alloc();
|
||||
if (!dst_frame) {
|
||||
spdlog::error("Failed to allocate destination AVFrame.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
dst_frame->format = pix_fmt;
|
||||
dst_frame->width = mat.w;
|
||||
dst_frame->height = mat.h;
|
||||
|
||||
// Allocate memory for the frame buffer
|
||||
if (av_frame_get_buffer(dst_frame, 32) < 0) {
|
||||
spdlog::error("Failed to allocate memory for destination AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Step 2: Convert ncnn::Mat to BGR AVFrame
|
||||
AVFrame *bgr_frame = av_frame_alloc();
|
||||
if (!bgr_frame) {
|
||||
spdlog::error("Failed to allocate intermediate BGR AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bgr_frame->format = AV_PIX_FMT_BGR24;
|
||||
bgr_frame->width = mat.w;
|
||||
bgr_frame->height = mat.h;
|
||||
|
||||
// Allocate memory for the intermediate BGR frame
|
||||
if (av_frame_get_buffer(bgr_frame, 32) < 0) {
|
||||
spdlog::error("Failed to allocate memory for BGR AVFrame.");
|
||||
av_frame_free(&dst_frame);
|
||||
av_frame_free(&bgr_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Copy the pixel data from ncnn::Mat to the BGR AVFrame
|
||||
for (int y = 0; y < mat.h; y++) {
|
||||
uint8_t *dst_row = bgr_frame->data[0] + y * bgr_frame->linesize[0];
|
||||
const uint8_t *src_row = mat.row<const uint8_t>(y);
|
||||
|
||||
// Copy 3 channels (BGR) per pixel
|
||||
memcpy(dst_row, src_row, static_cast<size_t>(mat.w) * 3);
|
||||
}
|
||||
|
||||
// Step 3: Convert the BGR frame to the desired pixel format
|
||||
SwsContext *sws_ctx = sws_getContext(
|
||||
bgr_frame->width,
|
||||
bgr_frame->height,
|
||||
AV_PIX_FMT_BGR24,
|
||||
dst_frame->width,
|
||||
dst_frame->height,
|
||||
pix_fmt,
|
||||
SWS_BILINEAR,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (sws_ctx == nullptr) {
|
||||
spdlog::error("Failed to initialize swscale context.");
|
||||
av_frame_free(&bgr_frame);
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Perform the conversion
|
||||
ret = sws_scale(
|
||||
sws_ctx,
|
||||
bgr_frame->data,
|
||||
bgr_frame->linesize,
|
||||
0,
|
||||
bgr_frame->height,
|
||||
dst_frame->data,
|
||||
dst_frame->linesize
|
||||
);
|
||||
|
||||
// Clean up
|
||||
sws_freeContext(sws_ctx);
|
||||
av_frame_free(&bgr_frame);
|
||||
|
||||
if (ret != dst_frame->height) {
|
||||
spdlog::error("Failed to convert BGR AVFrame to destination pixel format.");
|
||||
av_frame_free(&dst_frame);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dst_frame;
|
||||
}
|
||||
116
src/decoder.cpp
Normal file
116
src/decoder.cpp
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "decoder.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
static enum AVPixelFormat hw_pix_fmt = AV_PIX_FMT_NONE;
|
||||
|
||||
// Callback function to choose the hardware-accelerated pixel format
|
||||
static enum AVPixelFormat get_hw_format(AVCodecContext *_, const enum AVPixelFormat *pix_fmts) {
|
||||
for (const enum AVPixelFormat *p = pix_fmts; *p != AV_PIX_FMT_NONE; p++) {
|
||||
if (*p == hw_pix_fmt) {
|
||||
return *p;
|
||||
}
|
||||
}
|
||||
spdlog::error("Failed to get HW surface format.");
|
||||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
|
||||
int init_decoder(
|
||||
AVHWDeviceType hw_type,
|
||||
AVBufferRef *hw_ctx,
|
||||
std::filesystem::path in_fpath,
|
||||
AVFormatContext **fmt_ctx,
|
||||
AVCodecContext **dec_ctx,
|
||||
int *vstream_idx
|
||||
) {
|
||||
AVFormatContext *ifmt_ctx = NULL;
|
||||
AVCodecContext *codec_ctx = NULL;
|
||||
int ret;
|
||||
|
||||
if ((ret = avformat_open_input(&ifmt_ctx, in_fpath.u8string().c_str(), NULL, NULL)) < 0) {
|
||||
spdlog::error("Could not open input file '{}'", in_fpath.u8string().c_str());
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = avformat_find_stream_info(ifmt_ctx, NULL)) < 0) {
|
||||
spdlog::error("Failed to retrieve input stream information");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Find the first video stream
|
||||
ret = av_find_best_stream(ifmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Could not find video stream in the input file");
|
||||
return ret;
|
||||
}
|
||||
|
||||
int stream_index = ret;
|
||||
AVStream *video_stream = ifmt_ctx->streams[stream_index];
|
||||
|
||||
// Set up the decoder
|
||||
const AVCodec *decoder = avcodec_find_decoder(video_stream->codecpar->codec_id);
|
||||
if (!decoder) {
|
||||
spdlog::error(
|
||||
"Failed to find decoder for codec ID {}",
|
||||
static_cast<int>(video_stream->codecpar->codec_id)
|
||||
);
|
||||
return AVERROR_DECODER_NOT_FOUND;
|
||||
}
|
||||
|
||||
codec_ctx = avcodec_alloc_context3(decoder);
|
||||
if (!codec_ctx) {
|
||||
spdlog::error("Failed to allocate the decoder context");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
// Set hardware device context
|
||||
if (hw_ctx != nullptr) {
|
||||
codec_ctx->hw_device_ctx = av_buffer_ref(hw_ctx);
|
||||
codec_ctx->get_format = get_hw_format;
|
||||
|
||||
// Automatically determine the hardware pixel format
|
||||
for (int i = 0;; i++) {
|
||||
const AVCodecHWConfig *config = avcodec_get_hw_config(decoder, i);
|
||||
if (config == nullptr) {
|
||||
spdlog::error(
|
||||
"Decoder {} does not support device type {}.",
|
||||
decoder->name,
|
||||
av_hwdevice_get_type_name(hw_type)
|
||||
);
|
||||
avcodec_free_context(&codec_ctx);
|
||||
avformat_close_input(&ifmt_ctx);
|
||||
return AVERROR(ENOSYS);
|
||||
}
|
||||
if (config->methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX &&
|
||||
config->device_type == hw_type) {
|
||||
hw_pix_fmt = config->pix_fmt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((ret = avcodec_parameters_to_context(codec_ctx, video_stream->codecpar)) < 0) {
|
||||
spdlog::error("Failed to copy decoder parameters to input decoder context");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Set decoder time base and frame rate
|
||||
codec_ctx->time_base = video_stream->time_base;
|
||||
codec_ctx->pkt_timebase = video_stream->time_base;
|
||||
codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, video_stream, NULL);
|
||||
|
||||
if ((ret = avcodec_open2(codec_ctx, decoder, NULL)) < 0) {
|
||||
spdlog::error("Failed to open decoder for stream #{}", stream_index);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*fmt_ctx = ifmt_ctx;
|
||||
*dec_ctx = codec_ctx;
|
||||
*vstream_idx = stream_index;
|
||||
|
||||
return 0;
|
||||
}
|
||||
295
src/encoder.cpp
Normal file
295
src/encoder.cpp
Normal file
@@ -0,0 +1,295 @@
|
||||
#include "encoder.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "conversions.h"
|
||||
|
||||
static enum AVPixelFormat get_encoder_default_pix_fmt(const AVCodec *encoder) {
|
||||
const enum AVPixelFormat *p = encoder->pix_fmts;
|
||||
if (!p) {
|
||||
spdlog::error("No pixel formats supported by encoder");
|
||||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
return *p;
|
||||
}
|
||||
|
||||
int init_encoder(
|
||||
AVBufferRef *hw_ctx,
|
||||
std::filesystem::path out_fpath,
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVFormatContext **ofmt_ctx,
|
||||
AVCodecContext **enc_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
EncoderConfig *encoder_config,
|
||||
int vstream_idx,
|
||||
int **stream_map
|
||||
) {
|
||||
AVFormatContext *fmt_ctx = NULL;
|
||||
AVCodecContext *codec_ctx = NULL;
|
||||
int stream_index = 0;
|
||||
int ret;
|
||||
|
||||
avformat_alloc_output_context2(&fmt_ctx, NULL, NULL, out_fpath.u8string().c_str());
|
||||
if (!fmt_ctx) {
|
||||
spdlog::error("Could not create output context");
|
||||
return AVERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
const AVCodec *encoder = avcodec_find_encoder(encoder_config->codec);
|
||||
if (!encoder) {
|
||||
spdlog::error(
|
||||
"Required video encoder not found for vcodec {}",
|
||||
avcodec_get_name(encoder_config->codec)
|
||||
);
|
||||
return AVERROR_ENCODER_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Create a new video stream in the output file
|
||||
AVStream *out_stream = avformat_new_stream(fmt_ctx, NULL);
|
||||
if (!out_stream) {
|
||||
spdlog::error("Failed to allocate the output video stream");
|
||||
return AVERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
codec_ctx = avcodec_alloc_context3(encoder);
|
||||
if (!codec_ctx) {
|
||||
spdlog::error("Failed to allocate the encoder context");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
// Set hardware device context
|
||||
if (hw_ctx != nullptr) {
|
||||
codec_ctx->hw_device_ctx = av_buffer_ref(hw_ctx);
|
||||
}
|
||||
|
||||
// Set encoding parameters
|
||||
codec_ctx->height = encoder_config->out_height;
|
||||
codec_ctx->width = encoder_config->out_width;
|
||||
codec_ctx->sample_aspect_ratio = dec_ctx->sample_aspect_ratio;
|
||||
codec_ctx->bit_rate = encoder_config->bit_rate;
|
||||
|
||||
// Set the pixel format
|
||||
if (encoder_config->pix_fmt != AV_PIX_FMT_NONE) {
|
||||
// Use the specified pixel format
|
||||
codec_ctx->pix_fmt = encoder_config->pix_fmt;
|
||||
} else {
|
||||
// Fall back to the default pixel format
|
||||
codec_ctx->pix_fmt = get_encoder_default_pix_fmt(encoder);
|
||||
if (codec_ctx->pix_fmt == AV_PIX_FMT_NONE) {
|
||||
spdlog::error("Could not get the default pixel format for the encoder");
|
||||
return AVERROR(EINVAL);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the output video's time base
|
||||
if (dec_ctx->time_base.num > 0 && dec_ctx->time_base.den > 0) {
|
||||
codec_ctx->time_base = dec_ctx->time_base;
|
||||
} else {
|
||||
codec_ctx->time_base = av_inv_q(av_guess_frame_rate(ifmt_ctx, out_stream, NULL));
|
||||
}
|
||||
|
||||
// Set the output video's frame rate
|
||||
if (dec_ctx->framerate.num > 0 && dec_ctx->framerate.den > 0) {
|
||||
codec_ctx->framerate = dec_ctx->framerate;
|
||||
} else {
|
||||
codec_ctx->framerate = av_guess_frame_rate(ifmt_ctx, out_stream, NULL);
|
||||
}
|
||||
|
||||
// Set the CRF and preset for any codecs that support it
|
||||
std::string crf_str = std::to_string(encoder_config->crf);
|
||||
av_opt_set(codec_ctx->priv_data, "crf", crf_str.c_str(), 0);
|
||||
av_opt_set(codec_ctx->priv_data, "preset", encoder_config->preset, 0);
|
||||
|
||||
if (fmt_ctx->oformat->flags & AVFMT_GLOBALHEADER) {
|
||||
codec_ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
|
||||
}
|
||||
|
||||
if ((ret = avcodec_open2(codec_ctx, encoder, NULL)) < 0) {
|
||||
spdlog::error("Cannot open video encoder");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = avcodec_parameters_from_context(out_stream->codecpar, codec_ctx);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Failed to copy encoder parameters to output video stream");
|
||||
return ret;
|
||||
}
|
||||
|
||||
out_stream->time_base = codec_ctx->time_base;
|
||||
out_stream->avg_frame_rate = codec_ctx->framerate;
|
||||
out_stream->r_frame_rate = codec_ctx->framerate;
|
||||
|
||||
if (encoder_config->copy_streams) {
|
||||
// Allocate the stream map
|
||||
*stream_map =
|
||||
reinterpret_cast<int *>(av_malloc_array(ifmt_ctx->nb_streams, sizeof(**stream_map)));
|
||||
if (!*stream_map) {
|
||||
spdlog::error("Could not allocate stream mapping");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
// Map the video stream
|
||||
(*stream_map)[vstream_idx] = stream_index++;
|
||||
|
||||
// Loop through each stream in the input file
|
||||
for (int i = 0; i < static_cast<int>(ifmt_ctx->nb_streams); i++) {
|
||||
AVStream *in_stream = ifmt_ctx->streams[i];
|
||||
AVCodecParameters *in_codecpar = in_stream->codecpar;
|
||||
|
||||
if (i == vstream_idx) {
|
||||
// Video stream is already handled
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
|
||||
in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
|
||||
(*stream_map)[i] = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Create corresponding output stream
|
||||
AVStream *out_copied_stream = avformat_new_stream(fmt_ctx, NULL);
|
||||
if (!out_copied_stream) {
|
||||
spdlog::error("Failed allocating output stream");
|
||||
return AVERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
ret = avcodec_parameters_copy(out_copied_stream->codecpar, in_codecpar);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Failed to copy codec parameters");
|
||||
return ret;
|
||||
}
|
||||
out_copied_stream->codecpar->codec_tag = 0;
|
||||
|
||||
// Copy time base
|
||||
out_copied_stream->time_base = in_stream->time_base;
|
||||
|
||||
(*stream_map)[i] = stream_index++;
|
||||
}
|
||||
}
|
||||
|
||||
// Open the output file
|
||||
if (!(fmt_ctx->oformat->flags & AVFMT_NOFILE)) {
|
||||
ret = avio_open(&fmt_ctx->pb, out_fpath.u8string().c_str(), AVIO_FLAG_WRITE);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Could not open output file '{}'", out_fpath.u8string().c_str());
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
*ofmt_ctx = fmt_ctx;
|
||||
*enc_ctx = codec_ctx;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int write_frame(
|
||||
AVFrame *frame,
|
||||
AVCodecContext *enc_ctx,
|
||||
AVFormatContext *ofmt_ctx,
|
||||
int vstream_idx
|
||||
) {
|
||||
AVFrame *converted_frame = nullptr;
|
||||
int ret;
|
||||
|
||||
// Convert the frame to the encoder's pixel format if needed
|
||||
if (frame->format != enc_ctx->pix_fmt) {
|
||||
converted_frame = convert_avframe_pix_fmt(frame, enc_ctx->pix_fmt);
|
||||
if (!converted_frame) {
|
||||
spdlog::error("Error converting frame to encoder's pixel format");
|
||||
return AVERROR_EXTERNAL;
|
||||
}
|
||||
|
||||
converted_frame->pts = frame->pts;
|
||||
}
|
||||
|
||||
AVPacket *enc_pkt = av_packet_alloc();
|
||||
if (!enc_pkt) {
|
||||
spdlog::error("Could not allocate AVPacket");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
if (converted_frame != nullptr) {
|
||||
ret = avcodec_send_frame(enc_ctx, converted_frame);
|
||||
av_frame_free(&converted_frame);
|
||||
} else {
|
||||
ret = avcodec_send_frame(enc_ctx, frame);
|
||||
}
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error sending frame to encoder");
|
||||
av_packet_free(&enc_pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (ret >= 0) {
|
||||
ret = avcodec_receive_packet(enc_ctx, enc_pkt);
|
||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||
av_packet_unref(enc_pkt);
|
||||
break;
|
||||
} else if (ret < 0) {
|
||||
spdlog::error("Error encoding frame");
|
||||
av_packet_free(&enc_pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Rescale packet timestamps
|
||||
av_packet_rescale_ts(
|
||||
enc_pkt, enc_ctx->time_base, ofmt_ctx->streams[vstream_idx]->time_base
|
||||
);
|
||||
enc_pkt->stream_index = vstream_idx;
|
||||
|
||||
// Write the packet
|
||||
ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
|
||||
av_packet_unref(enc_pkt);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error muxing packet");
|
||||
av_packet_free(&enc_pkt);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
av_packet_free(&enc_pkt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int flush_encoder(AVCodecContext *enc_ctx, AVFormatContext *ofmt_ctx) {
|
||||
int ret;
|
||||
AVPacket *enc_pkt = av_packet_alloc();
|
||||
if (!enc_pkt) {
|
||||
spdlog::error("Could not allocate AVPacket");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
ret = avcodec_send_frame(enc_ctx, NULL);
|
||||
while (ret >= 0) {
|
||||
ret = avcodec_receive_packet(enc_ctx, enc_pkt);
|
||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||
av_packet_unref(enc_pkt);
|
||||
break;
|
||||
} else if (ret < 0) {
|
||||
spdlog::error("Error encoding frame");
|
||||
av_packet_free(&enc_pkt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Rescale packet timestamps
|
||||
av_packet_rescale_ts(enc_pkt, enc_ctx->time_base, ofmt_ctx->streams[0]->time_base);
|
||||
enc_pkt->stream_index = ofmt_ctx->streams[0]->index;
|
||||
|
||||
// Write the packet
|
||||
ret = av_interleaved_write_frame(ofmt_ctx, enc_pkt);
|
||||
av_packet_unref(enc_pkt);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error muxing packet");
|
||||
av_packet_free(&enc_pkt);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
av_packet_free(&enc_pkt);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Video2X Exceptions
|
||||
Dev: K4YT3X
|
||||
Date Created: December 13, 2018
|
||||
Last Modified: July 27, 2019
|
||||
"""
|
||||
|
||||
|
||||
class ArgumentError(Exception):
|
||||
def __init__(self, message):
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class StreamNotFoundError(Exception):
|
||||
def __init__(self, message):
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class UnrecognizedDriverError(Exception):
|
||||
def __init__(self, message):
|
||||
super().__init__(message)
|
||||
|
||||
|
||||
class UnsupportedPixelError(Exception):
|
||||
def __init__(self, message):
|
||||
super().__init__(message)
|
||||
287
src/ffmpeg.py
287
src/ffmpeg.py
@@ -1,287 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Video2X FFmpeg Controller
|
||||
Author: K4YT3X
|
||||
Date Created: Feb 24, 2018
|
||||
Last Modified: November 15, 2019
|
||||
|
||||
Description: This class handles all FFmpeg related operations.
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
import json
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
|
||||
|
||||
class Ffmpeg:
|
||||
"""This class communicates with FFmpeg
|
||||
|
||||
This class deals with FFmpeg. It handles extracting
|
||||
frames, stripping audio, converting images into videos
|
||||
and inserting audio tracks to videos.
|
||||
"""
|
||||
|
||||
def __init__(self, ffmpeg_settings, image_format):
|
||||
self.ffmpeg_settings = ffmpeg_settings
|
||||
|
||||
self.ffmpeg_path = pathlib.Path(self.ffmpeg_settings['ffmpeg_path'])
|
||||
self.ffmpeg_binary = self.ffmpeg_path / 'ffmpeg'
|
||||
self.ffmpeg_probe_binary = self.ffmpeg_path / 'ffprobe'
|
||||
self.image_format = image_format
|
||||
self.pixel_format = None
|
||||
|
||||
def get_pixel_formats(self):
|
||||
""" Get a dictionary of supported pixel formats
|
||||
|
||||
List all supported pixel formats and their
|
||||
corresponding bit depth.
|
||||
|
||||
Returns:
|
||||
dictionary -- JSON dict of all pixel formats to bit depth
|
||||
"""
|
||||
execute = [
|
||||
self.ffmpeg_probe_binary,
|
||||
'-v',
|
||||
'quiet',
|
||||
'-pix_fmts'
|
||||
]
|
||||
|
||||
# turn elements into str
|
||||
execute = [str(e) for e in execute]
|
||||
|
||||
Avalon.debug_info(f'Executing: {" ".join(execute)}')
|
||||
|
||||
# initialize dictionary to store pixel formats
|
||||
pixel_formats = {}
|
||||
|
||||
# record all pixel formats into dictionary
|
||||
for line in subprocess.run(execute, check=True, stdout=subprocess.PIPE).stdout.decode().split('\n'):
|
||||
try:
|
||||
pixel_formats[' '.join(line.split()).split()[1]] = int(' '.join(line.split()).split()[3])
|
||||
except (IndexError, ValueError):
|
||||
pass
|
||||
|
||||
# print pixel formats for debugging
|
||||
Avalon.debug_info(str(pixel_formats))
|
||||
|
||||
return pixel_formats
|
||||
|
||||
def get_video_info(self, input_video):
|
||||
""" Gets input video information
|
||||
|
||||
This method reads input video information
|
||||
using ffprobe in dictionary
|
||||
|
||||
Arguments:
|
||||
input_video {string} -- input video file path
|
||||
|
||||
Returns:
|
||||
dictionary -- JSON text of input video information
|
||||
"""
|
||||
|
||||
# this execution command needs to be hard-coded
|
||||
# since video2x only strictly recignizes this one format
|
||||
execute = [
|
||||
self.ffmpeg_probe_binary,
|
||||
'-v',
|
||||
'quiet',
|
||||
'-print_format',
|
||||
'json',
|
||||
'-show_format',
|
||||
'-show_streams',
|
||||
'-i',
|
||||
input_video
|
||||
]
|
||||
|
||||
# turn elements into str
|
||||
execute = [str(e) for e in execute]
|
||||
|
||||
Avalon.debug_info(f'Executing: {" ".join(execute)}')
|
||||
json_str = subprocess.run(execute, check=True, stdout=subprocess.PIPE).stdout
|
||||
return json.loads(json_str.decode('utf-8'))
|
||||
|
||||
def extract_frames(self, input_video, extracted_frames):
|
||||
"""Extract every frame from original videos
|
||||
|
||||
This method extracts every frame from input video using FFmpeg
|
||||
|
||||
Arguments:
|
||||
input_video {string} -- input video path
|
||||
extracted_frames {string} -- video output directory
|
||||
"""
|
||||
execute = [
|
||||
self.ffmpeg_binary
|
||||
]
|
||||
|
||||
execute.extend(self._read_configuration(phase='video_to_frames'))
|
||||
|
||||
execute.extend([
|
||||
'-i',
|
||||
input_video
|
||||
])
|
||||
|
||||
execute.extend(self._read_configuration(phase='video_to_frames', section='output_options'))
|
||||
|
||||
execute.extend([
|
||||
extracted_frames / f'extracted_%0d.{self.image_format}'
|
||||
])
|
||||
|
||||
self._execute(execute)
|
||||
|
||||
def convert_video(self, framerate, resolution, upscaled_frames):
|
||||
"""Converts images into videos
|
||||
|
||||
This method converts a set of images into a video
|
||||
|
||||
Arguments:
|
||||
framerate {float} -- target video framerate
|
||||
resolution {string} -- target video resolution
|
||||
upscaled_frames {string} -- source images directory
|
||||
"""
|
||||
execute = [
|
||||
self.ffmpeg_binary,
|
||||
'-r',
|
||||
str(framerate),
|
||||
'-s',
|
||||
resolution
|
||||
]
|
||||
|
||||
# read other options
|
||||
execute.extend(self._read_configuration(phase='frames_to_video'))
|
||||
|
||||
# read FFmpeg input options
|
||||
execute.extend(self._read_configuration(phase='frames_to_video', section='input_options'))
|
||||
|
||||
# WORKAROUND FOR WAIFU2X-NCNN-VULKAN
|
||||
# Dev: SAT3LL
|
||||
# rename all .png.png suffixes to .png
|
||||
import re
|
||||
regex = re.compile(r'\.png\.png$', re.IGNORECASE)
|
||||
for frame_name in upscaled_frames.iterdir():
|
||||
(upscaled_frames / frame_name).rename(upscaled_frames / regex.sub('.png', str(frame_name)))
|
||||
# END WORKAROUND
|
||||
|
||||
# append input frames path into command
|
||||
execute.extend([
|
||||
'-i',
|
||||
upscaled_frames / f'extracted_%d.{self.image_format}'
|
||||
])
|
||||
|
||||
# read FFmpeg output options
|
||||
execute.extend(self._read_configuration(phase='frames_to_video', section='output_options'))
|
||||
|
||||
# specify output file location
|
||||
execute.extend([
|
||||
upscaled_frames / 'no_audio.mp4'
|
||||
])
|
||||
|
||||
self._execute(execute)
|
||||
|
||||
def migrate_audio_tracks_subtitles(self, input_video, output_video, upscaled_frames):
|
||||
""" Migrates audio tracks and subtitles from input video to output video
|
||||
|
||||
Arguments:
|
||||
input_video {string} -- input video file path
|
||||
output_video {string} -- output video file path
|
||||
upscaled_frames {string} -- directory containing upscaled frames
|
||||
"""
|
||||
execute = [
|
||||
self.ffmpeg_binary
|
||||
]
|
||||
|
||||
execute.extend(self._read_configuration(phase='migrating_tracks'))
|
||||
|
||||
execute.extend([
|
||||
'-i',
|
||||
upscaled_frames / 'no_audio.mp4',
|
||||
'-i',
|
||||
input_video
|
||||
])
|
||||
|
||||
execute.extend(self._read_configuration(phase='migrating_tracks', section='output_options'))
|
||||
|
||||
execute.extend([
|
||||
output_video
|
||||
])
|
||||
|
||||
self._execute(execute)
|
||||
|
||||
def _read_configuration(self, phase, section=None):
|
||||
""" read configuration from JSON
|
||||
|
||||
Read the configurations (arguments) from the JSON
|
||||
configuration file and append them to the end of the
|
||||
FFmpeg command.
|
||||
|
||||
Arguments:
|
||||
execute {list} -- list of arguments to be executed
|
||||
phase {str} -- phase of operation
|
||||
"""
|
||||
|
||||
configuration = []
|
||||
|
||||
# if section is specified, read configurations or keys
|
||||
# from only that section
|
||||
if section:
|
||||
source = self.ffmpeg_settings[phase][section].keys()
|
||||
|
||||
# if pixel format is not specified, use the source pixel format
|
||||
try:
|
||||
if self.ffmpeg_settings[phase][section].get('-pix_fmt') is None:
|
||||
self.ffmpeg_settings[phase][section]['-pix_fmt'] = self.pixel_format
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
source = self.ffmpeg_settings[phase].keys()
|
||||
|
||||
for key in source:
|
||||
|
||||
if section:
|
||||
value = self.ffmpeg_settings[phase][section][key]
|
||||
else:
|
||||
value = self.ffmpeg_settings[phase][key]
|
||||
|
||||
# null or None means that leave this option out (keep default)
|
||||
if value is None or value is False or isinstance(value, dict):
|
||||
continue
|
||||
|
||||
# if the value is a list, append the same argument and all values
|
||||
elif isinstance(value, list):
|
||||
|
||||
for subvalue in value:
|
||||
configuration.append(key)
|
||||
if value is not True:
|
||||
configuration.append(str(subvalue))
|
||||
|
||||
# otherwise the value is typical
|
||||
else:
|
||||
configuration.append(key)
|
||||
|
||||
# true means key is an option
|
||||
if value is True:
|
||||
continue
|
||||
|
||||
configuration.append(str(value))
|
||||
|
||||
return configuration
|
||||
|
||||
def _execute(self, execute):
|
||||
""" execute command
|
||||
|
||||
Arguments:
|
||||
execute {list} -- list of arguments to be executed
|
||||
|
||||
Returns:
|
||||
int -- execution return code
|
||||
"""
|
||||
# turn all list elements into string to avoid errors
|
||||
execute = [str(e) for e in execute]
|
||||
|
||||
Avalon.debug_info(f'Executing: {execute}')
|
||||
|
||||
return subprocess.run(execute, check=True).returncode
|
||||
110
src/fsutils.cpp
Normal file
110
src/fsutils.cpp
Normal file
@@ -0,0 +1,110 @@
|
||||
#include "fsutils.h"
|
||||
|
||||
#if _WIN32
|
||||
#include <windows.h>
|
||||
#include <cwchar>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#if _WIN32
|
||||
static std::filesystem::path get_executable_directory() {
|
||||
std::vector<wchar_t> filepath(MAX_PATH);
|
||||
|
||||
// Get the executable path, expanding the buffer if necessary
|
||||
DWORD size = GetModuleFileNameW(NULL, filepath.data(), static_cast<DWORD>(filepath.size()));
|
||||
if (size == 0) {
|
||||
spdlog::error("Error getting executable path: {}", GetLastError());
|
||||
return std::filesystem::path();
|
||||
}
|
||||
|
||||
// Resize the buffer if necessary
|
||||
while (size >= filepath.size()) {
|
||||
filepath.resize(filepath.size() * 2);
|
||||
size = GetModuleFileNameW(NULL, filepath.data(), static_cast<DWORD>(filepath.size()));
|
||||
if (size == 0) {
|
||||
spdlog::error("Error getting executable path: {}", GetLastError());
|
||||
return std::filesystem::path();
|
||||
}
|
||||
}
|
||||
|
||||
// Create a std::filesystem::path from the filepath and return its parent path
|
||||
std::filesystem::path execpath(filepath.data());
|
||||
return execpath.parent_path();
|
||||
}
|
||||
#else // _WIN32
|
||||
static std::filesystem::path get_executable_directory() {
|
||||
std::error_code ec;
|
||||
std::filesystem::path filepath = std::filesystem::read_symlink("/proc/self/exe", ec);
|
||||
|
||||
if (ec) {
|
||||
spdlog::error("Error reading /proc/self/exe: {}", ec.message());
|
||||
return std::filesystem::path();
|
||||
}
|
||||
|
||||
return filepath.parent_path();
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
bool filepath_is_readable(const std::filesystem::path &path) {
|
||||
#if _WIN32
|
||||
FILE *fp = _wfopen(path.c_str(), L"rb");
|
||||
#else // _WIN32
|
||||
FILE *fp = fopen(path.c_str(), "rb");
|
||||
#endif // _WIN32
|
||||
if (!fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::filesystem::path find_resource_file(const std::filesystem::path &path) {
|
||||
if (filepath_is_readable(path)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
if (filepath_is_readable(std::filesystem::path("/usr/share/video2x/") / path)) {
|
||||
return std::filesystem::path("/usr/share/video2x/") / path;
|
||||
}
|
||||
|
||||
return get_executable_directory() / path;
|
||||
}
|
||||
|
||||
std::string path_to_u8string(const std::filesystem::path &path) {
|
||||
#if _WIN32
|
||||
std::wstring wide_path = path.wstring();
|
||||
int buffer_size =
|
||||
WideCharToMultiByte(CP_UTF8, 0, wide_path.c_str(), -1, nullptr, 0, nullptr, nullptr);
|
||||
if (buffer_size == 0) {
|
||||
return std::string();
|
||||
}
|
||||
std::vector<char> buffer(buffer_size);
|
||||
WideCharToMultiByte(
|
||||
CP_UTF8, 0, wide_path.c_str(), -1, buffer.data(), buffer_size, nullptr, nullptr
|
||||
);
|
||||
return std::string(buffer.data());
|
||||
#else
|
||||
return path.string();
|
||||
#endif
|
||||
}
|
||||
|
||||
StringType path_to_string_type(const std::filesystem::path &path) {
|
||||
#if _WIN32
|
||||
return path.wstring();
|
||||
#else
|
||||
return path.string();
|
||||
#endif
|
||||
}
|
||||
|
||||
StringType to_string_type(int value) {
|
||||
#if _WIN32
|
||||
return std::to_wstring(value);
|
||||
#else
|
||||
return std::to_string(value);
|
||||
#endif
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Video2X Image Cleaner
|
||||
Author: BrianPetkovsek
|
||||
Author: K4YT3X
|
||||
Date Created: March 24, 2019
|
||||
Last Modified: July 27, 2019
|
||||
|
||||
Description: This class is to remove the extracted frames
|
||||
that have already been upscaled.
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
import threading
|
||||
import time
|
||||
|
||||
|
||||
class ImageCleaner(threading.Thread):
|
||||
""" Video2X Image Cleaner
|
||||
|
||||
This class creates an object that keeps track of extracted
|
||||
frames that has already been upscaled and are not needed
|
||||
anymore. It then deletes them to save disk space.
|
||||
|
||||
Extends:
|
||||
threading.Thread
|
||||
"""
|
||||
|
||||
def __init__(self, input_directory, output_directory, threads):
|
||||
threading.Thread.__init__(self)
|
||||
self.input_directory = input_directory
|
||||
self.output_directory = output_directory
|
||||
self.threads = threads
|
||||
self.running = False
|
||||
|
||||
def run(self):
|
||||
""" Run image cleaner
|
||||
"""
|
||||
self.running = True
|
||||
|
||||
while self.running:
|
||||
self.remove_upscaled_frames()
|
||||
time.sleep(1)
|
||||
|
||||
def stop(self):
|
||||
""" Stop the image cleaner
|
||||
"""
|
||||
self.running = False
|
||||
self.join()
|
||||
|
||||
def remove_upscaled_frames(self):
|
||||
""" remove frames that have already been upscaled
|
||||
|
||||
This method compares the files in the extracted frames
|
||||
directory with the upscaled frames directory, and removes
|
||||
the frames that has already been upscaled.
|
||||
"""
|
||||
|
||||
# list all images in the extracted frames
|
||||
output_frames = [f for f in self.output_directory.iterdir() if f.is_file()]
|
||||
|
||||
# compare and remove frames downscaled images that finished being upscaled
|
||||
# within each thread's extracted frames directory
|
||||
for thread_id in range(self.threads):
|
||||
dir_path = self.input_directory / str(thread_id)
|
||||
|
||||
# for each file within all the directories
|
||||
for file in dir_path.iterdir():
|
||||
file_path = dir_path / file
|
||||
|
||||
# if file also exists in the output directory, then the file
|
||||
# has already been processed, thus not needed anymore
|
||||
if file_path.is_file() and file in output_frames:
|
||||
file_path.unlink(file)
|
||||
output_frames.remove(file)
|
||||
161
src/libplacebo.cpp
Normal file
161
src/libplacebo.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include "libplacebo.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/dict.h>
|
||||
#include <libavutil/opt.h>
|
||||
}
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
int init_libplacebo(
|
||||
AVFilterGraph **filter_graph,
|
||||
AVFilterContext **buffersrc_ctx,
|
||||
AVFilterContext **buffersink_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
int out_width,
|
||||
int out_height,
|
||||
uint32_t vk_device_index,
|
||||
const std::filesystem::path &shader_path
|
||||
) {
|
||||
int ret;
|
||||
|
||||
// Create the Vulkan hardware device context
|
||||
AVBufferRef *vk_hw_device_ctx = nullptr;
|
||||
ret = av_hwdevice_ctx_create(
|
||||
&vk_hw_device_ctx, AV_HWDEVICE_TYPE_VULKAN, std::to_string(vk_device_index).c_str(), NULL, 0
|
||||
);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Failed to create Vulkan hardware device context.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
AVFilterGraph *graph = avfilter_graph_alloc();
|
||||
if (!graph) {
|
||||
spdlog::error("Unable to create filter graph.");
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
// Create buffer source
|
||||
const AVFilter *buffersrc = avfilter_get_by_name("buffer");
|
||||
if (!buffersrc) {
|
||||
spdlog::error("Filter 'buffer' not found.");
|
||||
avfilter_graph_free(&graph);
|
||||
return AVERROR_FILTER_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Start building the arguments string
|
||||
std::string args = "video_size=" + std::to_string(dec_ctx->width) + "x" +
|
||||
std::to_string(dec_ctx->height) +
|
||||
":pix_fmt=" + std::to_string(dec_ctx->pix_fmt) +
|
||||
":time_base=" + std::to_string(dec_ctx->time_base.num) + "/" +
|
||||
std::to_string(dec_ctx->time_base.den) +
|
||||
":frame_rate=" + std::to_string(dec_ctx->framerate.num) + "/" +
|
||||
std::to_string(dec_ctx->framerate.den) +
|
||||
":pixel_aspect=" + std::to_string(dec_ctx->sample_aspect_ratio.num) + "/" +
|
||||
std::to_string(dec_ctx->sample_aspect_ratio.den);
|
||||
|
||||
// Make a copy of the AVClass on the stack
|
||||
AVClass priv_class_copy = *buffersrc->priv_class;
|
||||
AVClass *priv_class_copy_ptr = &priv_class_copy;
|
||||
|
||||
// Check if the colorspace option is supported
|
||||
if (av_opt_find(&priv_class_copy_ptr, "colorspace", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)) {
|
||||
args += ":colorspace=" + std::to_string(dec_ctx->colorspace);
|
||||
} else {
|
||||
spdlog::warn("Option 'colorspace' is not supported by the buffer filter.");
|
||||
}
|
||||
|
||||
// Check if the range option is supported
|
||||
if (av_opt_find(&priv_class_copy_ptr, "range", NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)) {
|
||||
args += ":range=" + std::to_string(dec_ctx->color_range);
|
||||
} else {
|
||||
spdlog::warn("Option 'range' is not supported by the buffer filter.");
|
||||
}
|
||||
|
||||
spdlog::debug("Buffer source args: {}", args);
|
||||
ret = avfilter_graph_create_filter(buffersrc_ctx, buffersrc, "in", args.c_str(), NULL, graph);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Cannot create buffer source.");
|
||||
avfilter_graph_free(&graph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
AVFilterContext *last_filter = *buffersrc_ctx;
|
||||
|
||||
// Create the libplacebo filter
|
||||
const AVFilter *libplacebo_filter = avfilter_get_by_name("libplacebo");
|
||||
if (!libplacebo_filter) {
|
||||
spdlog::error("Filter 'libplacebo' not found.");
|
||||
avfilter_graph_free(&graph);
|
||||
return AVERROR_FILTER_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Convert the shader path to a string since filter args is const char *
|
||||
std::string shader_path_string = shader_path.u8string();
|
||||
|
||||
#ifdef _WIN32
|
||||
// libplacebo does not recognize the Windows '\\' path separator
|
||||
std::replace(shader_path_string.begin(), shader_path_string.end(), '\\', '/');
|
||||
#endif
|
||||
|
||||
// Prepare the filter arguments
|
||||
std::string filter_args = "w=" + std::to_string(out_width) +
|
||||
":h=" + std::to_string(out_height) + ":custom_shader_path='" +
|
||||
shader_path_string + "'";
|
||||
|
||||
AVFilterContext *libplacebo_ctx;
|
||||
ret = avfilter_graph_create_filter(
|
||||
&libplacebo_ctx, libplacebo_filter, "libplacebo", filter_args.c_str(), NULL, graph
|
||||
);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Cannot create libplacebo filter.");
|
||||
avfilter_graph_free(&graph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Set the hardware device context to Vulkan
|
||||
libplacebo_ctx->hw_device_ctx = av_buffer_ref(vk_hw_device_ctx);
|
||||
av_buffer_unref(&vk_hw_device_ctx);
|
||||
|
||||
// Link buffersrc to libplacebo
|
||||
ret = avfilter_link(last_filter, 0, libplacebo_ctx, 0);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error connecting buffersrc to libplacebo filter.");
|
||||
avfilter_graph_free(&graph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
last_filter = libplacebo_ctx;
|
||||
|
||||
// Create buffer sink
|
||||
const AVFilter *buffersink = avfilter_get_by_name("buffersink");
|
||||
ret = avfilter_graph_create_filter(buffersink_ctx, buffersink, "out", NULL, NULL, graph);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Cannot create buffer sink.");
|
||||
avfilter_graph_free(&graph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Link libplacebo to buffersink
|
||||
ret = avfilter_link(last_filter, 0, *buffersink_ctx, 0);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error connecting libplacebo filter to buffersink.");
|
||||
avfilter_graph_free(&graph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Configure the filter graph
|
||||
ret = avfilter_graph_config(graph, NULL);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error configuring the filter graph.");
|
||||
avfilter_graph_free(&graph);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*filter_graph = graph;
|
||||
return 0;
|
||||
}
|
||||
148
src/libplacebo_filter.cpp
Normal file
148
src/libplacebo_filter.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
#include "libplacebo_filter.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "char_defs.h"
|
||||
#include "fsutils.h"
|
||||
#include "libplacebo.h"
|
||||
|
||||
LibplaceboFilter::LibplaceboFilter(
|
||||
uint32_t vk_device_index,
|
||||
const std::filesystem::path &shader_path,
|
||||
int out_width,
|
||||
int out_height
|
||||
)
|
||||
: filter_graph(nullptr),
|
||||
buffersrc_ctx(nullptr),
|
||||
buffersink_ctx(nullptr),
|
||||
vk_device_index(vk_device_index),
|
||||
shader_path(std::move(shader_path)),
|
||||
out_width(out_width),
|
||||
out_height(out_height) {}
|
||||
|
||||
LibplaceboFilter::~LibplaceboFilter() {
|
||||
if (buffersrc_ctx) {
|
||||
avfilter_free(buffersrc_ctx);
|
||||
buffersrc_ctx = nullptr;
|
||||
}
|
||||
if (buffersink_ctx) {
|
||||
avfilter_free(buffersink_ctx);
|
||||
buffersink_ctx = nullptr;
|
||||
}
|
||||
if (filter_graph) {
|
||||
avfilter_graph_free(&filter_graph);
|
||||
filter_graph = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int LibplaceboFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *_) {
|
||||
// Construct the shader path
|
||||
std::filesystem::path shader_full_path;
|
||||
if (filepath_is_readable(shader_path)) {
|
||||
// If the shader path is directly readable, use it
|
||||
shader_full_path = shader_path;
|
||||
} else {
|
||||
// Construct the fallback path using std::filesystem
|
||||
shader_full_path = find_resource_file(
|
||||
std::filesystem::path(STR("models")) / STR("libplacebo") /
|
||||
(path_to_string_type(shader_path) + STR(".glsl"))
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the shader file exists
|
||||
if (!std::filesystem::exists(shader_full_path)) {
|
||||
spdlog::error("libplacebo shader file not found: '{}'", shader_path.u8string());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Save the output time base
|
||||
in_time_base = dec_ctx->time_base;
|
||||
out_time_base = enc_ctx->time_base;
|
||||
|
||||
// Initialize the libplacebo filter
|
||||
int ret = init_libplacebo(
|
||||
&filter_graph,
|
||||
&buffersrc_ctx,
|
||||
&buffersink_ctx,
|
||||
dec_ctx,
|
||||
out_width,
|
||||
out_height,
|
||||
vk_device_index,
|
||||
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 ret;
|
||||
|
||||
// Get the filtered frame
|
||||
*out_frame = av_frame_alloc();
|
||||
if (*out_frame == nullptr) {
|
||||
spdlog::error("Failed to allocate output frame");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Feed the frame to the filter graph
|
||||
ret = av_buffersrc_add_frame(buffersrc_ctx, in_frame);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error while feeding the filter graph");
|
||||
av_frame_free(out_frame);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = av_buffersink_get_frame(buffersink_ctx, *out_frame);
|
||||
if (ret < 0) {
|
||||
av_frame_free(out_frame);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Rescale PTS to encoder's time base
|
||||
(*out_frame)->pts = av_rescale_q((*out_frame)->pts, in_time_base, out_time_base);
|
||||
|
||||
// Return the processed frame to the caller
|
||||
return 0;
|
||||
}
|
||||
|
||||
int LibplaceboFilter::flush(std::vector<AVFrame *> &flushed_frames) {
|
||||
int ret = av_buffersrc_add_frame(buffersrc_ctx, nullptr);
|
||||
if (ret < 0) {
|
||||
spdlog::error("Error while flushing filter graph");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Retrieve all remaining frames from the filter graph
|
||||
while (1) {
|
||||
AVFrame *filt_frame = av_frame_alloc();
|
||||
if (filt_frame == nullptr) {
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
|
||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||
av_frame_free(&filt_frame);
|
||||
break;
|
||||
}
|
||||
if (ret < 0) {
|
||||
av_frame_free(&filt_frame);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Rescale PTS to encoder's time base
|
||||
filt_frame->pts = av_rescale_q(filt_frame->pts, in_time_base, out_time_base);
|
||||
|
||||
// Add to processed frames
|
||||
flushed_frames.push_back(filt_frame);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
487
src/libvideo2x.cpp
Normal file
487
src/libvideo2x.cpp
Normal file
@@ -0,0 +1,487 @@
|
||||
#include "libvideo2x.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
|
||||
extern "C" {
|
||||
#include <libavutil/avutil.h>
|
||||
}
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "decoder.h"
|
||||
#include "encoder.h"
|
||||
#include "filter.h"
|
||||
#include "libplacebo_filter.h"
|
||||
#include "realesrgan_filter.h"
|
||||
|
||||
// Process frames using the selected filter.
|
||||
static int process_frames(
|
||||
EncoderConfig *encoder_config,
|
||||
VideoProcessingContext *proc_ctx,
|
||||
AVFormatContext *ifmt_ctx,
|
||||
AVFormatContext *ofmt_ctx,
|
||||
AVCodecContext *dec_ctx,
|
||||
AVCodecContext *enc_ctx,
|
||||
Filter *filter,
|
||||
int vstream_idx,
|
||||
int *stream_map,
|
||||
bool benchmark = false
|
||||
) {
|
||||
int ret;
|
||||
char errbuf[AV_ERROR_MAX_STRING_SIZE];
|
||||
std::vector<AVFrame *> flushed_frames;
|
||||
|
||||
// Get the total number of frames in the video with OpenCV
|
||||
spdlog::debug("Reading total number of frames");
|
||||
proc_ctx->total_frames = ifmt_ctx->streams[vstream_idx]->nb_frames;
|
||||
if (proc_ctx->total_frames > 0) {
|
||||
spdlog::debug("Read total number of frames from 'nb_frames': {}", proc_ctx->total_frames);
|
||||
} else {
|
||||
spdlog::warn("Estimating the total number of frames from duration * fps");
|
||||
|
||||
// Get the duration of the video
|
||||
double duration_secs = 0.0;
|
||||
if (ifmt_ctx->duration != AV_NOPTS_VALUE) {
|
||||
duration_secs =
|
||||
static_cast<double>(ifmt_ctx->duration) / static_cast<double>(AV_TIME_BASE);
|
||||
} else if (ifmt_ctx->streams[vstream_idx]->duration != AV_NOPTS_VALUE) {
|
||||
duration_secs = static_cast<double>(ifmt_ctx->streams[vstream_idx]->duration) *
|
||||
av_q2d(ifmt_ctx->streams[vstream_idx]->time_base);
|
||||
} else {
|
||||
spdlog::warn("Unable to determine video duration");
|
||||
}
|
||||
spdlog::debug("Video duration: {}s", duration_secs);
|
||||
|
||||
// Calculate average FPS
|
||||
double fps = av_q2d(ifmt_ctx->streams[vstream_idx]->avg_frame_rate);
|
||||
if (fps <= 0) {
|
||||
spdlog::debug("Unable to read the average frame rate from 'avg_frame_rate'");
|
||||
fps = av_q2d(ifmt_ctx->streams[vstream_idx]->r_frame_rate);
|
||||
}
|
||||
if (fps <= 0) {
|
||||
spdlog::debug("Unable to read the average frame rate from 'r_frame_rate'");
|
||||
fps = av_q2d(av_guess_frame_rate(ifmt_ctx, ifmt_ctx->streams[vstream_idx], nullptr));
|
||||
}
|
||||
if (fps <= 0) {
|
||||
spdlog::debug("Unable to estimate the average frame rate with 'av_guess_frame_rate'");
|
||||
fps = av_q2d(ifmt_ctx->streams[vstream_idx]->time_base);
|
||||
}
|
||||
if (fps <= 0 || duration_secs <= 0) {
|
||||
spdlog::warn("Unable to estimate the video's average frame rate");
|
||||
} else {
|
||||
// Calculate total frames
|
||||
proc_ctx->total_frames = static_cast<int64_t>(duration_secs * fps);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the total number of frames is still 0
|
||||
if (proc_ctx->total_frames <= 0) {
|
||||
spdlog::warn("Unable to determine the total number of frames");
|
||||
} else {
|
||||
spdlog::debug("{} frames to process", proc_ctx->total_frames);
|
||||
}
|
||||
|
||||
AVFrame *frame = av_frame_alloc();
|
||||
if (frame == nullptr) {
|
||||
ret = AVERROR(ENOMEM);
|
||||
return ret;
|
||||
}
|
||||
|
||||
AVPacket *packet = av_packet_alloc();
|
||||
if (packet == nullptr) {
|
||||
spdlog::critical("Could not allocate AVPacket");
|
||||
av_frame_free(&frame);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
// Lambda function for cleaning up resources
|
||||
auto cleanup = [&]() {
|
||||
av_frame_free(&frame);
|
||||
av_packet_free(&packet);
|
||||
for (AVFrame *&flushed_frame : flushed_frames) {
|
||||
if (flushed_frame) {
|
||||
av_frame_free(&flushed_frame);
|
||||
flushed_frame = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Read frames from the input file
|
||||
while (!proc_ctx->abort) {
|
||||
ret = av_read_frame(ifmt_ctx, packet);
|
||||
if (ret < 0) {
|
||||
if (ret == AVERROR_EOF) {
|
||||
spdlog::debug("Reached end of file");
|
||||
break;
|
||||
}
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error reading packet: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (packet->stream_index == vstream_idx) {
|
||||
ret = avcodec_send_packet(dec_ctx, packet);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error sending packet to decoder: {}", errbuf);
|
||||
av_packet_unref(packet);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (!proc_ctx->abort) {
|
||||
if (proc_ctx->pause) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = avcodec_receive_frame(dec_ctx, frame);
|
||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||
spdlog::debug("Frame not ready");
|
||||
break;
|
||||
} else if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error decoding video frame: {}", errbuf);
|
||||
av_packet_unref(packet);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
AVFrame *processed_frame = nullptr;
|
||||
ret = filter->process_frame(frame, &processed_frame);
|
||||
if (ret < 0 && ret != AVERROR(EAGAIN)) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
av_frame_free(&processed_frame);
|
||||
av_packet_unref(packet);
|
||||
cleanup();
|
||||
return ret;
|
||||
} else if (ret == 0 && processed_frame != nullptr) {
|
||||
if (!benchmark) {
|
||||
ret = write_frame(processed_frame, enc_ctx, ofmt_ctx, vstream_idx);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error encoding/writing frame: {}", errbuf);
|
||||
av_frame_free(&processed_frame);
|
||||
av_packet_unref(packet);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
av_frame_free(&processed_frame);
|
||||
proc_ctx->processed_frames++;
|
||||
}
|
||||
|
||||
av_frame_unref(frame);
|
||||
spdlog::debug(
|
||||
"Processed frame {}/{}", proc_ctx->processed_frames, proc_ctx->total_frames
|
||||
);
|
||||
}
|
||||
} else if (encoder_config->copy_streams && stream_map[packet->stream_index] >= 0) {
|
||||
AVStream *in_stream = ifmt_ctx->streams[packet->stream_index];
|
||||
int out_stream_index = stream_map[packet->stream_index];
|
||||
AVStream *out_stream = ofmt_ctx->streams[out_stream_index];
|
||||
|
||||
av_packet_rescale_ts(packet, in_stream->time_base, out_stream->time_base);
|
||||
packet->stream_index = out_stream_index;
|
||||
|
||||
ret = av_interleaved_write_frame(ofmt_ctx, packet);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::error("Error muxing packet: {}", errbuf);
|
||||
av_packet_unref(packet);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
av_packet_unref(packet);
|
||||
}
|
||||
|
||||
// Flush the filter
|
||||
ret = filter->flush(flushed_frames);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error flushing filter: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Encode and write all flushed frames
|
||||
for (AVFrame *&flushed_frame : flushed_frames) {
|
||||
ret = write_frame(flushed_frame, enc_ctx, ofmt_ctx, vstream_idx);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error encoding/writing flushed frame: {}", errbuf);
|
||||
av_frame_free(&flushed_frame);
|
||||
flushed_frame = nullptr;
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
av_frame_free(&flushed_frame);
|
||||
flushed_frame = nullptr;
|
||||
proc_ctx->processed_frames++;
|
||||
}
|
||||
|
||||
// Flush the encoder
|
||||
ret = flush_encoder(enc_ctx, ofmt_ctx);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error flushing encoder: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" int process_video(
|
||||
const CharType *in_fname,
|
||||
const CharType *out_fname,
|
||||
Libvideo2xLogLevel log_level,
|
||||
bool benchmark,
|
||||
uint32_t vk_device_index,
|
||||
AVHWDeviceType hw_type,
|
||||
const FilterConfig *filter_config,
|
||||
EncoderConfig *encoder_config,
|
||||
VideoProcessingContext *proc_ctx
|
||||
) {
|
||||
AVFormatContext *ifmt_ctx = nullptr;
|
||||
AVFormatContext *ofmt_ctx = nullptr;
|
||||
AVCodecContext *dec_ctx = nullptr;
|
||||
AVCodecContext *enc_ctx = nullptr;
|
||||
AVBufferRef *hw_ctx = nullptr;
|
||||
int *stream_map = nullptr;
|
||||
Filter *filter = nullptr;
|
||||
int vstream_idx = -1;
|
||||
char errbuf[AV_ERROR_MAX_STRING_SIZE];
|
||||
int ret = 0;
|
||||
|
||||
// Lambda function for cleaning up resources
|
||||
auto cleanup = [&]() {
|
||||
if (ifmt_ctx) {
|
||||
avformat_close_input(&ifmt_ctx);
|
||||
ifmt_ctx = nullptr;
|
||||
}
|
||||
if (ofmt_ctx && !(ofmt_ctx->oformat->flags & AVFMT_NOFILE)) {
|
||||
avio_closep(&ofmt_ctx->pb);
|
||||
ofmt_ctx->pb = nullptr;
|
||||
}
|
||||
if (ofmt_ctx) {
|
||||
avformat_free_context(ofmt_ctx);
|
||||
ofmt_ctx = nullptr;
|
||||
}
|
||||
if (dec_ctx) {
|
||||
avcodec_free_context(&dec_ctx);
|
||||
dec_ctx = nullptr;
|
||||
}
|
||||
if (enc_ctx) {
|
||||
avcodec_free_context(&enc_ctx);
|
||||
enc_ctx = nullptr;
|
||||
}
|
||||
if (hw_ctx) {
|
||||
av_buffer_unref(&hw_ctx);
|
||||
hw_ctx = nullptr;
|
||||
}
|
||||
if (stream_map) {
|
||||
av_free(stream_map);
|
||||
stream_map = nullptr;
|
||||
}
|
||||
if (filter) {
|
||||
delete filter;
|
||||
filter = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
// Set the log level for FFmpeg and spdlog (libvideo2x)
|
||||
switch (log_level) {
|
||||
case LIBVIDEO2X_LOG_LEVEL_TRACE:
|
||||
av_log_set_level(AV_LOG_TRACE);
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_DEBUG:
|
||||
av_log_set_level(AV_LOG_DEBUG);
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_INFO:
|
||||
av_log_set_level(AV_LOG_INFO);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_WARNING:
|
||||
av_log_set_level(AV_LOG_WARNING);
|
||||
spdlog::set_level(spdlog::level::warn);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_ERROR:
|
||||
av_log_set_level(AV_LOG_ERROR);
|
||||
spdlog::set_level(spdlog::level::err);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_CRITICAL:
|
||||
av_log_set_level(AV_LOG_FATAL);
|
||||
spdlog::set_level(spdlog::level::critical);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_OFF:
|
||||
av_log_set_level(AV_LOG_QUIET);
|
||||
spdlog::set_level(spdlog::level::off);
|
||||
break;
|
||||
default:
|
||||
av_log_set_level(AV_LOG_INFO);
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert the file names to std::filesystem::path
|
||||
std::filesystem::path in_fpath(in_fname);
|
||||
std::filesystem::path out_fpath(out_fname);
|
||||
|
||||
// Initialize hardware device context
|
||||
if (hw_type != AV_HWDEVICE_TYPE_NONE) {
|
||||
ret = av_hwdevice_ctx_create(&hw_ctx, hw_type, NULL, NULL, 0);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error initializing hardware device context: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize input
|
||||
ret = init_decoder(hw_type, hw_ctx, in_fpath, &ifmt_ctx, &dec_ctx, &vstream_idx);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Failed to initialize decoder: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Initialize output dimensions based on filter configuration
|
||||
int output_width = 0, output_height = 0;
|
||||
switch (filter_config->filter_type) {
|
||||
case FILTER_LIBPLACEBO:
|
||||
output_width = filter_config->config.libplacebo.out_width;
|
||||
output_height = filter_config->config.libplacebo.out_height;
|
||||
break;
|
||||
case FILTER_REALESRGAN:
|
||||
output_width = dec_ctx->width * filter_config->config.realesrgan.scaling_factor;
|
||||
output_height = dec_ctx->height * filter_config->config.realesrgan.scaling_factor;
|
||||
break;
|
||||
default:
|
||||
spdlog::critical("Unknown filter type");
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
spdlog::info("Output video dimensions: {}x{}", output_width, output_height);
|
||||
|
||||
// Initialize output encoder
|
||||
encoder_config->out_width = output_width;
|
||||
encoder_config->out_height = output_height;
|
||||
ret = init_encoder(
|
||||
hw_ctx,
|
||||
out_fpath,
|
||||
ifmt_ctx,
|
||||
&ofmt_ctx,
|
||||
&enc_ctx,
|
||||
dec_ctx,
|
||||
encoder_config,
|
||||
vstream_idx,
|
||||
&stream_map
|
||||
);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Failed to initialize encoder: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Write the output file header
|
||||
ret = avformat_write_header(ofmt_ctx, NULL);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error occurred when opening output file: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Create and initialize the appropriate filter
|
||||
if (filter_config->filter_type == FILTER_LIBPLACEBO) {
|
||||
const auto &config = filter_config->config.libplacebo;
|
||||
if (!config.shader_path) {
|
||||
spdlog::critical("Shader path must be provided for the libplacebo filter");
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
filter = new LibplaceboFilter{
|
||||
vk_device_index,
|
||||
std::filesystem::path(config.shader_path),
|
||||
config.out_width,
|
||||
config.out_height
|
||||
};
|
||||
} else if (filter_config->filter_type == FILTER_REALESRGAN) {
|
||||
const auto &config = filter_config->config.realesrgan;
|
||||
if (!config.model_name) {
|
||||
spdlog::critical("Model name must be provided for the RealESRGAN filter");
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
filter = new RealesrganFilter{
|
||||
static_cast<int>(vk_device_index),
|
||||
config.tta_mode,
|
||||
config.scaling_factor,
|
||||
config.model_name
|
||||
};
|
||||
} else {
|
||||
spdlog::critical("Unknown filter type");
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if the filter instance was created successfully
|
||||
if (filter == nullptr) {
|
||||
spdlog::critical("Failed to create filter instance");
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Initialize the filter
|
||||
ret = filter->init(dec_ctx, enc_ctx, hw_ctx);
|
||||
if (ret < 0) {
|
||||
spdlog::critical("Failed to initialize filter");
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Process frames
|
||||
ret = process_frames(
|
||||
encoder_config,
|
||||
proc_ctx,
|
||||
ifmt_ctx,
|
||||
ofmt_ctx,
|
||||
dec_ctx,
|
||||
enc_ctx,
|
||||
filter,
|
||||
vstream_idx,
|
||||
stream_map,
|
||||
benchmark
|
||||
);
|
||||
if (ret < 0) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error processing frames: {}", errbuf);
|
||||
cleanup();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Write the output file trailer
|
||||
av_write_trailer(ofmt_ctx);
|
||||
|
||||
// Cleanup before returning
|
||||
cleanup();
|
||||
|
||||
if (ret < 0 && ret != AVERROR_EOF) {
|
||||
av_strerror(ret, errbuf, sizeof(errbuf));
|
||||
spdlog::critical("Error occurred: {}", errbuf);
|
||||
return ret;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
121
src/realesrgan_filter.cpp
Normal file
121
src/realesrgan_filter.cpp
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "realesrgan_filter.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "conversions.h"
|
||||
#include "fsutils.h"
|
||||
|
||||
RealesrganFilter::RealesrganFilter(
|
||||
int gpuid,
|
||||
bool tta_mode,
|
||||
int scaling_factor,
|
||||
const StringType model_name
|
||||
)
|
||||
: realesrgan(nullptr),
|
||||
gpuid(gpuid),
|
||||
tta_mode(tta_mode),
|
||||
scaling_factor(scaling_factor),
|
||||
model_name(std::move(model_name)) {}
|
||||
|
||||
RealesrganFilter::~RealesrganFilter() {
|
||||
if (realesrgan) {
|
||||
delete realesrgan;
|
||||
realesrgan = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
int RealesrganFilter::init(AVCodecContext *dec_ctx, AVCodecContext *enc_ctx, AVBufferRef *_) {
|
||||
// Construct the model paths using std::filesystem
|
||||
std::filesystem::path model_param_path;
|
||||
std::filesystem::path model_bin_path;
|
||||
|
||||
StringType param_file_name =
|
||||
model_name + STR("-x") + to_string_type(scaling_factor) + STR(".param");
|
||||
StringType bin_file_name =
|
||||
model_name + STR("-x") + to_string_type(scaling_factor) + STR(".bin");
|
||||
|
||||
// Find the model paths by model name if provided
|
||||
model_param_path = std::filesystem::path(STR("models")) / STR("realesrgan") / param_file_name;
|
||||
model_bin_path = std::filesystem::path(STR("models")) / STR("realesrgan") / bin_file_name;
|
||||
|
||||
// Get the full paths using a function that possibly modifies or validates the path
|
||||
std::filesystem::path model_param_full_path = find_resource_file(model_param_path);
|
||||
std::filesystem::path model_bin_full_path = find_resource_file(model_bin_path);
|
||||
|
||||
// Check if the model files exist
|
||||
if (!std::filesystem::exists(model_param_full_path)) {
|
||||
spdlog::error("RealESRGAN model param file not found: {}", model_param_path.u8string());
|
||||
return -1;
|
||||
}
|
||||
if (!std::filesystem::exists(model_bin_full_path)) {
|
||||
spdlog::error("RealESRGAN model bin file not found: {}", model_bin_path.u8string());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create a new RealESRGAN instance
|
||||
realesrgan = new RealESRGAN(gpuid, tta_mode);
|
||||
|
||||
// Store the time bases
|
||||
in_time_base = dec_ctx->time_base;
|
||||
out_time_base = enc_ctx->time_base;
|
||||
out_pix_fmt = enc_ctx->pix_fmt;
|
||||
|
||||
// Load the model
|
||||
if (realesrgan->load(model_param_full_path, model_bin_full_path) != 0) {
|
||||
spdlog::error("Failed to load RealESRGAN model");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set RealESRGAN parameters
|
||||
realesrgan->scale = scaling_factor;
|
||||
realesrgan->prepadding = 10;
|
||||
|
||||
// Calculate tilesize based on GPU heap budget
|
||||
uint32_t heap_budget = ncnn::get_gpu_device(gpuid)->get_heap_budget();
|
||||
if (heap_budget > 1900) {
|
||||
realesrgan->tilesize = 200;
|
||||
} else if (heap_budget > 550) {
|
||||
realesrgan->tilesize = 100;
|
||||
} else if (heap_budget > 190) {
|
||||
realesrgan->tilesize = 64;
|
||||
} else {
|
||||
realesrgan->tilesize = 32;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RealesrganFilter::process_frame(AVFrame *in_frame, AVFrame **out_frame) {
|
||||
int ret;
|
||||
|
||||
// Convert the input frame to RGB24
|
||||
ncnn::Mat in_mat = avframe_to_ncnn_mat(in_frame);
|
||||
if (in_mat.empty()) {
|
||||
spdlog::error("Failed to convert AVFrame to ncnn::Mat");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Allocate space for ouptut ncnn::Mat
|
||||
int output_width = in_mat.w * realesrgan->scale;
|
||||
int output_height = in_mat.h * realesrgan->scale;
|
||||
ncnn::Mat out_mat = ncnn::Mat(output_width, output_height, static_cast<size_t>(3), 3);
|
||||
|
||||
ret = realesrgan->process(in_mat, out_mat);
|
||||
if (ret != 0) {
|
||||
spdlog::error("RealESRGAN processing failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Convert ncnn::Mat to AVFrame
|
||||
*out_frame = ncnn_mat_to_avframe(out_mat, out_pix_fmt);
|
||||
|
||||
// Rescale PTS to encoder's time base
|
||||
(*out_frame)->pts = av_rescale_q(in_frame->pts, in_time_base, out_time_base);
|
||||
|
||||
// Return the processed frame to the caller
|
||||
return ret;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
avalon_framework
|
||||
colorama
|
||||
GPUtil
|
||||
psutil
|
||||
pyyaml
|
||||
requests
|
||||
tqdm
|
||||
76
src/timer.cpp
Normal file
76
src/timer.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "timer.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
Timer::Timer() : running(false), paused(false), elapsed_time(0) {}
|
||||
|
||||
Timer::~Timer() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void Timer::start() {
|
||||
if (running) {
|
||||
return;
|
||||
}
|
||||
|
||||
running = true;
|
||||
paused = false;
|
||||
elapsed_time = 0;
|
||||
start_time = std::chrono::steady_clock::now();
|
||||
|
||||
timer_thread = std::thread([this]() {
|
||||
while (running) {
|
||||
if (!paused) {
|
||||
update_elapsed_time();
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void Timer::pause() {
|
||||
if (running && !paused) {
|
||||
paused = true;
|
||||
pause_start_time = std::chrono::steady_clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::resume() {
|
||||
if (running && paused) {
|
||||
paused = false;
|
||||
auto pause_end_time = std::chrono::steady_clock::now();
|
||||
auto pause_duration =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(pause_end_time - pause_start_time)
|
||||
.count();
|
||||
start_time += std::chrono::milliseconds(pause_duration);
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::stop() {
|
||||
running = false;
|
||||
if (timer_thread.joinable()) {
|
||||
timer_thread.join();
|
||||
}
|
||||
update_elapsed_time();
|
||||
}
|
||||
|
||||
bool Timer::is_running() const {
|
||||
return running;
|
||||
}
|
||||
|
||||
bool Timer::is_paused() const {
|
||||
return paused;
|
||||
}
|
||||
|
||||
int64_t Timer::get_elapsed_time() const {
|
||||
return elapsed_time;
|
||||
}
|
||||
|
||||
void Timer::update_elapsed_time() {
|
||||
if (running && !paused) {
|
||||
auto current_time = std::chrono::steady_clock::now();
|
||||
elapsed_time =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(current_time - start_time)
|
||||
.count();
|
||||
}
|
||||
}
|
||||
369
src/upscaler.py
369
src/upscaler.py
@@ -1,369 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Video2X Upscaler
|
||||
Author: K4YT3X
|
||||
Date Created: December 10, 2018
|
||||
Last Modified: December 11, 2019
|
||||
|
||||
Dev: SAT3LL
|
||||
|
||||
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
||||
available at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
|
||||
(C) 2018-2019 K4YT3X
|
||||
"""
|
||||
|
||||
# local imports
|
||||
from anime4k import Anime4k
|
||||
from exceptions import *
|
||||
from ffmpeg import Ffmpeg
|
||||
from image_cleaner import ImageCleaner
|
||||
from waifu2x_caffe import Waifu2xCaffe
|
||||
from waifu2x_converter import Waifu2xConverter
|
||||
from waifu2x_ncnn_vulkan import Waifu2xNcnnVulkan
|
||||
|
||||
# built-in imports
|
||||
from fractions import Fraction
|
||||
import contextlib
|
||||
import copy
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import traceback
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
from tqdm import tqdm
|
||||
|
||||
AVAILABLE_DRIVERS = ['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan', 'anime4k']
|
||||
|
||||
|
||||
class Upscaler:
|
||||
""" An instance of this class is a upscaler that will
|
||||
upscale all images in the given directory.
|
||||
|
||||
Raises:
|
||||
Exception -- all exceptions
|
||||
ArgumentError -- if argument is not valid
|
||||
"""
|
||||
|
||||
def __init__(self, input_video, output_video, method, driver_settings, ffmpeg_settings):
|
||||
# mandatory arguments
|
||||
self.input_video = input_video
|
||||
self.output_video = output_video
|
||||
self.method = method
|
||||
self.driver_settings = driver_settings
|
||||
self.ffmpeg_settings = ffmpeg_settings
|
||||
|
||||
# optional arguments
|
||||
self.waifu2x_driver = 'waifu2x_caffe'
|
||||
self.scale_width = None
|
||||
self.scale_height = None
|
||||
self.scale_ratio = None
|
||||
self.model_dir = None
|
||||
self.threads = 5
|
||||
self.video2x_cache_directory = pathlib.Path(tempfile.gettempdir()) / 'video2x'
|
||||
self.image_format = 'png'
|
||||
self.preserve_frames = False
|
||||
|
||||
def create_temp_directories(self):
|
||||
"""create temporary directory
|
||||
"""
|
||||
self.extracted_frames = pathlib.Path(tempfile.mkdtemp(dir=self.video2x_cache_directory))
|
||||
Avalon.debug_info(f'Extracted frames are being saved to: {self.extracted_frames}')
|
||||
self.upscaled_frames = pathlib.Path(tempfile.mkdtemp(dir=self.video2x_cache_directory))
|
||||
Avalon.debug_info(f'Upscaled frames are being saved to: {self.upscaled_frames}')
|
||||
|
||||
def cleanup_temp_directories(self):
|
||||
"""delete temp directories when done
|
||||
"""
|
||||
if not self.preserve_frames:
|
||||
for directory in [self.extracted_frames, self.upscaled_frames, self.video2x_cache_directory]:
|
||||
try:
|
||||
# avalon framework cannot be used if python is shutting down
|
||||
# therefore, plain print is used
|
||||
print(f'Cleaning up cache directory: {directory}')
|
||||
shutil.rmtree(directory)
|
||||
except (OSError, FileNotFoundError):
|
||||
print(f'Unable to delete: {directory}')
|
||||
traceback.print_exc()
|
||||
|
||||
def _check_arguments(self):
|
||||
# check if arguments are valid / all necessary argument
|
||||
# values are specified
|
||||
if not self.input_video:
|
||||
raise ArgumentError('You need to specify the video to process')
|
||||
elif (not self.scale_width or not self.scale_height) and not self.scale_ratio:
|
||||
raise ArgumentError('You must specify output video width and height or upscale factor')
|
||||
elif not self.output_video:
|
||||
raise ArgumentError('You need to specify the output video name')
|
||||
elif not self.method:
|
||||
raise ArgumentError('You need to specify the enlarging processing unit')
|
||||
|
||||
def _progress_bar(self, extracted_frames_directories):
|
||||
""" This method prints a progress bar
|
||||
|
||||
This method prints a progress bar by keeping track
|
||||
of the amount of frames in the input directory
|
||||
and the output directory. This is originally
|
||||
suggested by @ArmandBernard.
|
||||
"""
|
||||
|
||||
# get number of extracted frames
|
||||
self.total_frames = 0
|
||||
for directory in extracted_frames_directories:
|
||||
self.total_frames += len([f for f in directory.iterdir() if str(f)[-4:] == f'.{self.image_format}'])
|
||||
|
||||
with tqdm(total=self.total_frames, ascii=True, desc='Upscaling Progress') as progress_bar:
|
||||
|
||||
# tqdm update method adds the value to the progress
|
||||
# bar instead of setting the value. Therefore, a delta
|
||||
# needs to be calculated.
|
||||
previous_cycle_frames = 0
|
||||
while not self.progress_bar_exit_signal:
|
||||
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
self.total_frames_upscaled = len([f for f in self.upscaled_frames.iterdir() if str(f)[-4:] == f'.{self.image_format}'])
|
||||
delta = self.total_frames_upscaled - previous_cycle_frames
|
||||
previous_cycle_frames = self.total_frames_upscaled
|
||||
|
||||
# if upscaling is finished
|
||||
if self.total_frames_upscaled >= self.total_frames:
|
||||
return
|
||||
|
||||
# adds the delta into the progress bar
|
||||
progress_bar.update(delta)
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
def _upscale_frames(self):
|
||||
""" Upscale video frames with waifu2x-caffe
|
||||
|
||||
This function upscales all the frames extracted
|
||||
by ffmpeg using the waifu2x-caffe binary.
|
||||
|
||||
Arguments:
|
||||
w2 {Waifu2x Object} -- initialized waifu2x object
|
||||
"""
|
||||
|
||||
# progress bar thread exit signal
|
||||
self.progress_bar_exit_signal = False
|
||||
|
||||
# create a container for exceptions in threads
|
||||
# if this thread is not empty, then an exception has occured
|
||||
self.upscaler_exceptions = []
|
||||
|
||||
# initialize waifu2x driver
|
||||
drivers = AVAILABLE_DRIVERS
|
||||
if self.waifu2x_driver not in drivers:
|
||||
raise UnrecognizedDriverError(f'Unrecognized waifu2x driver: {self.waifu2x_driver}')
|
||||
|
||||
# it's easier to do multi-threading with waifu2x_converter
|
||||
# the number of threads can be passed directly to waifu2x_converter
|
||||
if self.waifu2x_driver == 'waifu2x_converter':
|
||||
w2 = Waifu2xConverter(self.driver_settings, self.model_dir)
|
||||
|
||||
progress_bar = threading.Thread(target=self._progress_bar, args=([self.extracted_frames],))
|
||||
progress_bar.start()
|
||||
|
||||
w2.upscale(self.extracted_frames, self.upscaled_frames, self.scale_ratio, self.threads, self.image_format, self.upscaler_exceptions)
|
||||
for image in [f for f in self.upscaled_frames.iterdir() if f.is_file()]:
|
||||
renamed = re.sub(f'_\[.*-.*\]\[x(\d+(\.\d+)?)\]\.{self.image_format}', f'.{self.image_format}', str(image))
|
||||
(self.upscaled_frames / image).rename(self.upscaled_frames / renamed)
|
||||
|
||||
self.progress_bar_exit_signal = True
|
||||
progress_bar.join()
|
||||
return
|
||||
|
||||
# drivers that are to be multi-threaded by video2x
|
||||
else:
|
||||
# create a container for all upscaler threads
|
||||
upscaler_threads = []
|
||||
|
||||
# list all images in the extracted frames
|
||||
frames = [(self.extracted_frames / f) for f in self.extracted_frames.iterdir() if f.is_file]
|
||||
|
||||
# if we have less images than threads,
|
||||
# create only the threads necessary
|
||||
if len(frames) < self.threads:
|
||||
self.threads = len(frames)
|
||||
|
||||
# create a directory for each thread and append directory
|
||||
# name into a list
|
||||
|
||||
thread_pool = []
|
||||
thread_directories = []
|
||||
for thread_id in range(self.threads):
|
||||
thread_directory = self.extracted_frames / str(thread_id)
|
||||
thread_directories.append(thread_directory)
|
||||
|
||||
# delete old directories and create new directories
|
||||
if thread_directory.is_dir():
|
||||
shutil.rmtree(thread_directory)
|
||||
thread_directory.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# append directory path into list
|
||||
thread_pool.append((thread_directory, thread_id))
|
||||
|
||||
# evenly distribute images into each directory
|
||||
# until there is none left in the directory
|
||||
for image in frames:
|
||||
# move image
|
||||
image.rename(thread_pool[0][0] / image.name)
|
||||
# rotate list
|
||||
thread_pool = thread_pool[-1:] + thread_pool[:-1]
|
||||
|
||||
# create threads and start them
|
||||
for thread_info in thread_pool:
|
||||
|
||||
# create a separate w2 instance for each thread
|
||||
if self.waifu2x_driver == 'waifu2x_caffe':
|
||||
w2 = Waifu2xCaffe(copy.deepcopy(self.driver_settings), self.method, self.model_dir, self.bit_depth)
|
||||
if self.scale_ratio:
|
||||
thread = threading.Thread(target=w2.upscale,
|
||||
args=(thread_info[0],
|
||||
self.upscaled_frames,
|
||||
self.scale_ratio,
|
||||
False,
|
||||
False,
|
||||
self.image_format,
|
||||
self.upscaler_exceptions))
|
||||
else:
|
||||
thread = threading.Thread(target=w2.upscale,
|
||||
args=(thread_info[0],
|
||||
self.upscaled_frames,
|
||||
False,
|
||||
self.scale_width,
|
||||
self.scale_height,
|
||||
self.image_format,
|
||||
self.upscaler_exceptions))
|
||||
|
||||
# if the driver being used is waifu2x_ncnn_vulkan
|
||||
elif self.waifu2x_driver == 'waifu2x_ncnn_vulkan':
|
||||
w2 = Waifu2xNcnnVulkan(copy.deepcopy(self.driver_settings))
|
||||
thread = threading.Thread(target=w2.upscale,
|
||||
args=(thread_info[0],
|
||||
self.upscaled_frames,
|
||||
self.scale_ratio,
|
||||
self.upscaler_exceptions))
|
||||
|
||||
# if the driver being used is anime4k
|
||||
elif self.waifu2x_driver == 'anime4k':
|
||||
w2 = Anime4k(copy.deepcopy(self.driver_settings))
|
||||
thread = threading.Thread(target=w2.upscale,
|
||||
args=(thread_info[0],
|
||||
self.upscaled_frames,
|
||||
self.scale_ratio,
|
||||
self.upscaler_exceptions))
|
||||
|
||||
# create thread
|
||||
thread.name = thread_info[1]
|
||||
|
||||
# add threads into the pool
|
||||
upscaler_threads.append(thread)
|
||||
|
||||
# start progress bar in a different thread
|
||||
progress_bar = threading.Thread(target=self._progress_bar, args=(thread_directories,))
|
||||
progress_bar.start()
|
||||
|
||||
# create the clearer and start it
|
||||
Avalon.debug_info('Starting upscaled image cleaner')
|
||||
image_cleaner = ImageCleaner(self.extracted_frames, self.upscaled_frames, len(upscaler_threads))
|
||||
image_cleaner.start()
|
||||
|
||||
# start all threads
|
||||
for thread in upscaler_threads:
|
||||
thread.start()
|
||||
|
||||
# wait for threads to finish
|
||||
for thread in upscaler_threads:
|
||||
thread.join()
|
||||
|
||||
# upscaling done, kill the clearer
|
||||
Avalon.debug_info('Killing upscaled image cleaner')
|
||||
image_cleaner.stop()
|
||||
|
||||
self.progress_bar_exit_signal = True
|
||||
|
||||
if len(self.upscaler_exceptions) != 0:
|
||||
raise(self.upscaler_exceptions[0])
|
||||
|
||||
def run(self):
|
||||
"""Main controller for Video2X
|
||||
|
||||
This function controls the flow of video conversion
|
||||
and handles all necessary functions.
|
||||
"""
|
||||
|
||||
# parse arguments for waifu2x
|
||||
# check argument sanity
|
||||
self._check_arguments()
|
||||
|
||||
# convert paths to absolute paths
|
||||
self.input_video = self.input_video.absolute()
|
||||
self.output_video = self.output_video.absolute()
|
||||
|
||||
# initialize objects for ffmpeg and waifu2x-caffe
|
||||
fm = Ffmpeg(self.ffmpeg_settings, self.image_format)
|
||||
|
||||
# extract frames from video
|
||||
fm.extract_frames(self.input_video, self.extracted_frames)
|
||||
|
||||
Avalon.info('Reading video information')
|
||||
video_info = fm.get_video_info(self.input_video)
|
||||
# analyze original video with ffprobe and retrieve framerate
|
||||
# width, height = info['streams'][0]['width'], info['streams'][0]['height']
|
||||
|
||||
# find index of video stream
|
||||
video_stream_index = None
|
||||
for stream in video_info['streams']:
|
||||
if stream['codec_type'] == 'video':
|
||||
video_stream_index = stream['index']
|
||||
break
|
||||
|
||||
# exit if no video stream found
|
||||
if video_stream_index is None:
|
||||
Avalon.error('Aborting: No video stream found')
|
||||
raise StreamNotFoundError('no video stream found')
|
||||
|
||||
# get average frame rate of video stream
|
||||
framerate = float(Fraction(video_info['streams'][video_stream_index]['avg_frame_rate']))
|
||||
fm.pixel_format = video_info['streams'][video_stream_index]['pix_fmt']
|
||||
|
||||
# get a dict of all pixel formats and corresponding bit depth
|
||||
pixel_formats = fm.get_pixel_formats()
|
||||
|
||||
try:
|
||||
self.bit_depth = pixel_formats[fm.pixel_format]
|
||||
except KeyError:
|
||||
Avalon.error(f'Unsupported pixel format: {fm.pixel_format}')
|
||||
raise UnsupportedPixelError(f'unsupported pixel format {fm.pixel_format}')
|
||||
|
||||
Avalon.info(f'Framerate: {framerate}')
|
||||
|
||||
# width/height will be coded width/height x upscale factor
|
||||
if self.scale_ratio:
|
||||
original_width = video_info['streams'][video_stream_index]['width']
|
||||
original_height = video_info['streams'][video_stream_index]['height']
|
||||
self.scale_width = int(self.scale_ratio * original_width)
|
||||
self.scale_height = int(self.scale_ratio * original_height)
|
||||
|
||||
# upscale images one by one using waifu2x
|
||||
Avalon.info('Starting to upscale extracted images')
|
||||
self._upscale_frames()
|
||||
Avalon.info('Upscaling completed')
|
||||
|
||||
# frames to Video
|
||||
Avalon.info('Converting extracted frames into video')
|
||||
|
||||
# use user defined output size
|
||||
fm.convert_video(framerate, f'{self.scale_width}x{self.scale_height}', self.upscaled_frames)
|
||||
Avalon.info('Conversion completed')
|
||||
|
||||
# migrate audio tracks and subtitles
|
||||
Avalon.info('Migrating audio tracks and subtitles to upscaled video')
|
||||
fm.migrate_audio_tracks_subtitles(self.input_video, self.output_video, self.upscaled_frames)
|
||||
734
src/video2x.cpp
Normal file
734
src/video2x.cpp
Normal file
@@ -0,0 +1,734 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <csignal>
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_set>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#include <conio.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/hwcontext.h>
|
||||
#include <libavutil/pixdesc.h>
|
||||
#include <libavutil/pixfmt.h>
|
||||
|
||||
#include <libvideo2x/libvideo2x.h>
|
||||
#include <libvideo2x/version.h>
|
||||
}
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define BOOST_PROGRAM_OPTIONS_WCHAR_T
|
||||
#define PO_STR_VALUE po::wvalue
|
||||
#else
|
||||
#define PO_STR_VALUE po::value
|
||||
#endif
|
||||
#include <boost/program_options.hpp>
|
||||
namespace po = boost::program_options;
|
||||
|
||||
#include "libvideo2x/char_defs.h"
|
||||
#include "libvideo2x/timer.h"
|
||||
|
||||
// Indicate if a newline needs to be printed before the next output
|
||||
std::atomic<bool> newline_required = false;
|
||||
|
||||
// Mutex for synchronizing access to VideoProcessingContext
|
||||
std::mutex proc_ctx_mutex;
|
||||
|
||||
// Structure to hold parsed arguments
|
||||
struct Arguments {
|
||||
StringType loglevel = STR("info");
|
||||
bool noprogress = false;
|
||||
|
||||
// General options
|
||||
std::filesystem::path in_fname;
|
||||
std::filesystem::path out_fname;
|
||||
StringType filter_type;
|
||||
uint32_t gpuid = 0;
|
||||
StringType hwaccel = STR("none");
|
||||
bool nocopystreams = false;
|
||||
bool benchmark = false;
|
||||
|
||||
// Encoder options
|
||||
StringType codec = STR("libx264");
|
||||
StringType preset = STR("slow");
|
||||
StringType pix_fmt;
|
||||
int64_t bitrate = 0;
|
||||
float crf = 20.0f;
|
||||
|
||||
// libplacebo options
|
||||
std::filesystem::path shader_path;
|
||||
int out_width = 0;
|
||||
int out_height = 0;
|
||||
|
||||
// RealESRGAN options
|
||||
StringType model_name;
|
||||
int scaling_factor = 0;
|
||||
};
|
||||
|
||||
// Set UNIX terminal input to non-blocking mode
|
||||
#ifndef _WIN32
|
||||
void set_nonblocking_input(bool enable) {
|
||||
static struct termios oldt, newt;
|
||||
if (enable) {
|
||||
tcgetattr(STDIN_FILENO, &oldt);
|
||||
newt = oldt;
|
||||
newt.c_lflag &= static_cast<unsigned int>(~(ICANON | ECHO));
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
|
||||
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
|
||||
} else {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
|
||||
fcntl(STDIN_FILENO, F_SETFL, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Convert a wide string to UTF-8 string
|
||||
#ifdef _WIN32
|
||||
std::string wstring_to_utf8(const std::wstring &wstr) {
|
||||
if (wstr.empty()) {
|
||||
return std::string();
|
||||
}
|
||||
int size_needed = WideCharToMultiByte(
|
||||
CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0, nullptr, nullptr
|
||||
);
|
||||
std::string converted_str(size_needed, 0);
|
||||
WideCharToMultiByte(
|
||||
CP_UTF8,
|
||||
0,
|
||||
wstr.data(),
|
||||
static_cast<int>(wstr.size()),
|
||||
&converted_str[0],
|
||||
size_needed,
|
||||
nullptr,
|
||||
nullptr
|
||||
);
|
||||
return converted_str;
|
||||
}
|
||||
#else
|
||||
std::string wstring_to_utf8(const std::string &str) {
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Newline-safe log callback for FFmpeg
|
||||
void newline_safe_ffmpeg_log_callback(void *ptr, int level, const char *fmt, va_list vl) {
|
||||
if (level <= av_log_get_level() && newline_required) {
|
||||
putchar('\n');
|
||||
newline_required = false;
|
||||
}
|
||||
av_log_default_callback(ptr, level, fmt, vl);
|
||||
}
|
||||
|
||||
bool is_valid_realesrgan_model(const StringType &model) {
|
||||
static const std::unordered_set<StringType> valid_realesrgan_models = {
|
||||
STR("realesrgan-plus"), STR("realesrgan-plus-anime"), STR("realesr-animevideov3")
|
||||
};
|
||||
return valid_realesrgan_models.count(model) > 0;
|
||||
}
|
||||
|
||||
enum Libvideo2xLogLevel parse_log_level(const StringType &level_name) {
|
||||
if (level_name == STR("trace")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_TRACE;
|
||||
} else if (level_name == STR("debug")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_DEBUG;
|
||||
} else if (level_name == STR("info")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_INFO;
|
||||
} else if (level_name == STR("warning") || level_name == STR("warn")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_WARNING;
|
||||
} else if (level_name == STR("error")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_ERROR;
|
||||
} else if (level_name == STR("critical")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_CRITICAL;
|
||||
} else if (level_name == STR("off") || level_name == STR("none")) {
|
||||
return LIBVIDEO2X_LOG_LEVEL_OFF;
|
||||
} else {
|
||||
spdlog::warn("Invalid log level specified. Defaulting to 'info'.");
|
||||
return LIBVIDEO2X_LOG_LEVEL_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
int list_gpus() {
|
||||
// Create a Vulkan instance
|
||||
VkInstance instance;
|
||||
VkInstanceCreateInfo create_info{};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
if (vkCreateInstance(&create_info, nullptr, &instance) != VK_SUCCESS) {
|
||||
spdlog::critical("Failed to create Vulkan instance.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enumerate physical devices
|
||||
uint32_t device_count = 0;
|
||||
VkResult result = vkEnumeratePhysicalDevices(instance, &device_count, nullptr);
|
||||
if (result != VK_SUCCESS) {
|
||||
spdlog::critical("Failed to enumerate Vulkan physical devices.");
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if any devices are found
|
||||
if (device_count == 0) {
|
||||
spdlog::critical("No Vulkan physical devices found.");
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get physical device properties
|
||||
std::vector<VkPhysicalDevice> physical_devices(device_count);
|
||||
result = vkEnumeratePhysicalDevices(instance, &device_count, physical_devices.data());
|
||||
if (result != VK_SUCCESS) {
|
||||
spdlog::critical("Failed to enumerate Vulkan physical devices.");
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// List GPU information
|
||||
for (uint32_t i = 0; i < device_count; i++) {
|
||||
VkPhysicalDevice device = physical_devices[i];
|
||||
VkPhysicalDeviceProperties device_properties;
|
||||
vkGetPhysicalDeviceProperties(device, &device_properties);
|
||||
|
||||
// Print GPU ID and name
|
||||
std::cout << i << ". " << device_properties.deviceName << std::endl;
|
||||
std::cout << "\tType: ";
|
||||
switch (device_properties.deviceType) {
|
||||
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
|
||||
std::cout << "Integrated GPU";
|
||||
break;
|
||||
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
|
||||
std::cout << "Discrete GPU";
|
||||
break;
|
||||
case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
|
||||
std::cout << "Virtual GPU";
|
||||
break;
|
||||
case VK_PHYSICAL_DEVICE_TYPE_CPU:
|
||||
std::cout << "CPU";
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unknown";
|
||||
break;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
// Print Vulkan API version
|
||||
std::cout << "\tVulkan API Version: " << VK_VERSION_MAJOR(device_properties.apiVersion)
|
||||
<< "." << VK_VERSION_MINOR(device_properties.apiVersion) << "."
|
||||
<< VK_VERSION_PATCH(device_properties.apiVersion) << std::endl;
|
||||
|
||||
// Print driver version
|
||||
std::cout << "\tDriver Version: " << VK_VERSION_MAJOR(device_properties.driverVersion)
|
||||
<< "." << VK_VERSION_MINOR(device_properties.driverVersion) << "."
|
||||
<< VK_VERSION_PATCH(device_properties.driverVersion) << std::endl;
|
||||
}
|
||||
|
||||
// Clean up Vulkan instance
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_valid_gpu_id(uint32_t gpu_id) {
|
||||
// Create a Vulkan instance
|
||||
VkInstance instance;
|
||||
VkInstanceCreateInfo create_info{};
|
||||
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
if (vkCreateInstance(&create_info, nullptr, &instance) != VK_SUCCESS) {
|
||||
spdlog::error("Failed to create Vulkan instance.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Enumerate physical devices
|
||||
uint32_t device_count = 0;
|
||||
VkResult result = vkEnumeratePhysicalDevices(instance, &device_count, nullptr);
|
||||
if (result != VK_SUCCESS) {
|
||||
spdlog::error("Failed to enumerate Vulkan physical devices.");
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Clean up Vulkan instance
|
||||
vkDestroyInstance(instance, nullptr);
|
||||
|
||||
if (gpu_id >= device_count) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Wrapper function for video processing thread
|
||||
void process_video_thread(
|
||||
Arguments *arguments,
|
||||
int *proc_ret,
|
||||
AVHWDeviceType hw_device_type,
|
||||
FilterConfig *filter_config,
|
||||
EncoderConfig *encoder_config,
|
||||
VideoProcessingContext *proc_ctx
|
||||
) {
|
||||
enum Libvideo2xLogLevel log_level = parse_log_level(arguments->loglevel);
|
||||
|
||||
StringType in_fname_string;
|
||||
StringType out_fname_string;
|
||||
|
||||
#ifdef _WIN32
|
||||
in_fname_string = StringType(arguments->in_fname.wstring());
|
||||
out_fname_string = StringType(arguments->out_fname.wstring());
|
||||
#else
|
||||
in_fname_string = StringType(arguments->in_fname.string());
|
||||
out_fname_string = StringType(arguments->out_fname.string());
|
||||
#endif
|
||||
|
||||
const CharType *in_fname = in_fname_string.c_str();
|
||||
const CharType *out_fname = out_fname_string.c_str();
|
||||
|
||||
*proc_ret = process_video(
|
||||
in_fname,
|
||||
out_fname,
|
||||
log_level,
|
||||
arguments->benchmark,
|
||||
arguments->gpuid,
|
||||
hw_device_type,
|
||||
filter_config,
|
||||
encoder_config,
|
||||
proc_ctx
|
||||
);
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
proc_ctx->completed = true;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
int wmain(int argc, wchar_t *argv[]) {
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
#else
|
||||
int main(int argc, char **argv) {
|
||||
#endif
|
||||
// Initialize arguments structure
|
||||
Arguments arguments;
|
||||
|
||||
// Parse command line arguments using Boost.Program_options
|
||||
try {
|
||||
po::options_description desc("Allowed options");
|
||||
|
||||
desc.add_options()
|
||||
("help", "Display this help page")
|
||||
("version,v", "Print program version")
|
||||
("loglevel", PO_STR_VALUE<StringType>(&arguments.loglevel)->default_value(STR("info"), "info"), "Set log level (trace, debug, info, warn, error, critical, none)")
|
||||
("noprogress", po::bool_switch(&arguments.noprogress), "Do not display the progress bar")
|
||||
("listgpus", "List the available GPUs")
|
||||
|
||||
// General Processing Options
|
||||
("input,i", PO_STR_VALUE<StringType>(), "Input video file path")
|
||||
("output,o", PO_STR_VALUE<StringType>(), "Output video file path")
|
||||
("filter,f", PO_STR_VALUE<StringType>(&arguments.filter_type), "Filter to use: 'libplacebo' or 'realesrgan'")
|
||||
("gpuid,g", po::value<uint32_t>(&arguments.gpuid)->default_value(0), "Vulkan GPU ID (default: 0)")
|
||||
("hwaccel,a", PO_STR_VALUE<StringType>(&arguments.hwaccel)->default_value(STR("none"), "none"), "Hardware acceleration method (default: none)")
|
||||
("nocopystreams", po::bool_switch(&arguments.nocopystreams), "Do not copy audio and subtitle streams")
|
||||
("benchmark", po::bool_switch(&arguments.benchmark), "Discard processed frames and calculate average FPS")
|
||||
|
||||
// Encoder options
|
||||
("codec,c", PO_STR_VALUE<StringType>(&arguments.codec)->default_value(STR("libx264"), "libx264"), "Output codec (default: libx264)")
|
||||
("preset,p", PO_STR_VALUE<StringType>(&arguments.preset)->default_value(STR("slow"), "slow"), "Encoder preset (default: slow)")
|
||||
("pixfmt,x", PO_STR_VALUE<StringType>(&arguments.pix_fmt), "Output pixel format (default: auto)")
|
||||
("bitrate,b", po::value<int64_t>(&arguments.bitrate)->default_value(0), "Bitrate in bits per second (default: 0 (VBR))")
|
||||
("crf,q", po::value<float>(&arguments.crf)->default_value(20.0f), "Constant Rate Factor (default: 20.0)")
|
||||
|
||||
// libplacebo options
|
||||
("shader,s", PO_STR_VALUE<StringType>(), "Name or path of the GLSL shader file to use")
|
||||
("width,w", po::value<int>(&arguments.out_width), "Output width")
|
||||
("height,h", po::value<int>(&arguments.out_height), "Output height")
|
||||
|
||||
// RealESRGAN options
|
||||
("model,m", PO_STR_VALUE<StringType>(&arguments.model_name), "Name of the model to use")
|
||||
("scale,r", po::value<int>(&arguments.scaling_factor), "Scaling factor (2, 3, or 4)")
|
||||
;
|
||||
|
||||
// Positional arguments
|
||||
po::positional_options_description p;
|
||||
p.add("input", 1).add("output", 1).add("filter", 1);
|
||||
|
||||
#ifdef _WIN32
|
||||
po::variables_map vm;
|
||||
po::store(po::wcommand_line_parser(argc, argv).options(desc).positional(p).run(), vm);
|
||||
#else
|
||||
po::variables_map vm;
|
||||
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
|
||||
#endif
|
||||
po::notify(vm);
|
||||
|
||||
if (vm.count("help")) {
|
||||
std::cout << desc << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("version")) {
|
||||
std::cout << "Video2X version " << LIBVIDEO2X_VERSION_STRING << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (vm.count("listgpus")) {
|
||||
return list_gpus();
|
||||
}
|
||||
|
||||
// Assign positional arguments
|
||||
if (vm.count("input")) {
|
||||
arguments.in_fname = std::filesystem::path(vm["input"].as<StringType>());
|
||||
} else {
|
||||
spdlog::critical("Input file path is required.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("output")) {
|
||||
arguments.out_fname = std::filesystem::path(vm["output"].as<StringType>());
|
||||
} else if (!arguments.benchmark) {
|
||||
spdlog::critical("Output file path is required.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!vm.count("filter")) {
|
||||
spdlog::critical("Filter type is required (libplacebo or realesrgan).");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (vm.count("shader")) {
|
||||
arguments.shader_path = std::filesystem::path(vm["shader"].as<StringType>());
|
||||
}
|
||||
|
||||
if (vm.count("model")) {
|
||||
if (!is_valid_realesrgan_model(vm["model"].as<StringType>())) {
|
||||
spdlog::critical(
|
||||
"Invalid model specified. Must be 'realesrgan-plus', "
|
||||
"'realesrgan-plus-anime', or 'realesr-animevideov3'."
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} catch (const po::error &e) {
|
||||
spdlog::critical("Error parsing options: {}", e.what());
|
||||
return 1;
|
||||
} catch (const std::exception &e) {
|
||||
spdlog::critical("Unexpected exception caught while parsing options: {}", e.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Additional validations
|
||||
if (arguments.filter_type == STR("libplacebo")) {
|
||||
if (arguments.shader_path.empty() || arguments.out_width == 0 ||
|
||||
arguments.out_height == 0) {
|
||||
spdlog::critical(
|
||||
"For libplacebo, shader name/path (-s), width (-w), "
|
||||
"and height (-h) are required."
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
} else if (arguments.filter_type == STR("realesrgan")) {
|
||||
if (arguments.scaling_factor == 0 || arguments.model_name.empty()) {
|
||||
spdlog::critical("For realesrgan, scaling factor (-r) and model (-m) are required.");
|
||||
return 1;
|
||||
}
|
||||
if (arguments.scaling_factor != 2 && arguments.scaling_factor != 3 &&
|
||||
arguments.scaling_factor != 4) {
|
||||
spdlog::critical("Scaling factor must be 2, 3, or 4.");
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
spdlog::critical("Invalid filter type specified. Must be 'libplacebo' or 'realesrgan'.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate GPU ID
|
||||
int gpu_status = is_valid_gpu_id(arguments.gpuid);
|
||||
if (gpu_status < 0) {
|
||||
spdlog::warn("Unable to validate GPU ID.");
|
||||
} else if (arguments.gpuid > 0 && gpu_status == 0) {
|
||||
spdlog::critical("Invalid GPU ID specified.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate bitrate
|
||||
if (arguments.bitrate < 0) {
|
||||
spdlog::critical("Invalid bitrate specified.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Validate CRF
|
||||
if (arguments.crf < 0.0f || arguments.crf > 51.0f) {
|
||||
spdlog::critical("CRF must be between 0 and 51.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse codec to AVCodec
|
||||
const AVCodec *codec = avcodec_find_encoder_by_name(wstring_to_utf8(arguments.codec).c_str());
|
||||
if (!codec) {
|
||||
spdlog::critical("Codec '{}' not found.", wstring_to_utf8(arguments.codec));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Parse pixel format to AVPixelFormat
|
||||
enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE;
|
||||
if (!arguments.pix_fmt.empty()) {
|
||||
pix_fmt = av_get_pix_fmt(wstring_to_utf8(arguments.pix_fmt).c_str());
|
||||
if (pix_fmt == AV_PIX_FMT_NONE) {
|
||||
spdlog::critical("Invalid pixel format '{}'.", wstring_to_utf8(arguments.pix_fmt));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Set spdlog log level
|
||||
auto log_level = parse_log_level(arguments.loglevel);
|
||||
switch (log_level) {
|
||||
case LIBVIDEO2X_LOG_LEVEL_TRACE:
|
||||
spdlog::set_level(spdlog::level::trace);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_DEBUG:
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_INFO:
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_WARNING:
|
||||
spdlog::set_level(spdlog::level::warn);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_ERROR:
|
||||
spdlog::set_level(spdlog::level::err);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_CRITICAL:
|
||||
spdlog::set_level(spdlog::level::critical);
|
||||
break;
|
||||
case LIBVIDEO2X_LOG_LEVEL_OFF:
|
||||
spdlog::set_level(spdlog::level::off);
|
||||
break;
|
||||
default:
|
||||
spdlog::set_level(spdlog::level::info);
|
||||
break;
|
||||
}
|
||||
|
||||
// Print program version and processing information
|
||||
spdlog::info("Video2X version {}", LIBVIDEO2X_VERSION_STRING);
|
||||
spdlog::info("Processing file: {}", arguments.in_fname.u8string());
|
||||
|
||||
#ifdef _WIN32
|
||||
std::wstring shader_path_str = arguments.shader_path.wstring();
|
||||
#else
|
||||
std::string shader_path_str = arguments.shader_path.string();
|
||||
#endif
|
||||
|
||||
// Setup filter configurations based on the parsed arguments
|
||||
FilterConfig filter_config;
|
||||
if (arguments.filter_type == STR("libplacebo")) {
|
||||
filter_config.filter_type = FILTER_LIBPLACEBO;
|
||||
filter_config.config.libplacebo.out_width = arguments.out_width;
|
||||
filter_config.config.libplacebo.out_height = arguments.out_height;
|
||||
filter_config.config.libplacebo.shader_path = shader_path_str.c_str();
|
||||
} else if (arguments.filter_type == STR("realesrgan")) {
|
||||
filter_config.filter_type = FILTER_REALESRGAN;
|
||||
filter_config.config.realesrgan.tta_mode = false;
|
||||
filter_config.config.realesrgan.scaling_factor = arguments.scaling_factor;
|
||||
filter_config.config.realesrgan.model_name = arguments.model_name.c_str();
|
||||
}
|
||||
|
||||
std::string preset_str = wstring_to_utf8(arguments.preset);
|
||||
|
||||
// Setup encoder configuration
|
||||
EncoderConfig encoder_config;
|
||||
encoder_config.out_width = 0;
|
||||
encoder_config.out_height = 0;
|
||||
encoder_config.copy_streams = !arguments.nocopystreams;
|
||||
encoder_config.codec = codec->id;
|
||||
encoder_config.pix_fmt = pix_fmt;
|
||||
encoder_config.preset = preset_str.c_str();
|
||||
encoder_config.bit_rate = arguments.bitrate;
|
||||
encoder_config.crf = arguments.crf;
|
||||
|
||||
// Parse hardware acceleration method
|
||||
enum AVHWDeviceType hw_device_type = AV_HWDEVICE_TYPE_NONE;
|
||||
if (arguments.hwaccel != STR("none")) {
|
||||
hw_device_type = av_hwdevice_find_type_by_name(wstring_to_utf8(arguments.hwaccel).c_str());
|
||||
if (hw_device_type == AV_HWDEVICE_TYPE_NONE) {
|
||||
spdlog::critical(
|
||||
"Invalid hardware device type '{}'.", wstring_to_utf8(arguments.hwaccel)
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Setup struct to store processing context
|
||||
VideoProcessingContext proc_ctx;
|
||||
proc_ctx.processed_frames = 0;
|
||||
proc_ctx.total_frames = 0;
|
||||
proc_ctx.pause = false;
|
||||
proc_ctx.abort = false;
|
||||
proc_ctx.completed = false;
|
||||
|
||||
// Register a newline-safe log callback for FFmpeg
|
||||
av_log_set_callback(newline_safe_ffmpeg_log_callback);
|
||||
|
||||
// Create a thread for video processing
|
||||
int proc_ret = 0;
|
||||
std::thread processing_thread(
|
||||
process_video_thread,
|
||||
&arguments,
|
||||
&proc_ret,
|
||||
hw_device_type,
|
||||
&filter_config,
|
||||
&encoder_config,
|
||||
&proc_ctx
|
||||
);
|
||||
spdlog::info("Press SPACE to pause/resume, 'q' to abort.");
|
||||
|
||||
// Setup timer
|
||||
Timer timer;
|
||||
timer.start();
|
||||
|
||||
// Enable non-blocking input
|
||||
#ifndef _WIN32
|
||||
set_nonblocking_input(true);
|
||||
#endif
|
||||
|
||||
// Main thread loop to display progress and handle input
|
||||
while (true) {
|
||||
bool completed;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
completed = proc_ctx.completed;
|
||||
}
|
||||
if (completed) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for key presses
|
||||
int ch = -1;
|
||||
|
||||
// Check for key press
|
||||
#ifdef _WIN32
|
||||
if (_kbhit()) {
|
||||
ch = _getch();
|
||||
}
|
||||
#else
|
||||
ch = getchar();
|
||||
#endif
|
||||
|
||||
if (ch == ' ' || ch == '\n') {
|
||||
// Toggle pause state
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
proc_ctx.pause = !proc_ctx.pause;
|
||||
if (proc_ctx.pause) {
|
||||
putchar('\n');
|
||||
spdlog::info("Processing paused. Press SPACE to resume, 'q' to abort.");
|
||||
timer.pause();
|
||||
} else {
|
||||
spdlog::info("Resuming processing...");
|
||||
timer.resume();
|
||||
}
|
||||
}
|
||||
} else if (ch == 'q' || ch == 'Q') {
|
||||
// Abort processing
|
||||
putchar('\n');
|
||||
spdlog::info("Aborting processing...");
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
proc_ctx.abort = true;
|
||||
newline_required = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Display progress
|
||||
if (!arguments.noprogress) {
|
||||
int64_t processed_frames, total_frames;
|
||||
bool pause;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
processed_frames = proc_ctx.processed_frames;
|
||||
total_frames = proc_ctx.total_frames;
|
||||
pause = proc_ctx.pause;
|
||||
}
|
||||
if (!pause && total_frames > 0) {
|
||||
double percentage = total_frames > 0 ? static_cast<double>(processed_frames) *
|
||||
100.0 / static_cast<double>(total_frames)
|
||||
: 0.0;
|
||||
int64_t time_elapsed = timer.get_elapsed_time() / 1000;
|
||||
std::cout << "\rProcessing frame " << processed_frames << "/" << total_frames
|
||||
<< " (" << percentage << "%); time elapsed: " << time_elapsed << "s";
|
||||
std::cout.flush();
|
||||
newline_required = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Sleep for 100ms
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
// Restore terminal to blocking mode
|
||||
#ifndef _WIN32
|
||||
set_nonblocking_input(false);
|
||||
#endif
|
||||
|
||||
// Join the processing thread to ensure it completes before exiting
|
||||
processing_thread.join();
|
||||
|
||||
// Print a newline if progress bar was displayed
|
||||
if (newline_required) {
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
// Print final message based on processing result
|
||||
bool aborted;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
aborted = proc_ctx.abort;
|
||||
}
|
||||
if (aborted) {
|
||||
spdlog::warn("Video processing aborted");
|
||||
return 2;
|
||||
} else if (proc_ret != 0) {
|
||||
spdlog::critical("Video processing failed with error code {}", proc_ret);
|
||||
return 1;
|
||||
} else {
|
||||
spdlog::info("Video processed successfully");
|
||||
}
|
||||
|
||||
// Calculate statistics
|
||||
int64_t processed_frames;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(proc_ctx_mutex);
|
||||
processed_frames = proc_ctx.processed_frames;
|
||||
}
|
||||
int64_t time_elapsed = timer.get_elapsed_time() / 1000;
|
||||
float average_speed_fps = static_cast<float>(processed_frames) /
|
||||
(time_elapsed > 0 ? static_cast<float>(time_elapsed) : 1);
|
||||
|
||||
// Print processing summary
|
||||
printf("====== Video2X %s summary ======\n", arguments.benchmark ? "Benchmark" : "Processing");
|
||||
printf("Video file processed: %s\n", arguments.in_fname.u8string().c_str());
|
||||
printf("Total frames processed: %ld\n", proc_ctx.processed_frames);
|
||||
printf("Total time taken: %ld s\n", time_elapsed);
|
||||
printf("Average processing speed: %.2f FPS\n", average_speed_fps);
|
||||
|
||||
// Print additional information if not in benchmark mode
|
||||
if (!arguments.benchmark) {
|
||||
printf("Output written to: %s\n", arguments.out_fname.u8string().c_str());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
102
src/video2x.json
102
src/video2x.json
@@ -1,102 +0,0 @@
|
||||
{
|
||||
"waifu2x_caffe": {
|
||||
"waifu2x_caffe_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-caffe\\waifu2x-caffe-cui.exe",
|
||||
"input_extention_list": null,
|
||||
"output_extention": null,
|
||||
"mode": "noise_scale",
|
||||
"scale_ratio": null,
|
||||
"scale_width": null,
|
||||
"scale_height": null,
|
||||
"noise_level": 3,
|
||||
"process": "gpu",
|
||||
"crop_size": 128,
|
||||
"output_quality": -1,
|
||||
"output_depth": 8,
|
||||
"batch_size": 1,
|
||||
"gpu": 0,
|
||||
"tta": 0,
|
||||
"input_path": null,
|
||||
"output_path": null,
|
||||
"model_dir": null,
|
||||
"crop_w": null,
|
||||
"crop_h": null
|
||||
},
|
||||
"waifu2x_converter": {
|
||||
"waifu2x_converter_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-converter-cpp",
|
||||
"output-format": null,
|
||||
"png-compression": null,
|
||||
"image-quality": null,
|
||||
"block-size": null,
|
||||
"disable-gpu": null,
|
||||
"force-OpenCL": null,
|
||||
"processor": null,
|
||||
"jobs": null,
|
||||
"model-dir": null,
|
||||
"scale-ratio": null,
|
||||
"noise-level": 3,
|
||||
"mode": "noise-scale",
|
||||
"silent": true,
|
||||
"output": null,
|
||||
"input": null
|
||||
},
|
||||
"waifu2x_ncnn_vulkan": {
|
||||
"waifu2x_ncnn_vulkan_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-ncnn-vulkan\\waifu2x-ncnn-vulkan.exe",
|
||||
"v": null,
|
||||
"i": null,
|
||||
"o": null,
|
||||
"n": 2,
|
||||
"s": 2,
|
||||
"t": 400,
|
||||
"m": "models-cunet",
|
||||
"g": 0,
|
||||
"j": "1:2:2"
|
||||
},
|
||||
"anime4k": {
|
||||
"anime4k_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\anime4k\\Anime4K.jar",
|
||||
"java_path": "C:\\Program Files\\Java\\jdk-12.0.2\\bin\\java.exe"
|
||||
},
|
||||
"ffmpeg": {
|
||||
"ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin",
|
||||
"video_to_frames": {
|
||||
"output_options": {
|
||||
"-qscale:v": null,
|
||||
"-pix_fmt": "rgba64be"
|
||||
},
|
||||
"-hwaccel": "auto",
|
||||
"-y": true
|
||||
},
|
||||
"frames_to_video": {
|
||||
"input_options": {
|
||||
"-qscale:v": null,
|
||||
"-qscale:a": null,
|
||||
"-f": "image2"
|
||||
},
|
||||
"output_options": {
|
||||
"-vcodec": "libx264",
|
||||
"-crf": 17,
|
||||
"-b:v": null,
|
||||
"-pix_fmt": null
|
||||
},
|
||||
"-hwaccel": "auto",
|
||||
"-y": true
|
||||
},
|
||||
"migrating_tracks": {
|
||||
"output_options": {
|
||||
"-map": [
|
||||
"0:v:0?",
|
||||
"1?",
|
||||
"-1:v?"
|
||||
],
|
||||
"-c": "copy",
|
||||
"-pix_fmt": null
|
||||
},
|
||||
"-hwaccel": "auto",
|
||||
"-y": true
|
||||
}
|
||||
},
|
||||
"video2x": {
|
||||
"video2x_cache_directory": null,
|
||||
"image_format": "png",
|
||||
"preserve_frames": false
|
||||
}
|
||||
}
|
||||
446
src/video2x.py
446
src/video2x.py
@@ -1,446 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
r"""
|
||||
|
||||
__ __ _ _ ___ __ __
|
||||
\ \ / / (_) | | |__ \ \ \ / /
|
||||
\ \ / / _ __| | ___ ___ ) | \ V /
|
||||
\ \/ / | | / _` | / _ \ / _ \ / / > <
|
||||
\ / | | | (_| | | __/ | (_) | / /_ / . \
|
||||
\/ |_| \__,_| \___| \___/ |____| /_/ \_\
|
||||
|
||||
|
||||
Name: Video2X Controller
|
||||
Creator: K4YT3X
|
||||
Date Created: Feb 24, 2018
|
||||
Last Modified: January 4, 2020
|
||||
|
||||
Editor: BrianPetkovsek
|
||||
Editor: SAT3LL
|
||||
|
||||
Licensed under the GNU General Public License Version 3 (GNU GPL v3),
|
||||
available at: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
|
||||
(C) 2018 - 2020 K4YT3X
|
||||
|
||||
Video2X is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Video2X is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Description: Video2X is an automation software based on waifu2x image
|
||||
enlarging engine. It extracts frames from a video, enlarge it by a
|
||||
number of times without losing any details or quality, keeping lines
|
||||
smooth and edges sharp.
|
||||
"""
|
||||
|
||||
# local imports
|
||||
from exceptions import *
|
||||
from upscaler import AVAILABLE_DRIVERS
|
||||
from upscaler import Upscaler
|
||||
|
||||
# built-in imports
|
||||
import argparse
|
||||
import contextlib
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import traceback
|
||||
import yaml
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
import GPUtil
|
||||
import psutil
|
||||
|
||||
|
||||
VERSION = '3.0.0'
|
||||
|
||||
LEGAL_INFO = f'''Video2X Version: {VERSION}
|
||||
Author: K4YT3X
|
||||
License: GNU GPL v3
|
||||
Github Page: https://github.com/k4yt3x/video2x
|
||||
Contact: k4yt3x@k4yt3x.com'''
|
||||
|
||||
LOGO = r'''
|
||||
__ __ _ _ ___ __ __
|
||||
\ \ / / (_) | | |__ \ \ \ / /
|
||||
\ \ / / _ __| | ___ ___ ) | \ V /
|
||||
\ \/ / | | / _` | / _ \ / _ \ / / > <
|
||||
\ / | | | (_| | | __/ | (_) | / /_ / . \
|
||||
\/ |_| \__,_| \___| \___/ |____| /_/ \_\
|
||||
'''
|
||||
|
||||
# each thread might take up to 2.5 GB during initialization.
|
||||
# (system memory, not to be confused with GPU memory)
|
||||
SYS_MEM_PER_THREAD = 2.5
|
||||
GPU_MEM_PER_THREAD = 3.5
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Processes CLI arguments
|
||||
|
||||
This function parses all arguments
|
||||
This allows users to customize options
|
||||
for the output video.
|
||||
"""
|
||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
|
||||
# video options
|
||||
file_options = parser.add_argument_group('File Options')
|
||||
file_options.add_argument('-i', '--input', type=pathlib.Path, help='source video file/directory', action='store')
|
||||
file_options.add_argument('-o', '--output', type=pathlib.Path, help='output video file/directory', action='store')
|
||||
|
||||
# upscaler options
|
||||
upscaler_options = parser.add_argument_group('Upscaler Options')
|
||||
upscaler_options.add_argument('-m', '--method', help='upscaling method', action='store', default='gpu', choices=['cpu', 'gpu', 'cudnn'])
|
||||
upscaler_options.add_argument('-d', '--driver', help='upscaling driver', action='store', default='waifu2x_caffe', choices=AVAILABLE_DRIVERS)
|
||||
upscaler_options.add_argument('-y', '--model_dir', type=pathlib.Path, help='directory containing model JSON files', action='store')
|
||||
upscaler_options.add_argument('-t', '--threads', help='number of threads to use for upscaling', action='store', type=int, default=1)
|
||||
upscaler_options.add_argument('-c', '--config', type=pathlib.Path, help='video2x config file location', action='store', default=pathlib.Path(sys.argv[0]).parent.absolute() / 'video2x.yaml')
|
||||
upscaler_options.add_argument('-b', '--batch', help='enable batch mode (select all default values to questions)', action='store_true')
|
||||
|
||||
# scaling options
|
||||
scaling_options = parser.add_argument_group('Scaling Options')
|
||||
scaling_options.add_argument('--width', help='output video width', action='store', type=int)
|
||||
scaling_options.add_argument('--height', help='output video height', action='store', type=int)
|
||||
scaling_options.add_argument('-r', '--ratio', help='scaling ratio', action='store', type=float)
|
||||
|
||||
# extra options
|
||||
extra_options = parser.add_argument_group('Extra Options')
|
||||
extra_options.add_argument('-v', '--version', help='display version, lawful information and exit', action='store_true')
|
||||
|
||||
# parse arguments
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def print_logo():
|
||||
"""print video2x logo"""
|
||||
print(LOGO)
|
||||
print(f'\n{"Video2X Video Enlarger".rjust(40, " ")}')
|
||||
print(f'\n{Avalon.FM.BD}{f"Version {VERSION}".rjust(36, " ")}{Avalon.FM.RST}\n')
|
||||
|
||||
|
||||
def check_memory():
|
||||
""" Check usable system memory
|
||||
Warn the user if insufficient memory is available for
|
||||
the number of threads that the user have chosen.
|
||||
"""
|
||||
|
||||
memory_status = []
|
||||
# get system available memory
|
||||
system_memory_available = psutil.virtual_memory().available / (1024 ** 3)
|
||||
memory_status.append(('system', system_memory_available))
|
||||
|
||||
# check if Nvidia-smi is available
|
||||
# GPUtil requires nvidia-smi.exe to interact with GPU
|
||||
if args.method in ['gpu', 'cudnn']:
|
||||
if not (shutil.which('nvidia-smi') or
|
||||
pathlib.Path(r'C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe').is_file()):
|
||||
# Nvidia System Management Interface not available
|
||||
Avalon.warning('Nvidia-smi not available, skipping available memory check')
|
||||
Avalon.warning('If you experience error \"cudaSuccess out of memory\", try reducing number of threads you\'re using')
|
||||
else:
|
||||
with contextlib.suppress(ValueError):
|
||||
# "0" is GPU ID. Both waifu2x drivers use the first GPU available, therefore only 0 makes sense
|
||||
gpu_memory_available = (GPUtil.getGPUs()[0].memoryTotal - GPUtil.getGPUs()[0].memoryUsed) / 1024
|
||||
memory_status.append(('GPU', gpu_memory_available))
|
||||
|
||||
# go though each checkable memory type and check availability
|
||||
for memory_type, memory_available in memory_status:
|
||||
|
||||
if memory_type == 'system':
|
||||
mem_per_thread = SYS_MEM_PER_THREAD
|
||||
else:
|
||||
mem_per_thread = GPU_MEM_PER_THREAD
|
||||
|
||||
# if user doesn't even have enough memory to run even one thread
|
||||
if memory_available < mem_per_thread:
|
||||
Avalon.warning(f'You might have insufficient amount of {memory_type} memory available to run this program ({memory_available} GB)')
|
||||
Avalon.warning('Proceed with caution')
|
||||
if args.threads > 1:
|
||||
if Avalon.ask('Reduce number of threads to avoid crashing?', default=True, batch=args.batch):
|
||||
args.threads = 1
|
||||
# if memory available is less than needed, warn the user
|
||||
elif memory_available < (mem_per_thread * args.threads):
|
||||
Avalon.warning(f'Each waifu2x-caffe thread will require up to {SYS_MEM_PER_THREAD} GB of system memory')
|
||||
Avalon.warning(f'You demanded {args.threads} threads to be created, but you only have {round(memory_available, 4)} GB {memory_type} memory available')
|
||||
Avalon.warning(f'{mem_per_thread * args.threads} GB of {memory_type} memory is recommended for {args.threads} threads')
|
||||
Avalon.warning(f'With your current amount of {memory_type} memory available, {int(memory_available // mem_per_thread)} threads is recommended')
|
||||
|
||||
# ask the user if he / she wants to change to the recommended
|
||||
# number of threads
|
||||
if Avalon.ask('Change to the recommended value?', default=True, batch=args.batch):
|
||||
args.threads = int(memory_available // mem_per_thread)
|
||||
else:
|
||||
Avalon.warning('Proceed with caution')
|
||||
|
||||
|
||||
def read_config(config_file: pathlib.Path) -> dict:
|
||||
""" read video2x configurations from config file
|
||||
|
||||
Arguments:
|
||||
config_file {pathlib.Path} -- video2x configuration file pathlib.Path
|
||||
|
||||
Returns:
|
||||
dict -- dictionary of video2x configuration
|
||||
"""
|
||||
|
||||
with open(config_file, 'r') as config:
|
||||
return yaml.load(config, Loader=yaml.FullLoader)
|
||||
|
||||
|
||||
def absolutify_paths(config):
|
||||
""" Check to see if paths to binaries are absolute
|
||||
|
||||
This function checks if paths to binary files are absolute.
|
||||
If not, then absolutify the path.
|
||||
|
||||
Arguments:
|
||||
config {dict} -- configuration file dictionary
|
||||
|
||||
Returns:
|
||||
dict -- configuration file dictionary
|
||||
"""
|
||||
current_directory = pathlib.Path(sys.argv[0]).parent.absolute()
|
||||
|
||||
# check waifu2x-caffe path
|
||||
if not re.match('^[a-z]:', config['waifu2x_caffe']['waifu2x_caffe_path'], re.IGNORECASE):
|
||||
config['waifu2x_caffe']['waifu2x_caffe_path'] = current_directory / config['waifu2x_caffe']['waifu2x_caffe_path']
|
||||
|
||||
# check waifu2x-converter-cpp path
|
||||
if not re.match('^[a-z]:', config['waifu2x_converter']['waifu2x_converter_path'], re.IGNORECASE):
|
||||
config['waifu2x_converter']['waifu2x_converter_path'] = current_directory / config['waifu2x_converter']['waifu2x_converter_path']
|
||||
|
||||
# check waifu2x_ncnn_vulkan path
|
||||
if not re.match('^[a-z]:', config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'], re.IGNORECASE):
|
||||
config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path'] = current_directory / config['waifu2x_ncnn_vulkan']['waifu2x_ncnn_vulkan_path']
|
||||
|
||||
# check anime4k path
|
||||
if not re.match('^[a-z]:', config['anime4k']['anime4k_path'], re.IGNORECASE):
|
||||
config['anime4k']['anime4k_path'] = current_directory / config['anime4k']['anime4k_path']
|
||||
|
||||
# check ffmpeg path
|
||||
if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
|
||||
config['ffmpeg']['ffmpeg_path'] = current_directory / config['ffmpeg']['ffmpeg_path']
|
||||
|
||||
# check video2x cache path
|
||||
if config['video2x']['video2x_cache_directory']:
|
||||
if not re.match('^[a-z]:', config['video2x']['video2x_cache_directory'], re.IGNORECASE):
|
||||
config['video2x']['video2x_cache_directory'] = current_directory / config['video2x']['video2x_cache_directory']
|
||||
|
||||
return config
|
||||
|
||||
|
||||
# /////////////////// Execution /////////////////// #
|
||||
|
||||
# this is not a library
|
||||
if __name__ != '__main__':
|
||||
Avalon.error('This file cannot be imported')
|
||||
raise ImportError(f'{__file__} cannot be imported')
|
||||
|
||||
# print video2x logo
|
||||
print_logo()
|
||||
|
||||
# parse command line arguments
|
||||
args = parse_arguments()
|
||||
|
||||
# display version and lawful informaition
|
||||
if args.version:
|
||||
print(LEGAL_INFO)
|
||||
sys.exit(0)
|
||||
|
||||
# arguments sanity check
|
||||
if not args.input:
|
||||
Avalon.error('You must specify input video file/directory path')
|
||||
raise ArgumentError('input video path not specified')
|
||||
if not args.output:
|
||||
Avalon.error('You must specify output video file/directory path')
|
||||
raise ArgumentError('output video path not specified')
|
||||
if (args.driver in ['waifu2x_converter', 'waifu2x_ncnn_vulkan', 'anime4k']) and args.width and args.height:
|
||||
Avalon.error('Selected driver accepts only scaling ratio')
|
||||
raise ArgumentError('selected driver supports only scaling ratio')
|
||||
if args.driver == 'waifu2x_ncnn_vulkan' and args.ratio is not None and (args.ratio > 2 or not args.ratio.is_integer()):
|
||||
Avalon.error('Scaling ratio must be 1 or 2 for waifu2x_ncnn_vulkan')
|
||||
raise ArgumentError('scaling ratio must be 1 or 2 for waifu2x_ncnn_vulkan')
|
||||
if (args.width or args.height) and args.ratio:
|
||||
Avalon.error('You can only specify either scaling ratio or output width and height')
|
||||
raise ArgumentError('both scaling ration and width/height specified')
|
||||
if (args.width and not args.height) or (not args.width and args.height):
|
||||
Avalon.error('You must specify both width and height')
|
||||
raise ArgumentError('only one of width or height is specified')
|
||||
|
||||
# check available memory if driver is waifu2x-based
|
||||
if args.driver in ['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan']:
|
||||
check_memory()
|
||||
|
||||
# anime4k runs significantly faster with more threads
|
||||
if args.driver == 'anime4k' and args.threads <= 1:
|
||||
Avalon.warning('Anime4K runs significantly faster with more threads')
|
||||
if Avalon.ask('Use more threads of Anime4K?', default=True, batch=args.batch):
|
||||
while True:
|
||||
try:
|
||||
threads = Avalon.gets('Amount of threads to use [5]: ', default=5, batch=args.batch)
|
||||
args.threads = int(threads)
|
||||
break
|
||||
except ValueError:
|
||||
if threads == '':
|
||||
args.threads = 5
|
||||
break
|
||||
Avalon.error(f'{threads} is not a valid integer')
|
||||
|
||||
# read configurations from configuration file
|
||||
config = read_config(args.config)
|
||||
|
||||
# config = absolutify_paths(config)
|
||||
|
||||
# load waifu2x configuration
|
||||
driver_settings = config[args.driver]
|
||||
|
||||
# check if driver path exists
|
||||
if not pathlib.Path(driver_settings['path']).is_file():
|
||||
if not pathlib.Path(f'{driver_settings["path"]}.exe').is_file():
|
||||
Avalon.error('Specified driver executable directory doesn\'t exist')
|
||||
Avalon.error('Please check the configuration file settings')
|
||||
raise FileNotFoundError(driver_settings['path'])
|
||||
|
||||
# if the driver is Anime4K, check if JDK 12 is installed
|
||||
if args.driver == 'anime4k':
|
||||
if not pathlib.Path('C:/Program Files/Java/jdk-12.0.2/bin/java.exe').is_file():
|
||||
Avalon.warning('Cannot find JDK 12 at its default installation location')
|
||||
Avalon.warning('Please ensure you have JDK 12 installed and configured')
|
||||
|
||||
# read FFmpeg configuration
|
||||
ffmpeg_settings = config['ffmpeg']
|
||||
|
||||
# load video2x settings
|
||||
image_format = config['video2x']['image_format'].lower()
|
||||
preserve_frames = config['video2x']['preserve_frames']
|
||||
|
||||
# load cache directory
|
||||
if isinstance(config['video2x']['video2x_cache_directory'], str):
|
||||
video2x_cache_directory = pathlib.Path(config['video2x']['video2x_cache_directory'])
|
||||
else:
|
||||
video2x_cache_directory = pathlib.Path(tempfile.gettempdir()) / 'video2x'
|
||||
|
||||
if video2x_cache_directory.exists() and not video2x_cache_directory.is_dir():
|
||||
Avalon.error('Specified cache directory is a file/link')
|
||||
raise FileExistsError('Specified cache directory is a file/link')
|
||||
|
||||
elif not video2x_cache_directory.exists():
|
||||
# if destination file is a file or a symbolic link
|
||||
Avalon.warning(f'Specified cache directory {video2x_cache_directory} does not exist')
|
||||
|
||||
# try creating the cache directory
|
||||
if Avalon.ask('Create directory?', default=True, batch=args.batch):
|
||||
try:
|
||||
video2x_cache_directory.mkdir(parents=True, exist_ok=True)
|
||||
Avalon.info(f'{video2x_cache_directory} created')
|
||||
|
||||
# there can be a number of exceptions here
|
||||
# PermissionError, FileExistsError, etc.
|
||||
# therefore, we put a catch-them-all here
|
||||
except Exception as e:
|
||||
Avalon.error(f'Unable to create {video2x_cache_directory}')
|
||||
Avalon.error('Aborting...')
|
||||
raise e
|
||||
else:
|
||||
raise FileNotFoundError('Could not create cache directory')
|
||||
|
||||
|
||||
# start execution
|
||||
try:
|
||||
# start timer
|
||||
begin_time = time.time()
|
||||
|
||||
# if input specified is a single file
|
||||
if args.input.is_file():
|
||||
|
||||
# upscale single video file
|
||||
Avalon.info(f'Upscaling single video file: {args.input}')
|
||||
|
||||
# check for input output format mismatch
|
||||
if args.output.is_dir():
|
||||
Avalon.error('Input and output path type mismatch')
|
||||
Avalon.error('Input is single file but output is directory')
|
||||
raise Exception('input output path type mismatch')
|
||||
if not re.search(r'.*\..*$', str(args.output)):
|
||||
Avalon.error('No suffix found in output file path')
|
||||
Avalon.error('Suffix must be specified for FFmpeg')
|
||||
raise Exception('No suffix specified')
|
||||
|
||||
upscaler = Upscaler(input_video=args.input, output_video=args.output, method=args.method, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings)
|
||||
|
||||
# set optional options
|
||||
upscaler.waifu2x_driver = args.driver
|
||||
upscaler.scale_width = args.width
|
||||
upscaler.scale_height = args.height
|
||||
upscaler.scale_ratio = args.ratio
|
||||
upscaler.model_dir = args.model_dir
|
||||
upscaler.threads = args.threads
|
||||
upscaler.video2x_cache_directory = video2x_cache_directory
|
||||
upscaler.image_format = image_format
|
||||
upscaler.preserve_frames = preserve_frames
|
||||
|
||||
# run upscaler
|
||||
upscaler.create_temp_directories()
|
||||
upscaler.run()
|
||||
upscaler.cleanup_temp_directories()
|
||||
|
||||
# if input specified is a directory
|
||||
elif args.input.is_dir():
|
||||
# upscale videos in a directory
|
||||
Avalon.info(f'Upscaling videos in directory: {args.input}')
|
||||
|
||||
# make output directory if it doesn't exist
|
||||
args.output.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
for input_video in [f for f in args.input.iterdir() if f.is_file()]:
|
||||
output_video = args.output / input_video.name
|
||||
upscaler = Upscaler(input_video=input_video, output_video=output_video, method=args.method, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings)
|
||||
|
||||
# set optional options
|
||||
upscaler.waifu2x_driver = args.driver
|
||||
upscaler.scale_width = args.width
|
||||
upscaler.scale_height = args.height
|
||||
upscaler.scale_ratio = args.ratio
|
||||
upscaler.model_dir = args.model_dir
|
||||
upscaler.threads = args.threads
|
||||
upscaler.video2x_cache_directory = video2x_cache_directory
|
||||
upscaler.image_format = image_format
|
||||
upscaler.preserve_frames = preserve_frames
|
||||
|
||||
# run upscaler
|
||||
upscaler.create_temp_directories()
|
||||
upscaler.run()
|
||||
upscaler.cleanup_temp_directories()
|
||||
else:
|
||||
Avalon.error('Input path is neither a file nor a directory')
|
||||
raise FileNotFoundError(f'{args.input} is neither file nor directory')
|
||||
|
||||
Avalon.info(f'Program completed, taking {round((time.time() - begin_time), 5)} seconds')
|
||||
|
||||
except Exception:
|
||||
Avalon.error('An exception has occurred')
|
||||
traceback.print_exc()
|
||||
|
||||
# try cleaning up temp directories
|
||||
with contextlib.suppress(Exception):
|
||||
upscaler.cleanup_temp_directories()
|
||||
|
||||
finally:
|
||||
# remove Video2X cache directory
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
if not preserve_frames:
|
||||
shutil.rmtree(video2x_cache_directory)
|
||||
@@ -1,89 +0,0 @@
|
||||
---
|
||||
waifu2x_caffe:
|
||||
path: C:\Users\K4YT3X\AppData\Local\video2x\waifu2x-caffe\waifu2x-caffe-cui
|
||||
input_extention_list:
|
||||
output_extention:
|
||||
mode: noise_scale
|
||||
scale_ratio:
|
||||
scale_width:
|
||||
scale_height:
|
||||
noise_level: 3
|
||||
process: gpu
|
||||
crop_size: 128
|
||||
output_quality: -1
|
||||
output_depth: 8
|
||||
batch_size: 1
|
||||
gpu: 0
|
||||
tta: 0
|
||||
input_path:
|
||||
output_path:
|
||||
model_dir:
|
||||
crop_w:
|
||||
crop_h:
|
||||
waifu2x_converter:
|
||||
path: C:\Users\K4YT3X\AppData\Local\video2x\waifu2x-converter-cpp
|
||||
output-format:
|
||||
png-compression:
|
||||
image-quality:
|
||||
block-size:
|
||||
disable-gpu:
|
||||
force-OpenCL:
|
||||
processor:
|
||||
jobs:
|
||||
model-dir:
|
||||
scale-ratio:
|
||||
noise-level: 3
|
||||
mode: noise-scale
|
||||
silent: true
|
||||
output:
|
||||
input:
|
||||
waifu2x_ncnn_vulkan:
|
||||
path: C:\Users\K4YT3X\AppData\Local\video2x\waifu2x-ncnn-vulkan\waifu2x-ncnn-vulkan
|
||||
v:
|
||||
i:
|
||||
o:
|
||||
n: 2
|
||||
s: 2
|
||||
t: 400
|
||||
m: models-cunet
|
||||
g: 0
|
||||
j: "1:2:2"
|
||||
anime4k:
|
||||
path: C:\Users\K4YT3X\AppData\Local\video2x\anime4k\Anime4K.jar
|
||||
java_path: C:\Program Files\Java\jdk-12.0.2\bin\java.exe
|
||||
ffmpeg:
|
||||
ffmpeg_path: C:\Users\K4YT3X\AppData\Local\video2x\ffmpeg-latest-win64-static\bin
|
||||
video_to_frames:
|
||||
output_options:
|
||||
"-qscale:v":
|
||||
"-pix_fmt": rgba64be
|
||||
"-hwaccel": auto
|
||||
"-y": true
|
||||
frames_to_video:
|
||||
input_options:
|
||||
"-qscale:v":
|
||||
"-qscale:a":
|
||||
"-f": image2
|
||||
output_options:
|
||||
"-vcodec": libx264
|
||||
"-crf": 17
|
||||
"-b:v":
|
||||
"-pix_fmt":
|
||||
"-hwaccel": auto
|
||||
"-y": true
|
||||
migrating_tracks:
|
||||
output_options:
|
||||
"-map":
|
||||
- 0:v?
|
||||
- 1:a?
|
||||
- 1:s?
|
||||
- 1:d?
|
||||
- 1:t?
|
||||
"-c": copy
|
||||
"-pix_fmt":
|
||||
"-hwaccel": auto
|
||||
"-y": true
|
||||
video2x:
|
||||
video2x_cache_directory:
|
||||
image_format: png
|
||||
preserve_frames: false
|
||||
@@ -1,462 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Creator: Video2X GUI
|
||||
Author: K4YT3X
|
||||
Date Created: July 27, 2019
|
||||
Last Modified: December 11, 2019
|
||||
|
||||
Description: A simple GUI for Video2X made with tkinter.
|
||||
"""
|
||||
|
||||
# local imports
|
||||
from exceptions import *
|
||||
from upscaler import Upscaler
|
||||
|
||||
# built-in imports
|
||||
from tkinter import *
|
||||
from tkinter import messagebox
|
||||
from tkinter import ttk
|
||||
from tkinter.filedialog import *
|
||||
import contextlib
|
||||
import pathlib
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import yaml
|
||||
|
||||
VERSION = '1.1.3'
|
||||
|
||||
VIDEO2X_CONFIG = pathlib.Path(sys.argv[0]).parent.absolute() / 'video2x.yaml'
|
||||
|
||||
LEGAL_INFO = f'''Video2X GUI Version: {VERSION}
|
||||
Author: K4YT3X
|
||||
License: GNU GPL v3
|
||||
Github Page: https://github.com/k4yt3x/video2x
|
||||
Contact: k4yt3x@k4yt3x.com'''
|
||||
|
||||
# global static variables
|
||||
AVAILABLE_METHODS = {
|
||||
'GPU': 'gpu',
|
||||
'CUDNN': 'cudnn',
|
||||
'CPU': 'cpu'
|
||||
}
|
||||
|
||||
AVAILABLE_DRIVERS = {
|
||||
'Waifu2X Caffe': 'waifu2x_caffe',
|
||||
'Waifu2X Converter CPP': 'waifu2x_converter',
|
||||
'Waifu2x NCNN Vulkan': 'waifu2x_ncnn_vulkan',
|
||||
'Anime4K': 'anime4k'
|
||||
}
|
||||
|
||||
IMAGE_FORMATS = {'PNG', 'JPG'}
|
||||
|
||||
DEMUXER_EXTENSIONS = {'3dostr', '4xm', 'aa', 'aac', 'ac3', 'acm', 'act',
|
||||
'adf', 'adp', 'ads', 'adx', 'aea', 'afc', 'aiff', 'aix', 'alaw',
|
||||
'alias_pix', 'alsa', 'amr', 'amrnb', 'amrwb', 'anm', 'apc', 'ape',
|
||||
'apng', 'aptx', 'aptx_hd', 'aqtitle', 'asf', 'asf_o', 'ass', 'ast',
|
||||
'au', 'avi', 'avisynth', 'avr', 'avs', 'avs2', 'bethsoftvid', 'bfi',
|
||||
'bfstm', 'bin', 'bink', 'bit', 'bmp_pipe', 'bmv', 'boa', 'brender_pix',
|
||||
'brstm', 'c93', 'caf', 'cavsvideo', 'cdg', 'cdxl', 'cine', 'codec2',
|
||||
'codec2raw', 'concat', 'dash', 'data', 'daud', 'dcstr', 'dds_pipe',
|
||||
'dfa', 'dirac', 'dnxhd', 'dpx_pipe', 'dsf', 'dsicin', 'dss', 'dts',
|
||||
'dtshd', 'dv', 'dvbsub', 'dvbtxt', 'dxa', 'ea', 'ea_cdata', 'eac3',
|
||||
'epaf', 'exr_pipe', 'f32be', 'f32le', 'f64be', 'f64le', 'fbdev',
|
||||
'ffmetadata', 'film_cpk', 'filmstrip', 'fits', 'flac', 'flic', 'flv',
|
||||
'frm', 'fsb', 'g722', 'g723_1', 'g726', 'g726le', 'g729', 'gdv', 'genh',
|
||||
'gif', 'gsm', 'gxf', 'h261', 'h263', 'h264', 'hevc', 'hls', 'applehttp',
|
||||
'hnm', 'ico', 'idcin', 'idf', 'iec61883', 'iff', 'ilbc', 'image2',
|
||||
'image2pipe', 'ingenient', 'ipmovie', 'ircam', 'iss', 'iv8', 'ivf',
|
||||
'ivr', 'j2k_pipe', 'jack', 'jacosub', 'jpeg_pipe', 'jpegls_pipe',
|
||||
'jv', 'kmsgrab', 'lavfi', 'libcdio', 'libdc1394', 'libgme', 'libopenmpt',
|
||||
'live_flv', 'lmlm4', 'loas', 'lrc', 'lvf', 'lxf', 'm4v', 'matroska', 'webm',
|
||||
'mgsts', 'microdvd', 'mjpeg', 'mjpeg_2000', 'mlp', 'mlv', 'mm', 'mmf',
|
||||
'mov', 'mp4', 'm4a', '3gp', '3g2', 'mj2', 'mp3', 'mpc', 'mpc8', 'mpeg',
|
||||
'mpegts', 'mpegtsraw', 'mpegvideo', 'mpjpeg', 'mpl2', 'mpsub', 'msf',
|
||||
'msnwctcp', 'mtaf', 'mtv', 'mulaw', 'musx', 'mv', 'mvi', 'mxf', 'mxg',
|
||||
'nc', 'nistsphere', 'nsp', 'nsv', 'nut', 'nuv', 'ogg', 'oma', 'openal',
|
||||
'oss', 'paf', 'pam_pipe', 'pbm_pipe', 'pcx_pipe', 'pgm_pipe', 'pgmyuv_pipe',
|
||||
'pictor_pipe', 'pjs', 'pmp', 'png_pipe', 'ppm_pipe', 'psd_pipe', 'psxstr',
|
||||
'pulse', 'pva', 'pvf', 'qcp', 'qdraw_pipe', 'r3d', 'rawvideo', 'realtext',
|
||||
'redspark', 'rl2', 'rm', 'roq', 'rpl', 'rsd', 'rso', 'rtp', 'rtsp',
|
||||
's16be', 's16le', 's24be', 's24le', 's32be', 's32le', 's337m', 's8',
|
||||
'sami', 'sap', 'sbc', 'sbg', 'scc', 'sdp', 'sdr2', 'sds', 'sdx', 'ser',
|
||||
'sgi_pipe', 'shn', 'siff', 'sln', 'smjpeg', 'smk', 'smush', 'sndio',
|
||||
'sol', 'sox', 'spdif', 'srt', 'stl', 'subviewer', 'subviewer1', 'sunrast_pipe',
|
||||
'sup', 'svag', 'svg_pipe', 'swf', 'tak', 'tedcaptions', 'thp', 'tiertexseq',
|
||||
'tiff_pipe', 'tmv', 'truehd', 'tta', 'tty', 'txd', 'ty', 'u16be', 'u16le',
|
||||
'u24be', 'u24le', 'u32be', 'u32le', 'u8', 'v210', 'v210x', 'vag', 'vc1',
|
||||
'vc1test', 'vidc', 'video4linux2', 'v4l2', 'vivo', 'vmd', 'vobsub', 'voc',
|
||||
'vpk', 'vplayer', 'vqf', 'w64', 'wav', 'wc3movie', 'webm_dash_manifest',
|
||||
'webp_pipe', 'webvtt', 'wsaud', 'wsd', 'wsvqa', 'wtv', 'wv', 'wve', 'x11grab',
|
||||
'xa', 'xbin', 'xmv', 'xpm_pipe', 'xvag', 'xwd_pipe', 'xwma', 'yop', 'yuv4mpegpipe'}
|
||||
|
||||
|
||||
class Video2xGui():
|
||||
|
||||
def __init__(self):
|
||||
|
||||
self.running = False
|
||||
|
||||
# create main window
|
||||
self.main_window = Tk()
|
||||
self.main_window.title(f'Video2X GUI {VERSION}')
|
||||
self.main_frame = Frame()
|
||||
self.main_frame.pack(fill=BOTH, expand=True)
|
||||
|
||||
# add menu bar
|
||||
self.menu_bar = Menu(self.main_frame)
|
||||
|
||||
# file menu
|
||||
self.file_menu = Menu(self.menu_bar, tearoff=0)
|
||||
self.file_menu.add_command(label='Exit', command=self.main_frame.quit)
|
||||
self.menu_bar.add_cascade(label='File', menu=self.file_menu)
|
||||
|
||||
# help menu
|
||||
self.help_menu = Menu(self.menu_bar, tearoff=0)
|
||||
self.help_menu.add_command(label='About', command=self._display_help)
|
||||
self.menu_bar.add_cascade(label='Help', menu=self.help_menu)
|
||||
|
||||
self.main_window.config(menu=self.menu_bar)
|
||||
|
||||
# file frame
|
||||
self.file_frame = Frame(self.main_frame)
|
||||
self.file_frame.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
|
||||
# input file
|
||||
self.input_file = StringVar()
|
||||
label_text = StringVar()
|
||||
label_text.set('Input File')
|
||||
Label(self.file_frame, textvariable=label_text, relief=RIDGE, width=10).grid(row=0, column=0, padx=5, pady=5, sticky=W)
|
||||
Entry(self.file_frame, textvariable=self.input_file, width=60).grid(row=0, column=1, padx=5, pady=5, sticky=W)
|
||||
Button(self.file_frame, text='Select', command=self._select_input).grid(row=0, column=2, padx=5, pady=5, sticky=W)
|
||||
|
||||
# output file
|
||||
self.output_file = StringVar()
|
||||
label_text = StringVar()
|
||||
label_text.set('Output File')
|
||||
Label(self.file_frame, textvariable=label_text, relief=RIDGE, width=10).grid(row=1, column=0, padx=5, pady=5, sticky=W)
|
||||
Entry(self.file_frame, textvariable=self.output_file, width=60).grid(row=1, column=1, padx=5, pady=5, sticky=W)
|
||||
Button(self.file_frame, text='Select', command=self._select_output).grid(row=1, column=2, padx=5, pady=5, sticky=W)
|
||||
|
||||
# options
|
||||
self.options_frame = Frame()
|
||||
# self.options_left.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
self.options_frame.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
|
||||
self.options_left = Frame(self.options_frame)
|
||||
# self.options_left.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
self.options_left.grid(row=0, column=0, padx=5, pady=5, sticky=N)
|
||||
|
||||
# width
|
||||
self.width = IntVar()
|
||||
# self.width.set(1920)
|
||||
Label(self.options_left, text='Width', relief=RIDGE, width=15).grid(row=0, column=0, padx=2, pady=3)
|
||||
width_field = Entry(self.options_left, textvariable=self.width)
|
||||
width_field.grid(row=0, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# height
|
||||
self.height = IntVar()
|
||||
# self.height.set(1080)
|
||||
Label(self.options_left, text='Height', relief=RIDGE, width=15).grid(row=1, column=0, padx=2, pady=3)
|
||||
height_field = Entry(self.options_left, textvariable=self.height)
|
||||
height_field.grid(row=1, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# scale ratio
|
||||
self.scale_ratio = DoubleVar()
|
||||
# self.scale_ratio.set(2.0)
|
||||
Label(self.options_left, text='Scale Ratio', relief=RIDGE, width=15).grid(row=2, column=0, padx=2, pady=3)
|
||||
scale_ratio_field = Entry(self.options_left, textvariable=self.scale_ratio)
|
||||
scale_ratio_field.grid(row=2, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# image format
|
||||
self.image_format = StringVar(self.options_left)
|
||||
self.image_format.set('PNG')
|
||||
Label(self.options_left, text='Image Format', relief=RIDGE, width=15).grid(row=3, column=0, padx=2, pady=3)
|
||||
image_format_menu = OptionMenu(self.options_left, self.image_format, *IMAGE_FORMATS)
|
||||
image_format_menu.grid(row=3, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# options
|
||||
self.options_right = Frame(self.options_frame)
|
||||
# self.options_left.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
self.options_right.grid(row=0, column=1, padx=5, pady=5, sticky=N)
|
||||
|
||||
# threads
|
||||
self.threads = IntVar()
|
||||
self.threads.set(1)
|
||||
Label(self.options_right, text='Threads', relief=RIDGE, width=15).grid(row=0, column=0, padx=2, pady=3)
|
||||
threads_field = Entry(self.options_right, textvariable=self.threads)
|
||||
threads_field.grid(row=0, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# method
|
||||
self.method = StringVar(self.options_left)
|
||||
self.method.set('GPU')
|
||||
Label(self.options_right, text='Method', relief=RIDGE, width=15).grid(row=1, column=0, padx=2, pady=3)
|
||||
method_menu = OptionMenu(self.options_right, self.method, *AVAILABLE_METHODS)
|
||||
method_menu.grid(row=1, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# driver
|
||||
self.driver = StringVar(self.options_left)
|
||||
self.driver.set('Waifu2X Caffe')
|
||||
Label(self.options_right, text='Driver', relief=RIDGE, width=15).grid(row=2, column=0, padx=2, pady=3)
|
||||
driver_menu = OptionMenu(self.options_right, self.driver, *AVAILABLE_DRIVERS)
|
||||
driver_menu.grid(row=2, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# preserve frames
|
||||
self.preserve_frames = BooleanVar(self.options_left)
|
||||
self.preserve_frames.set(False)
|
||||
Label(self.options_right, text='Preserve Frames', relief=RIDGE, width=15).grid(row=3, column=0, padx=2, pady=3)
|
||||
preserve_frames_menu = OptionMenu(self.options_right, self.preserve_frames, *{True, False})
|
||||
preserve_frames_menu.grid(row=3, column=1, padx=2, pady=3, sticky=W)
|
||||
|
||||
# progress bar
|
||||
self.progress_bar_frame = Frame()
|
||||
self.progress_bar_frame.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
|
||||
self.progress_bar = ttk.Progressbar(self.progress_bar_frame, orient='horizontal', length=100, mode='determinate')
|
||||
self.progress_bar.pack(fill=X)
|
||||
|
||||
# start button frame
|
||||
self.start_frame = Frame()
|
||||
self.start_frame.pack(fill=X, padx=5, pady=5, expand=True)
|
||||
|
||||
# start button
|
||||
self.start_button_text = StringVar()
|
||||
self.start_button_text.set('Start')
|
||||
Button(self.start_frame, textvariable=self.start_button_text, command=self._launch_upscaling, width=20).pack(side=RIGHT)
|
||||
|
||||
self.main_frame.mainloop()
|
||||
|
||||
def _display_help(self):
|
||||
messagebox.showinfo('About', LEGAL_INFO)
|
||||
|
||||
def _launch_upscaling(self):
|
||||
|
||||
# prevent launching multiple instances
|
||||
if self.running:
|
||||
messagebox.showerror('Error', 'Video2X is already running')
|
||||
return
|
||||
|
||||
# arguments sanity check
|
||||
if self.input_file.get() == '':
|
||||
messagebox.showerror('Error', 'You must specify input video file/directory path')
|
||||
return
|
||||
if self.output_file.get() == '':
|
||||
messagebox.showerror('Error', 'You must specify output video file/directory path')
|
||||
return
|
||||
if (self.driver.get() in ['Waifu2X Converter CPP', 'Waifu2x NCNN Vulkan', 'Anime4K']) and self.width.get() and self.height.get():
|
||||
messagebox.showerror('Error', f'Selected driver \"{self.driver.get()}\" accepts only scaling ratio')
|
||||
return
|
||||
if self.driver.get() == 'waifu2x_ncnn_vulkan' and (self.scale_ratio.get() > 2 or not self.scale_ratio.get().is_integer()):
|
||||
messagebox.showerror('Error', 'Scaling ratio must be 1 or 2 for waifu2x_ncnn_vulkan')
|
||||
return
|
||||
if (self.width.get() or self.height.get()) and self.scale_ratio.get():
|
||||
messagebox.showerror('Error', 'You can only specify either scaling ratio or output width and height')
|
||||
return
|
||||
if (self.width.get() and not self.height.get()) or (not self.width.get() and self.height.get()):
|
||||
messagebox.showerror('Error', 'You must specify both width and height')
|
||||
return
|
||||
if (not self.width.get() or not self.height.get()) and not self.scale_ratio.get():
|
||||
messagebox.showerror('Error', 'You must specify either output dimensions or scaling ratio')
|
||||
return
|
||||
|
||||
upscale = threading.Thread(target=self._upscale)
|
||||
upscale.start()
|
||||
self.running = True
|
||||
self.start_button_text.set('Running')
|
||||
|
||||
def _upscale(self):
|
||||
|
||||
try:
|
||||
# start timer
|
||||
begin_time = time.time()
|
||||
|
||||
# read configuration file
|
||||
config = read_config(VIDEO2X_CONFIG)
|
||||
config = absolutify_paths(config)
|
||||
|
||||
input_file = pathlib.Path(self.input_file.get())
|
||||
output_file = pathlib.Path(self.output_file.get())
|
||||
driver = AVAILABLE_DRIVERS[self.driver.get()]
|
||||
|
||||
# load specified driver's config into driver_settings
|
||||
driver_settings = config[driver]
|
||||
|
||||
# if executable doesn't exist, show warning
|
||||
if not pathlib.Path(driver_settings['path']).is_file() and not pathlib.Path(f'{driver_settings["path"]}.exe').is_file():
|
||||
messagebox.showerror('Error', 'Specified driver directory doesn\'t exist\nPlease check the configuration file settings')
|
||||
raise FileNotFoundError(driver_settings['path'])
|
||||
|
||||
# read FFmpeg configuration
|
||||
ffmpeg_settings = config['ffmpeg']
|
||||
|
||||
# load video2x settings
|
||||
image_format = config['video2x']['image_format'].lower()
|
||||
preserve_frames = config['video2x']['preserve_frames']
|
||||
|
||||
# load cache directory
|
||||
if isinstance(config['video2x']['video2x_cache_directory'], str):
|
||||
video2x_cache_directory = pathlib.Path(config['video2x']['video2x_cache_directory'])
|
||||
else:
|
||||
video2x_cache_directory = pathlib.Path(tempfile.gettempdir()) / 'video2x'
|
||||
|
||||
if video2x_cache_directory.exists() and not video2x_cache_directory.is_dir():
|
||||
messagebox.showerror('Error', 'Specified cache directory is a file/link')
|
||||
raise FileExistsError('Specified cache directory is a file/link')
|
||||
|
||||
elif not video2x_cache_directory.exists():
|
||||
# try creating the cache directory
|
||||
if messagebox.askyesno('Question', f'Specified cache directory {video2x_cache_directory} does not exist\nCreate directory?'):
|
||||
try:
|
||||
video2x_cache_directory.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# there can be a number of exceptions here
|
||||
# PermissionError, FileExistsError, etc.
|
||||
# therefore, we put a catch-them-all here
|
||||
except Exception as e:
|
||||
messagebox.showerror('Error', f'Unable to create {video2x_cache_directory}\nAborting...')
|
||||
raise e
|
||||
else:
|
||||
raise FileNotFoundError('Could not create cache directory')
|
||||
|
||||
# load more settings from gui
|
||||
width = self.width.get()
|
||||
height = self.height.get()
|
||||
scale_ratio = self.scale_ratio.get()
|
||||
image_format = self.image_format.get()
|
||||
threads = self.threads.get()
|
||||
method = AVAILABLE_METHODS[self.method.get()]
|
||||
preserve_frames = self.preserve_frames.get()
|
||||
|
||||
self.upscaler = Upscaler(input_video=input_file, output_video=output_file, method=method, driver_settings=driver_settings, ffmpeg_settings=ffmpeg_settings)
|
||||
|
||||
# set optional options
|
||||
self.upscaler.waifu2x_driver = driver
|
||||
self.upscaler.scale_width = width
|
||||
self.upscaler.scale_height = height
|
||||
self.upscaler.scale_ratio = scale_ratio
|
||||
self.upscaler.model_dir = None
|
||||
self.upscaler.threads = threads
|
||||
self.upscaler.video2x_cache_directory = video2x_cache_directory
|
||||
self.upscaler.image_format = image_format
|
||||
self.upscaler.preserve_frames = preserve_frames
|
||||
|
||||
# run upscaler
|
||||
self.upscaler.create_temp_directories()
|
||||
|
||||
# start progress bar
|
||||
progress_bar = threading.Thread(target=self._progress_bar)
|
||||
progress_bar.start()
|
||||
|
||||
# start upscaling
|
||||
self.upscaler.run()
|
||||
self.upscaler.cleanup_temp_directories()
|
||||
|
||||
# show message when upscaling completes
|
||||
messagebox.showinfo('Info', f'Upscaling Completed\nTime Taken: {round((time.time() - begin_time), 5)} seconds')
|
||||
self.progress_bar['value'] = 100
|
||||
self.running = False
|
||||
self.start_button_text.set('Start')
|
||||
|
||||
except Exception as e:
|
||||
messagebox.showerror('Error', f'Upscaler ran into an error:\n{e}')
|
||||
|
||||
# try cleaning up temp directories
|
||||
with contextlib.suppress(Exception):
|
||||
self.upscaler.cleanup_temp_directories()
|
||||
|
||||
|
||||
def _progress_bar(self):
|
||||
""" This method prints a progress bar
|
||||
|
||||
This method prints a progress bar by keeping track
|
||||
of the amount of frames in the input directory
|
||||
and the output directory. This is originally
|
||||
suggested by @ArmandBernard.
|
||||
"""
|
||||
# initialize variables early
|
||||
self.upscaler.progress_bar_exit_signal = False
|
||||
self.upscaler.total_frames_upscaled = 0
|
||||
self.upscaler.total_frames = 1
|
||||
|
||||
# initialize progress bar values
|
||||
self.progress_bar['value'] = 0
|
||||
|
||||
while not self.upscaler.progress_bar_exit_signal:
|
||||
self.progress_bar['value'] = int(100 * self.upscaler.total_frames_upscaled / self.upscaler.total_frames)
|
||||
time.sleep(1)
|
||||
|
||||
def _select_input(self):
|
||||
self.input_file.set(askopenfilename(title='Select Input File'))
|
||||
|
||||
# remove input file extension
|
||||
input_filename = str(self.input_file.get())
|
||||
for extension in DEMUXER_EXTENSIONS:
|
||||
if input_filename.endswith(f'.{extension}'):
|
||||
input_filename = input_filename[:-1 - len(extension)]
|
||||
|
||||
# try to set an output file name automatically
|
||||
output_file = pathlib.Path(f'{input_filename}_output.mp4')
|
||||
|
||||
output_file_id = 0
|
||||
while output_file.is_file() and output_file_id <= 10:
|
||||
output_file = pathlib.Path(f'{input_filename}_output_{output_file_id}.mp4')
|
||||
output_file_id += 1
|
||||
|
||||
if not output_file.exists():
|
||||
self.output_file.set(str(output_file))
|
||||
|
||||
def _select_output(self):
|
||||
self.output_file.set(asksaveasfilename(title='Select Output File'))
|
||||
|
||||
|
||||
def read_config(config_file):
|
||||
""" Reads configuration file
|
||||
|
||||
Returns a dictionary read by parsing Video2X config.
|
||||
"""
|
||||
with open(config_file, 'r') as raw_config:
|
||||
config = yaml.load(raw_config, Loader=yaml.FullLoader)
|
||||
return config
|
||||
|
||||
|
||||
def absolutify_paths(config):
|
||||
""" Check to see if paths to binaries are absolute
|
||||
|
||||
This function checks if paths to binary files are absolute.
|
||||
If not, then absolutify the path.
|
||||
|
||||
Arguments:
|
||||
config {dict} -- configuration file dictionary
|
||||
|
||||
Returns:
|
||||
dict -- configuration file dictionary
|
||||
"""
|
||||
current_directory = pathlib.Path(sys.argv[0]).parent.absolute()
|
||||
|
||||
# check waifu2x-caffe path
|
||||
if not re.match('^[a-z]:', config['waifu2x_caffe']['path'], re.IGNORECASE):
|
||||
config['waifu2x_caffe']['path'] = current_directory / config['waifu2x_caffe']['path']
|
||||
|
||||
# check waifu2x-converter-cpp path
|
||||
if not re.match('^[a-z]:', config['waifu2x_converter']['path'], re.IGNORECASE):
|
||||
config['waifu2x_converter']['path'] = current_directory / config['waifu2x_converter']['path']
|
||||
|
||||
# check waifu2x_ncnn_vulkan path
|
||||
if not re.match('^[a-z]:', config['waifu2x_ncnn_vulkan']['path'], re.IGNORECASE):
|
||||
config['waifu2x_ncnn_vulkan']['path'] = current_directory / config['waifu2x_ncnn_vulkan']['path']
|
||||
|
||||
# check ffmpeg path
|
||||
if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
|
||||
config['ffmpeg']['ffmpeg_path'] = current_directory / config['ffmpeg']['ffmpeg_path']
|
||||
|
||||
# check video2x cache path
|
||||
if config['video2x']['video2x_cache_directory']:
|
||||
if not re.match('^[a-z]:', config['video2x']['video2x_cache_directory'], re.IGNORECASE):
|
||||
config['video2x']['video2x_cache_directory'] = current_directory / config['video2x']['video2x_cache_directory']
|
||||
|
||||
return config
|
||||
|
||||
|
||||
video2x_gui = Video2xGui()
|
||||
@@ -1,382 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Video2X Setup Script
|
||||
Creator: K4YT3X
|
||||
Date Created: November 28, 2018
|
||||
Last Modified: January 4, 2020
|
||||
|
||||
Editor: BrianPetkovsek
|
||||
Editor: SAT3LL
|
||||
|
||||
Description: This script helps installing all dependencies of video2x
|
||||
and generates a configuration for it.
|
||||
|
||||
Installation Details:
|
||||
- ffmpeg: %LOCALAPPDATA%\\video2x\\ffmpeg
|
||||
- waifu2x-caffe: %LOCALAPPDATA%\\video2x\\waifu2x-caffe
|
||||
- waifu2x-cpp-converter: %LOCALAPPDATA%\\video2x\\waifu2x-converter-cpp
|
||||
- waifu2x_ncnn_vulkan: %LOCALAPPDATA%\\video2x\\waifu2x-ncnn-vulkan
|
||||
- anime4k: %LOCALAPPDATA%\\video2x\\anime4k
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
from datetime import timedelta
|
||||
import argparse
|
||||
import contextlib
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import traceback
|
||||
import urllib
|
||||
import zipfile
|
||||
|
||||
# Requests doesn't come with windows, therefore
|
||||
# it will be installed as a dependency and imported
|
||||
# later in the script.
|
||||
# import requests
|
||||
|
||||
VERSION = '1.6.1'
|
||||
|
||||
# global static variables
|
||||
LOCALAPPDATA = pathlib.Path(os.getenv('localappdata'))
|
||||
VIDEO2X_CONFIG = pathlib.Path(sys.argv[0]).parent.absolute() / 'video2x.yaml'
|
||||
DRIVER_OPTIONS = ['all', 'waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan', 'anime4k']
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
"""Processes CLI arguments
|
||||
"""
|
||||
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
|
||||
# video options
|
||||
general_options = parser.add_argument_group('General Options')
|
||||
general_options.add_argument('-d', '--driver', help='driver to download and configure', action='store', choices=DRIVER_OPTIONS, default='all')
|
||||
|
||||
# parse arguments
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
class Video2xSetup:
|
||||
""" Install dependencies for video2x video enlarger
|
||||
|
||||
This library is meant to be executed as a stand-alone
|
||||
script. All files will be installed under %LOCALAPPDATA%\\video2x.
|
||||
"""
|
||||
|
||||
def __init__(self, driver, download_python_modules):
|
||||
self.driver = driver
|
||||
self.download_python_modules = download_python_modules
|
||||
self.trash = []
|
||||
|
||||
def run(self):
|
||||
if self.download_python_modules:
|
||||
print('\nInstalling Python libraries')
|
||||
self._install_python_requirements()
|
||||
|
||||
print('\nInstalling FFmpeg')
|
||||
self._install_ffmpeg()
|
||||
|
||||
if self.driver == 'all':
|
||||
self._install_waifu2x_caffe()
|
||||
self._install_waifu2x_converter_cpp()
|
||||
self._install_waifu2x_ncnn_vulkan()
|
||||
self._install_anime4k()
|
||||
elif self.driver == 'waifu2x_caffe':
|
||||
self._install_waifu2x_caffe()
|
||||
elif self.driver == 'waifu2x_converter':
|
||||
self._install_waifu2x_converter_cpp()
|
||||
elif self.driver == 'waifu2x_ncnn_vulkan':
|
||||
self._install_waifu2x_ncnn_vulkan()
|
||||
elif self.driver == 'anime4k':
|
||||
self._install_anime4k()
|
||||
|
||||
print('\nGenerating Video2X configuration file')
|
||||
self._generate_config()
|
||||
|
||||
print('\nCleaning up temporary files')
|
||||
self._cleanup()
|
||||
|
||||
def _install_python_requirements(self):
|
||||
""" Read requirements.txt and return its content
|
||||
"""
|
||||
pip_install('requirements.txt')
|
||||
|
||||
def _cleanup(self):
|
||||
""" Cleanup all the temp files downloaded
|
||||
"""
|
||||
for file in self.trash:
|
||||
try:
|
||||
if file.is_dir():
|
||||
print(f'Deleting directory: {file}')
|
||||
shutil.rmtree(file)
|
||||
else:
|
||||
print(f'Deleting file: {file}')
|
||||
file.unlink()
|
||||
except Exception:
|
||||
print(f'Error deleting: {file}')
|
||||
traceback.print_exc()
|
||||
|
||||
def _install_ffmpeg(self):
|
||||
""" Install FFMPEG
|
||||
"""
|
||||
latest_release = 'https://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.zip'
|
||||
|
||||
ffmpeg_zip = download(latest_release, tempfile.gettempdir())
|
||||
self.trash.append(ffmpeg_zip)
|
||||
|
||||
with zipfile.ZipFile(ffmpeg_zip) as zipf:
|
||||
zipf.extractall(LOCALAPPDATA / 'video2x')
|
||||
|
||||
def _install_waifu2x_caffe(self):
|
||||
""" Install waifu2x_caffe
|
||||
"""
|
||||
print('\nInstalling waifu2x-caffe')
|
||||
import requests
|
||||
|
||||
# Get latest release of waifu2x-caffe via GitHub API
|
||||
latest_release = requests.get('https://api.github.com/repos/lltcggie/waifu2x-caffe/releases/latest').json()
|
||||
|
||||
for a in latest_release['assets']:
|
||||
if 'waifu2x-caffe.zip' in a['browser_download_url']:
|
||||
waifu2x_caffe_zip = download(a['browser_download_url'], tempfile.gettempdir())
|
||||
self.trash.append(waifu2x_caffe_zip)
|
||||
|
||||
with zipfile.ZipFile(waifu2x_caffe_zip) as zipf:
|
||||
zipf.extractall(LOCALAPPDATA / 'video2x')
|
||||
|
||||
def _install_waifu2x_converter_cpp(self):
|
||||
""" Install waifu2x_caffe
|
||||
"""
|
||||
print('\nInstalling waifu2x-converter-cpp')
|
||||
import requests
|
||||
|
||||
# Get latest release of waifu2x-caffe via GitHub API
|
||||
latest_release = requests.get('https://api.github.com/repos/DeadSix27/waifu2x-converter-cpp/releases/latest').json()
|
||||
|
||||
for a in latest_release['assets']:
|
||||
if re.search(r'waifu2x-DeadSix27-win64_v[0-9]*\.zip', a['browser_download_url']):
|
||||
waifu2x_converter_cpp_zip = download(a['browser_download_url'], tempfile.gettempdir())
|
||||
self.trash.append(waifu2x_converter_cpp_zip)
|
||||
|
||||
with zipfile.ZipFile(waifu2x_converter_cpp_zip) as zipf:
|
||||
zipf.extractall(LOCALAPPDATA / 'video2x' / 'waifu2x-converter-cpp')
|
||||
|
||||
def _install_waifu2x_ncnn_vulkan(self):
|
||||
""" Install waifu2x-ncnn-vulkan
|
||||
"""
|
||||
print('\nInstalling waifu2x-ncnn-vulkan')
|
||||
import requests
|
||||
|
||||
# Get latest release of waifu2x-ncnn-vulkan via Github API
|
||||
latest_release = requests.get('https://api.github.com/repos/nihui/waifu2x-ncnn-vulkan/releases/latest').json()
|
||||
|
||||
for a in latest_release['assets']:
|
||||
if re.search(r'waifu2x-ncnn-vulkan-\d*\.zip', a['browser_download_url']):
|
||||
waifu2x_ncnn_vulkan_zip = download(a['browser_download_url'], tempfile.gettempdir())
|
||||
self.trash.append(waifu2x_ncnn_vulkan_zip)
|
||||
|
||||
# extract and rename
|
||||
waifu2x_ncnn_vulkan_directory = LOCALAPPDATA / 'video2x' / 'waifu2x-ncnn-vulkan'
|
||||
with zipfile.ZipFile(waifu2x_ncnn_vulkan_zip) as zipf:
|
||||
zipf.extractall(LOCALAPPDATA / 'video2x')
|
||||
|
||||
# if directory already exists, remove it
|
||||
if waifu2x_ncnn_vulkan_directory.exists():
|
||||
shutil.rmtree(waifu2x_ncnn_vulkan_directory)
|
||||
|
||||
# rename the newly extracted directory
|
||||
(LOCALAPPDATA / 'video2x' / zipf.namelist()[0]).rename(waifu2x_ncnn_vulkan_directory)
|
||||
|
||||
def _install_anime4k(self):
|
||||
""" Install Anime4K
|
||||
"""
|
||||
print('\nInstalling Anime4K')
|
||||
|
||||
"""
|
||||
import requests
|
||||
|
||||
# get latest release of Anime4K via Github API
|
||||
# at the time of writing this portion, Anime4K doesn't yet have a stable release
|
||||
# therefore releases/latest won't work
|
||||
latest_release = requests.get('https://api.github.com/repos/bloc97/Anime4K/releases').json()[0]
|
||||
|
||||
for a in latest_release['assets']:
|
||||
if 'Anime4K_Java.zip' in a['browser_download_url']:
|
||||
anime4k_zip = download(a['browser_download_url'], tempfile.gettempdir())
|
||||
self.trash.append(anime4k_zip)
|
||||
"""
|
||||
|
||||
# since Java pre-compiled release has been removed from download
|
||||
# page, we use this cached version as a temporary solution
|
||||
anime4k_zip = download('https://files.flexio.org/Resources/anime4k.zip', tempfile.gettempdir())
|
||||
self.trash.append(anime4k_zip)
|
||||
|
||||
# extract and rename
|
||||
with zipfile.ZipFile(anime4k_zip) as zipf:
|
||||
zipf.extractall(LOCALAPPDATA / 'video2x' / 'anime4k')
|
||||
|
||||
def _generate_config(self):
|
||||
""" Generate video2x config
|
||||
"""
|
||||
import yaml
|
||||
|
||||
# open current video2x configuration file as template
|
||||
with open(VIDEO2X_CONFIG, 'r') as template:
|
||||
template_dict = yaml.load(template, Loader=yaml.FullLoader)
|
||||
template.close()
|
||||
|
||||
# configure only the specified drivers
|
||||
if self.driver == 'all':
|
||||
template_dict['waifu2x_caffe']['path'] = str(LOCALAPPDATA / 'video2x' / 'waifu2x-caffe' / 'waifu2x-caffe-cui.exe')
|
||||
template_dict['waifu2x_converter']['path'] = str(LOCALAPPDATA / 'video2x' / 'waifu2x-converter-cpp')
|
||||
template_dict['waifu2x_ncnn_vulkan']['path'] = str(LOCALAPPDATA / 'video2x' / 'waifu2x-ncnn-vulkan' / 'waifu2x-ncnn-vulkan.exe')
|
||||
template_dict['anime4k']['path'] = str(LOCALAPPDATA / 'video2x' / 'anime4k' / 'Anime4K.jar')
|
||||
elif self.driver == 'waifu2x_caffe':
|
||||
template_dict['waifu2x_caffe']['path'] = str(LOCALAPPDATA / 'video2x' / 'waifu2x-caffe' / 'waifu2x-caffe-cui.exe')
|
||||
elif self.driver == 'waifu2x_converter':
|
||||
template_dict['waifu2x_converter']['path'] = str(LOCALAPPDATA / 'video2x' / 'waifu2x-converter-cpp')
|
||||
elif self.driver == 'waifu2x_ncnn_vulkan':
|
||||
template_dict['waifu2x_ncnn_vulkan']['path'] = str(LOCALAPPDATA / 'video2x' / 'waifu2x-ncnn-vulkan' / 'waifu2x-ncnn-vulkan.exe')
|
||||
elif self.driver == 'anime4k':
|
||||
template_dict['anime4k']['path'] = str(LOCALAPPDATA / 'video2x' / 'anime4k' / 'Anime4K.jar')
|
||||
|
||||
template_dict['ffmpeg']['ffmpeg_path'] = str(LOCALAPPDATA / 'video2x' / 'ffmpeg-latest-win64-static' / 'bin')
|
||||
template_dict['video2x']['video2x_cache_directory'] = None
|
||||
template_dict['video2x']['preserve_frames'] = False
|
||||
|
||||
# write configuration into file
|
||||
with open(VIDEO2X_CONFIG, 'w') as config:
|
||||
yaml.dump(template_dict, config)
|
||||
|
||||
|
||||
def download(url, save_path, chunk_size=4096):
|
||||
""" Download file to local with requests library
|
||||
"""
|
||||
from tqdm import tqdm
|
||||
import requests
|
||||
|
||||
save_path = pathlib.Path(save_path)
|
||||
|
||||
# create target folder if it doesn't exist
|
||||
save_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# create requests stream for steaming file
|
||||
stream = requests.get(url, stream=True, allow_redirects=True)
|
||||
|
||||
# get file name
|
||||
file_name = None
|
||||
if 'content-disposition' in stream.headers:
|
||||
disposition = stream.headers['content-disposition']
|
||||
with contextlib.suppress(IndexError):
|
||||
file_name = re.findall("filename=(.+)", disposition)[0].strip('"')
|
||||
|
||||
if file_name is None:
|
||||
# output_file = f'{save_path}\\{stream.url.split("/")[-1]}'
|
||||
output_file = save_path / stream.url.split('/')[-1]
|
||||
else:
|
||||
output_file = save_path / file_name
|
||||
|
||||
# decode url encoding
|
||||
output_file = pathlib.Path(urllib.parse.unquote(str(output_file)))
|
||||
|
||||
# get total size for progress bar if provided in headers
|
||||
total_size = 0
|
||||
if 'content-length' in stream.headers:
|
||||
total_size = int(stream.headers['content-length'])
|
||||
|
||||
# print download information summary
|
||||
print(f'Downloading: {url}')
|
||||
print(f'Total size: {total_size}')
|
||||
print(f'Chunk size: {chunk_size}')
|
||||
print(f'Saving to: {output_file}')
|
||||
|
||||
# Write content into file
|
||||
with open(output_file, 'wb') as output:
|
||||
with tqdm(total=total_size, ascii=True) as progress_bar:
|
||||
for chunk in stream.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
output.write(chunk)
|
||||
progress_bar.update(len(chunk))
|
||||
|
||||
# return the full path of saved file
|
||||
return output_file
|
||||
|
||||
|
||||
def pip_install(file):
|
||||
""" Install python package via python pip module
|
||||
|
||||
pip.main() is not available after pip 9.0.1, thus
|
||||
pip module is not used in this case.
|
||||
"""
|
||||
return subprocess.run([sys.executable, '-m', 'pip', 'install', '-U', '-r', file]).returncode
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
# set default exit code
|
||||
EXIT_CODE = 0
|
||||
|
||||
# get start time
|
||||
start_time = time.time()
|
||||
|
||||
# check platform
|
||||
if sys.platform != 'win32':
|
||||
print('This script is currently only compatible with Windows')
|
||||
EXIT_CODE = 1
|
||||
sys.exit(1)
|
||||
|
||||
# parse command line arguments
|
||||
args = parse_arguments()
|
||||
print('Video2X Setup Script')
|
||||
print(f'Version: {VERSION}')
|
||||
|
||||
# do not install pip modules if script
|
||||
# is packaged in exe format
|
||||
download_python_modules = True
|
||||
if sys.argv[0].endswith('.exe'):
|
||||
print('\nScript is packaged as exe, skipping pip module download')
|
||||
download_python_modules = False
|
||||
|
||||
setup = Video2xSetup(args.driver, download_python_modules)
|
||||
setup.run()
|
||||
print('\nScript finished successfully')
|
||||
|
||||
except SystemExit:
|
||||
pass
|
||||
|
||||
# if PermissionError is raised
|
||||
# user needs to run this with higher privilege
|
||||
except PermissionError:
|
||||
traceback.print_exc()
|
||||
print('You might have insufficient privilege for this script to run')
|
||||
print('Try running this script with Administrator privileges')
|
||||
EXIT_CODE = 1
|
||||
|
||||
# for any exception in the script
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print('An error has occurred')
|
||||
print('Video2X Automatic Setup has failed')
|
||||
|
||||
# in case of a failure, try cleaning up temp files
|
||||
try:
|
||||
setup._cleanup()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
print('An error occurred while trying to cleanup files')
|
||||
|
||||
EXIT_CODE = 1
|
||||
|
||||
# regardless if script finishes successfully or not
|
||||
# print script execution summary
|
||||
finally:
|
||||
print('Script finished')
|
||||
print(f'Time taken: {timedelta(seconds=round(time.time() - start_time))}')
|
||||
input('Press [ENTER] to exit script')
|
||||
sys.exit(EXIT_CODE)
|
||||
@@ -1,98 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Waifu2x Caffe Driver
|
||||
Author: K4YT3X
|
||||
Date Created: Feb 24, 2018
|
||||
Last Modified: October 6, 2019
|
||||
|
||||
Description: This class is a high-level wrapper
|
||||
for waifu2x-caffe.
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
|
||||
|
||||
class Waifu2xCaffe:
|
||||
"""This class communicates with waifu2x cui engine
|
||||
|
||||
An object will be created for this class, containing information
|
||||
about the binary address and the processing method. When being called
|
||||
by the main program, other detailed information will be passed to
|
||||
the upscale function.
|
||||
"""
|
||||
|
||||
def __init__(self, driver_settings, process, model_dir, bit_depth):
|
||||
self.driver_settings = driver_settings
|
||||
self.driver_settings['process'] = process
|
||||
self.driver_settings['model_dir'] = model_dir
|
||||
self.driver_settings['output_depth'] = bit_depth
|
||||
|
||||
# arguments passed through command line overwrites config file values
|
||||
self.process = process
|
||||
self.model_dir = model_dir
|
||||
self.print_lock = threading.Lock()
|
||||
|
||||
def upscale(self, input_directory, output_directory, scale_ratio, scale_width, scale_height, image_format, upscaler_exceptions):
|
||||
"""This is the core function for WAIFU2X class
|
||||
|
||||
Arguments:
|
||||
input_directory {string} -- source directory path
|
||||
output_directory {string} -- output directory path
|
||||
width {int} -- output video width
|
||||
height {int} -- output video height
|
||||
"""
|
||||
|
||||
try:
|
||||
# overwrite config file settings
|
||||
self.driver_settings['input_path'] = input_directory
|
||||
self.driver_settings['output_path'] = output_directory
|
||||
|
||||
if scale_ratio:
|
||||
self.driver_settings['scale_ratio'] = scale_ratio
|
||||
elif scale_width and scale_height:
|
||||
self.driver_settings['scale_width'] = scale_width
|
||||
self.driver_settings['scale_height'] = scale_height
|
||||
|
||||
self.driver_settings['output_extention'] = image_format
|
||||
|
||||
# print thread start message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started')
|
||||
self.print_lock.release()
|
||||
|
||||
# list to be executed
|
||||
# initialize the list with waifu2x binary path as the first element
|
||||
execute = [str(self.driver_settings['path'])]
|
||||
|
||||
for key in self.driver_settings.keys():
|
||||
|
||||
value = self.driver_settings[key]
|
||||
|
||||
# is executable key or null or None means that leave this option out (keep default)
|
||||
if key == 'path' or value is None or value is False:
|
||||
continue
|
||||
else:
|
||||
if len(key) == 1:
|
||||
execute.append(f'-{key}')
|
||||
else:
|
||||
execute.append(f'--{key}')
|
||||
execute.append(str(value))
|
||||
|
||||
Avalon.debug_info(f'Executing: {execute}')
|
||||
completed_command = subprocess.run(execute, check=True)
|
||||
|
||||
# print thread exiting message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting')
|
||||
self.print_lock.release()
|
||||
|
||||
# return command execution return code
|
||||
return completed_command.returncode
|
||||
except Exception as e:
|
||||
upscaler_exceptions.append(e)
|
||||
@@ -1,96 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Waifu2x Converter CPP Driver
|
||||
Author: K4YT3X
|
||||
Date Created: February 8, 2019
|
||||
Last Modified: October 6, 2019
|
||||
|
||||
Description: This class is a high-level wrapper
|
||||
for waifu2x-converter-cpp.
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
import pathlib
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
|
||||
|
||||
class Waifu2xConverter:
|
||||
"""This class communicates with waifu2x cui engine
|
||||
|
||||
An object will be created for this class, containing information
|
||||
about the binary address and the processing method. When being called
|
||||
by the main program, other detailed information will be passed to
|
||||
the upscale function.
|
||||
"""
|
||||
|
||||
def __init__(self, driver_settings, model_dir):
|
||||
self.driver_settings = driver_settings
|
||||
self.driver_settings['model_dir'] = model_dir
|
||||
self.print_lock = threading.Lock()
|
||||
|
||||
def upscale(self, input_directory, output_directory, scale_ratio, jobs, image_format, upscaler_exceptions):
|
||||
""" Waifu2x Converter Driver Upscaler
|
||||
This method executes the upscaling of extracted frames.
|
||||
|
||||
Arguments:
|
||||
input_directory {string} -- source directory path
|
||||
output_directory {string} -- output directory path
|
||||
scale_ratio {int} -- frames' scale ratio
|
||||
threads {int} -- number of threads
|
||||
"""
|
||||
|
||||
try:
|
||||
# overwrite config file settings
|
||||
self.driver_settings['input'] = input_directory
|
||||
self.driver_settings['output'] = output_directory
|
||||
self.driver_settings['scale-ratio'] = scale_ratio
|
||||
self.driver_settings['jobs'] = jobs
|
||||
self.driver_settings['output-format'] = image_format
|
||||
|
||||
# models_rgb must be specified manually for waifu2x-converter-cpp
|
||||
# if it's not specified in the arguments, create automatically
|
||||
if self.driver_settings['model-dir'] is None:
|
||||
self.driver_settings['model-dir'] = pathlib.Path(self.driver_settings['waifu2x_converter_path']) / 'models_rgb'
|
||||
|
||||
# print thread start message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started')
|
||||
self.print_lock.release()
|
||||
|
||||
# list to be executed
|
||||
# initialize the list with waifu2x binary path as the first element
|
||||
execute = [str(pathlib.Path(self.driver_settings['path']) / 'waifu2x-converter-cpp.exe')]
|
||||
|
||||
for key in self.driver_settings.keys():
|
||||
|
||||
value = self.driver_settings[key]
|
||||
|
||||
# the key doesn't need to be passed in this case
|
||||
if key == 'path':
|
||||
continue
|
||||
|
||||
# null or None means that leave this option out (keep default)
|
||||
elif value is None or value is False:
|
||||
continue
|
||||
else:
|
||||
if len(key) == 1:
|
||||
execute.append(f'-{key}')
|
||||
else:
|
||||
execute.append(f'--{key}')
|
||||
|
||||
# true means key is an option
|
||||
if value is True:
|
||||
continue
|
||||
|
||||
execute.append(str(value))
|
||||
|
||||
Avalon.debug_info(f'Executing: {execute}')
|
||||
return subprocess.run(execute, check=True).returncode
|
||||
|
||||
except Exception as e:
|
||||
upscaler_exceptions.append(e)
|
||||
@@ -1,94 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Name: Waifu2x NCNN Vulkan Driver
|
||||
Creator: SAT3LL
|
||||
Date Created: June 26, 2019
|
||||
Last Modified: November 15, 2019
|
||||
|
||||
Editor: K4YT3X
|
||||
Last Modified: January 4, 2020
|
||||
|
||||
Description: This class is a high-level wrapper
|
||||
for waifu2x_ncnn_vulkan.
|
||||
"""
|
||||
|
||||
# built-in imports
|
||||
import os
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
# third-party imports
|
||||
from avalon_framework import Avalon
|
||||
|
||||
|
||||
class Waifu2xNcnnVulkan:
|
||||
"""This class communicates with waifu2x ncnn vulkan engine
|
||||
|
||||
An object will be created for this class, containing information
|
||||
about the binary address and the processing method. When being called
|
||||
by the main program, other detailed information will be passed to
|
||||
the upscale function.
|
||||
"""
|
||||
|
||||
def __init__(self, driver_settings):
|
||||
self.driver_settings = driver_settings
|
||||
|
||||
# arguments passed through command line overwrites config file values
|
||||
|
||||
# waifu2x_ncnn_vulkan can't find its own model directory if its not in the current dir
|
||||
# so change to it
|
||||
os.chdir(os.path.join(self.driver_settings['path'], '..'))
|
||||
|
||||
self.print_lock = threading.Lock()
|
||||
|
||||
def upscale(self, input_directory, output_directory, scale_ratio, upscaler_exceptions):
|
||||
"""This is the core function for WAIFU2X class
|
||||
|
||||
Arguments:
|
||||
input_directory {string} -- source directory path
|
||||
output_directory {string} -- output directory path
|
||||
ratio {int} -- output video ratio
|
||||
"""
|
||||
|
||||
try:
|
||||
# overwrite config file settings
|
||||
self.driver_settings['i'] = input_directory
|
||||
self.driver_settings['o'] = output_directory
|
||||
self.driver_settings['s'] = int(scale_ratio)
|
||||
|
||||
# print thread start message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} started')
|
||||
self.print_lock.release()
|
||||
|
||||
# list to be executed
|
||||
# initialize the list with waifu2x binary path as the first element
|
||||
execute = [str(self.driver_settings['path'])]
|
||||
|
||||
for key in self.driver_settings.keys():
|
||||
|
||||
value = self.driver_settings[key]
|
||||
|
||||
# is executable key or null or None means that leave this option out (keep default)
|
||||
if key == 'path' or value is None or value is False:
|
||||
continue
|
||||
else:
|
||||
if len(key) == 1:
|
||||
execute.append(f'-{key}')
|
||||
else:
|
||||
execute.append(f'--{key}')
|
||||
execute.append(str(value))
|
||||
|
||||
Avalon.debug_info(f'Executing: {execute}')
|
||||
completed_command = subprocess.run(execute, check=True)
|
||||
|
||||
# print thread exiting message
|
||||
self.print_lock.acquire()
|
||||
Avalon.debug_info(f'[upscaler] Thread {threading.current_thread().name} exiting')
|
||||
self.print_lock.release()
|
||||
|
||||
# return command execution return code
|
||||
return completed_command.returncode
|
||||
except Exception as e:
|
||||
upscaler_exceptions.append(e)
|
||||
1
third_party/boost
vendored
Submodule
1
third_party/boost
vendored
Submodule
Submodule third_party/boost added at 65c1319bb9
1
third_party/librealesrgan_ncnn_vulkan
vendored
Submodule
1
third_party/librealesrgan_ncnn_vulkan
vendored
Submodule
Submodule third_party/librealesrgan_ncnn_vulkan added at cd68df6f98
1
third_party/ncnn
vendored
Submodule
1
third_party/ncnn
vendored
Submodule
Submodule third_party/ncnn added at 9b5f6a39b4
1
third_party/opencv
vendored
Submodule
1
third_party/opencv
vendored
Submodule
Submodule third_party/opencv added at 71d3237a09
1
third_party/spdlog
vendored
Submodule
1
third_party/spdlog
vendored
Submodule
Submodule third_party/spdlog added at e593f6695c
Reference in New Issue
Block a user