Skip to content

Commit

Permalink
feat: added Dockerfile, PKGBUILD, and GHA workflows
Browse files Browse the repository at this point in the history
Signed-off-by: k4yt3x <[email protected]>
  • Loading branch information
k4yt3x committed Oct 7, 2024
1 parent f590ead commit bdbc6e9
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 20 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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@v2
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
- name: Build Video2X
run: |
mkdir -p /tmp/build /tmp/install
cmake -B /tmp/build -S . -DUSE_SYSTEM_NCNN=OFF \
-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/tmp/install
cmake --build /tmp/build --config Release --target install --parallel
- name: Package artifacts
run: |
tar cJvf /tmp/video2x-nightly.txz -C /tmp/install .
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: video2x-nightly
path: /tmp/video2x-nightly.txz
55 changes: 55 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Release
on:
push:
tags:
- "*"

jobs:
setup:
if: github.event.base_ref == 'refs/heads/master'
name: Setup
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.get_tag.outputs.tag }}
steps:
- name: Get tag
id: get_tag
run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//}

container:
name: Build and upload container
needs:
- setup
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- 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: Dockerfile
image: video2x
tags: latest, ${{ needs.setup.outputs.tag }}

create-release:
name: Create release
needs:
- setup
- container
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.setup.outputs.tag }}
release_name: Video2X ${{ needs.setup.outputs.tag }}
draft: true
prerelease: false
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ 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")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -s")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s")
endif()

# Build options
option(BUILD_SHARED_LIBS "Build libvideo2x as a shared library" ON)
option(BUILD_VIDEO2X "Build the video2x executable" ON)
Expand All @@ -40,12 +46,12 @@ if(WIN32)

# FFmpeg
list(APPEND ALL_LIBRARIES
${FFMPEG_BASE_PATH}/lib/avformat.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
${FFMPEG_BASE_PATH}/lib/avdevice.lib
)
list(APPEND ALL_INCLUDE_DIRS ${FFMPEG_BASE_PATH}/include)

Expand All @@ -68,12 +74,12 @@ else()
# Find the required packages using pkg-config
find_package(PkgConfig REQUIRED)
set(REQUIRED_PKGS
libavformat
libavcodec
libavdevice
libavfilter
libavformat
libavutil
libswscale
libavdevice
)

# Loop through each package to find and collect include dirs and libraries
Expand Down
45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Name: Video2X Dockerfile
# Creator: K4YT3X
# Date Created: February 3, 2022
# Last Modified: October 7, 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 ffmpeg ncnn git cmake make clang pkgconf vulkan-headers sudo \
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 makepkg -s --noconfirm \
&& find /video2x -maxdepth 1 -name '*.pkg.tar.zst' | 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 <[email protected]>" \
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

COPY --from=builder /tmp/video2x.pkg.tar.zst /video2x.pkg.tar.zst
COPY . /video2x
WORKDIR /video2x
RUN pacman -Sy --noconfirm ffmpeg ncnn \
nvidia-utils vulkan-radeon vulkan-intel vulkan-swrast \
&& pacman -U --noconfirm /video2x.pkg.tar.zst \
&& rm -rf /video2x.pkg.tar.zst /var/cache/pacman/pkg/*

WORKDIR /host
ENTRYPOINT ["/usr/bin/video2x"]
25 changes: 9 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
BINDIR=build

build:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B build
cmake --build build --config Release --parallel
cp build/compile_commands.json .
cmake -S . -B $(BINDIR) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release
cmake --build $(BINDIR) --config Release --parallel
cp $(BINDIR)/compile_commands.json .

static:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B build \
cmake -S . -B $(BINDIR) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF -DUSE_SYSTEM_NCNN=OFF
cmake --build build --config Release --parallel
cp build/compile_commands.json .
cmake --build $(BINDIR) --config Release --parallel
cp $(BINDIR)/compile_commands.json .

debug:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -S . -B build
cmake --build build --config Debug --parallel
cp build/compile_commands.json .

windows:
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S . -B build \
-DCMAKE_TOOLCHAIN_FILE=cmake/windows-x64-toolchain.cmake \
-DUSE_SYSTEM_NCNN=OFF -DBUILD_VIDEO2X=OFF
cmake --build build --config Release --parallel
cp build/compile_commands.json .
cmake -S . -B $(BINDIR) -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build $(BINDIR) --config Debug --parallel
cp $(BINDIR)/compile_commands.json .

test-realesrgan:
LD_LIBRARY_PATH=$(BINDIR) $(BINDIR)/video2x -i data/standard-test.mp4 -o data/output.mp4 \
Expand Down
27 changes: 27 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pkgname=video2x
pkgver=r862.f590ead
pkgrel=1
pkgdesc="A lossless video super resolution framework"
arch=('x86_64')
url="https://github.com/k4yt3x/video2x"
license=('AGPL3')
depends=('ffmpeg' 'ncnn' 'vulkan-driver')
makedepends=('git' 'cmake' 'make' 'clang' 'pkgconf' 'vulkan-headers')

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
}

0 comments on commit bdbc6e9

Please sign in to comment.