Skip to content

Using Video2X On Linux Without Root Access

k4yt3x edited this page Feb 11, 2022 · 1 revision

Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-74-generic x86_64)

[Environmet variable]

vi .bashrc

use a esc :w to add environment variable to the end of .bashrc

export PATH=~/lib/ffmpeg/bin:$PATH
export PATH=~/lib/cmake/bin:$PATH
export PATH=~/lib/opencv/bin:$PATH
export PATH=~/lib/gettext/bin:$PATH
export PATH=~/lib/help2man/bin:$PATH
export PATH=~/lib/texinfo/bin:$PATH
export PATH=~/lib/bison/bin:$PATH
export PATH=~/lib/indent/bin:$PATH
export PATH=~/lib/flex/bin:$PATH
export PATH=~/lib/doxygen/bin:$PATH
export PATH=~/lib/hdf5/bin:$PATH
export PATH=~/local/bin:$PATH
#export BOOST_INCLUDEDIR=~/local/include:$BOOST_INCLUDEDIR
export LIBRARY_PATH=~/local/lib:$LIBRARY_PATH
export LD_LIBRARY_PATH=~/local/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=~/lib/ffmpeg/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=~/lib/libcaffe:$LD_LIBRARY_PATH

activate environment variables

source .bashrc

This is what I install:
cmake 3.16.4
openssl 1.1.1d
opencv 3.4.1
m4 1.4.18
libtool 2.4.6
autoconf 2.69
gettext 0.20
help2man 1.47.9
texinfo 6.7
bison 3.5
indent 2.2.12
flex 2.64
doxygen 1.8.17
hdf5 1.10.6
ffmpeg 2019-10-13-1751e31

---still testing---  
(sudo apt install libboost-all-dev libgflags-dev libprotobuf-dev protobuf-compiler libgoogle-glog-dev libhdf5-dev liblmdb-dev libleveldb-dev libsnappy-dev libatlas-base-dev libmsgpack-dev)
boost 1.72.0  
automake 1.16.1  
glog 0.4.0  
gflags 2.2.2  
protobuf 3.11.3  
lmdb 0.9.24  
...  

[Install Deependencies]

cmake + openssl

if your cmake version is lower than 3.12.2, this may happen when you ./configure the caffe, because CUDA 10.0+ requires at least CMake 3.12.2+
Error: CUDA_cublas_device_LIBRARY (ADVANCED) not found

wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz
tar -xvzf OpenSSL_1_1_1d.tar.gz
cd openssl-OpenSSL_1_1_1d
./config --prefix= $HOME/lib/openssl
make –j
make install

wget https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4.tar.gz
tar -xvzf cmake-3.16.4.tar.gz
cd cmake-3.16.4
cmake -DOPENSSL_ROOT_DIR=~/lib/openssl -DOPENSSL_LIBRARIES=~/lib/openssl/lib
./configure --prefix= $HOME/lib/cmake
make -j
make install

opencv
(some of codes in caffe are not supported by opencv 4, but if you insist to use 4, you can edit cpp file by checking error output;you will need to edit 4 cpp file)

mkdir opencv
cd opencv
git clone -b 3.4.1 https://github.com/opencv/opencv
git clone -b 3.4.1 https://github.com/opencv/opencv_contrib
cd opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=~/lib/opencv ..
make -j
make install

m4

wget http://mirrors.kernel.org/gnu/m4/m4-1.4.18.tar.gz
tar -xzvf m4-1.4.18.tar.gz
cd m4-1.4.18
./configure --prefix=$HOME/local
make -j
make install

libtool

wget http://mirrors.kernel.org/gnu/libtool/libtool-2.4.6.tar.gz
tar -xzvf libtool-2.4.6.tar.gz
cd libtool-2.4.6
./configure --prefix=$HOME/local
make -j
make install

autoconf

wget http://mirrors.kernel.org/gnu/autoconf/autoconf-2.69.tar.gz
tar -xzvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=$HOME/local
make -j
make install

gettext

wget https://ftp.gnu.org/pub/gnu/gettext/gettext-0.20.tar.gz
tar -xvzf gettext-0.20.tar.gz
cd gettext-0.20
./configure --prefix=$HOME/lib/gettext
make -j
make install

help2man

wget http://mirrors.kernel.org/gnu/help2man/help2man-1.47.9.tar.xz
tar -xvJf help2man-1.47.9.tar.xz
cd help2man-1.47.9
./configure --prefix=$HOME/lib/help2man
make -j
make install

texinfo

wget http://mirrors.kernel.org/gnu/texinfo/texinfo-6.7.tar.gz
tar -xvzf texinfo-6.7.tar.gz
cd texinfo-6.7
./configure --prefix=$HOME/lib/texinfo
make -j
make install

bison

wget http://mirrors.kernel.org/gnu/bison/bison-3.5.tar.gz
tar -xvzf bison-3.5.tar.gz
cd bison-3.5
./configure --prefix=$HOME/lib/bison
make -j
make install

indent

wget https://ftp.gnu.org/gnu/indent/indent-2.2.12.tar.gz
tar -xvzf indent-2.2.12.tar.gz
cd indent-2.2.12
./configure --prefix=$HOME/lib/indent
make -j
make install

flex

wget https://github.com/westes/flex/releases/download/v2.6.3/flex-2.6.3.tar.gz
tar -xvzf flex-2.6.3.tar.gz
cd flex-2.6.3
./configure --prefix=$HOME/lib/flex
make -j
make install

doxgen

wget https://github.com/doxygen/doxygen/archive/Release_1_8_17.tar.gz
tar -xvzf Release_1_8_17.tar.gz
cd doxygen-Release_1_8_17
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=~/lib/doxygen ..
make install

hdf5

wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.6/src/hdf5-1.10.6.tar.gz
tar -xvzf hdf5-1.10.6.tar.gz
cd hdf5-1.10.6
./configure --prefix=$HOME/lib/hdf5
make -j
make install

ffmpeg

git clone https://github.com/markus-perl/ffmpeg-build-script.git
cd ffmpeg-build-script
./build-ffmpeg --build

If you want x265 support 10 bit (optional) Before ./build-ffmpeg --build

vim build-ffmpeg

Add sleep 1m to line 324, and then ./build-ffmpeg --build Wait x265 and you will have 1 min (you need open another window)

cd packages/x265_3.2/source/
vim CMakeLists.txt

Switch

option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" OFF)

with

option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" ON)

After x265 build finish

./x265 --help

Check the Output info, it should contains 10bit

x265 [info]: HEVC encoder version 3.2
x265 [info]: build info [Linux][GCC 7.4.0][64 bit] 10bit

Install the binary to your /usr/local/bin folder? [Y/n] n

mv workspace ffmpeg
cp -r ffmpeg ~/lib

numpy

pip2 install numpy

#boost

wget https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz
tar -zxvf boost_1_72_0.tar.gz
cd boost_1_72_0
./bootstrap.sh --prefix=$HOME/local
./b2 -j20
./b2 install

#automake

wget http://mirrors.kernel.org/gnu/automake/automake-1.16.1.tar.gz
tar -zxvf automake-1.16.1.tar.gz
cd automake-1.16.1
./configure --prefix=$HOME/local
make -j
make install

#gflags

git clone https://github.com/gflags/gflags.git
cd gflags
mkdir build
cd build
CXXFLAGS="-fPIC" cmake -D CMAKE_INSTALL_PREFIX=$HOME/local ..
make -j
make install

#glog

git clone https://github.com/google/glog.git
cd glog
./autogen.sh
./configure --prefix=$HOME/local
make -j
make install

#protobuf

wget https://github.com/protocolbuffers/protobuf/releases/download/v3.11.3/protobuf-cpp-3.11.3.tar.gz
tar -zxvf protobuf-cpp-3.11.3.tar.gz
cd protobuf-3.11.3
./autogen.sh
./configure --prefix=$HOME/local
make -j
make install

#lmdb

wget https://github.com/LMDB/lmdb/archive/LMDB_0.9.24.tar.gz
tar -zxvf LMDB_0.9.24.tar.gz
cd lmdb-LMDB_0.9.24/libraries/liblmdb
make -j
make prefix=$HOME/local install

[Build waifu2x-caffe-ubuntu]

git clone --recurse-submodules https://github.com/nagadomi/waifu2x-caffe-ubuntu.git
cd waifu2x-caffe-ubuntu
git clone https://github.com/nagadomi/caffe.git

find this file and edit it /caffe/cmake/Dependencies.cmake search

# ---[ HDF5
find_package(HDF5 COMPONENTS HL REQUIRED)
include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES})

add this line
list(APPEND Caffe_LINKER_LIBS ${HDF5_HL_LIBRARIES})
now we can start to build

mkdir build
cd build
cmake ..
cmake ..
make -j
mv libcaffe/lib libcaffe/libcaffe
cp -r libcaffe/libaoffe ~/lib
cp waifu2x-caffe ../bin/

[Video2x]

cd
git clone https://github.com/k4yt3x/video2x.git
cd video2x/bin
cp -r ~/waifu2x-caffe-ubuntu/bin/ waifu2x-caffe
pip3 install --user -r requirements.txt

[Modify Video2X to work on Linux]
Video2X is not designed for Linux atm, so I modified some of the code to get it working. By the time you're reading this, these issues might be fixed:

Bug fix 1: (required) Video2X uses absolute paths instead of relative paths. Without this fix Video2X can't find the programs it's calling.

video2x.json, line 3: Switch

"waifu2x_caffe_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\waifu2x-caffe\\waifu2x-caffe-cui.exe",

with

"waifu2x_caffe_path": "waifu2x-caffe/waifu2x-caffe",

video2x.json, line 59: Switch

"ffmpeg_path": "C:\\Users\\K4YT3X\\AppData\\Local\\video2x\\ffmpeg-latest-win64-static\\bin",

with

"ffmpeg_path": "",

ffmpeg.py, line 33 Switch

self.ffmpeg_binary = self.ffmpeg_path / 'ffmpeg.exe'
self.ffmpeg_probe_binary = self.ffmpeg_path / 'ffprobe.exe

with

self.ffmpeg_binary = self.ffmpeg_path / 'ffmpeg'
self.ffmpeg_probe_binary = self.ffmpeg_path / 'ffprobe'

video2x.py, line 230 Switch

    if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
        config['ffmpeg']['ffmpeg_path'] = current_directory / config['ffmpeg']['ffmpeg_path']

with

    #if not re.match('^[a-z]:', config['ffmpeg']['ffmpeg_path'], re.IGNORECASE):
    #    config['ffmpeg']['ffmpeg_path'] = current_directory / config['ffmpeg']['ffmpeg_path']

Bug fix 2: (required) Without this change ffmpeg errors out.

ffmpeg.py, line 287: Switch

return subprocess.run(execute, shell=True, check=True).returncode

with

return subprocess.run(execute, check=True).returncode

Bug fix 3: (optional) Video2X by default doesn't support embedded fonts in mkvs, which is pretty common in anime. This fixes this issue.

video2x.json, line 86 Switch

          "0:v:0?",
          "1?",
          "-1:v?"

with

          "0:v?",
          "1:a?",
          "1:s?",
          "1:d?",
          "1:t?"

Bug fix 4: (required) The pixel_formats variable is a dictionary, and Avalon.debug_info needs to be a string format.

open ffmpeg.py, goto line 70 Switch

Avalon.debug_info(pixel_formats)

with

Avalon.debug_info(str(pixel_formats))

You may still missing something else, but these instructions can still be a good reference.

Clone this wiki locally