tripathiarpan20 commited on
Commit
ea28873
·
verified ·
1 Parent(s): ffad4cb

vidaio: upload miner files

Browse files
Files changed (2) hide show
  1. chute_config.yml +35 -0
  2. miner.py +75 -0
chute_config.yml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Image:
2
+ from_base: parachutes/python:3.12-cu13
3
+ set_user: chutes
4
+ run_command:
5
+ - uv pip install meson==1.5.1
6
+ set_user: root
7
+ run_command:
8
+ # Core build tools + runtime deps
9
+ - apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common curl build-essential cmake ninja-build nasm g++ pkg-config git wget unzip perl libx264-dev libx265-dev libvpx-dev nvidia-cuda-dev nvidia-cuda-toolkit python3-pip python3-venv && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Install nv-codec-headers (pinned commit)
12
+ - wget -q https://github.com/FFmpeg/nv-codec-headers/archive/876af32a202d0de83bd1d36fe74ee0f7fcf86b0d.zip && unzip -q 876af32a202d0de83bd1d36fe74ee0f7fcf86b0d.zip && cd nv-codec-headers-876af32a202d0de83bd1d36fe74ee0f7fcf86b0d && make && make install && cd .. && rm -rf nv-codec-headers-* 876af32a202d0de83bd1d36fe74ee0f7fcf86b0d.zip
13
+
14
+ # Build dav1d v1.4.2 (AV1 decoder)
15
+ - git clone --branch 1.4.2 --depth 1 https://code.videolan.org/videolan/dav1d.git && cd dav1d && mkdir build && cd build && meson setup .. --default-library=static --buildtype release && ninja && ninja install && ldconfig && cd ../.. && rm -rf dav1d
16
+
17
+ # Build ffmpeg (pinned commit 33b215d) with CUDA + NVENC + NVDEC + x264 + x265 + dav1d
18
+ - export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:/usr/local/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH" && git init ffmpeg && cd ffmpeg && git remote add origin https://github.com/FFmpeg/FFmpeg.git && git fetch --depth 1 origin 33b215d1554a14e87416a24f8e6034312e629af7 && git checkout FETCH_HEAD && ./configure --enable-gpl --enable-libx264 --enable-libx265 --enable-libvpx --enable-libdav1d --enable-nonfree --enable-cuda-nvcc --enable-nvenc --enable-nvdec --extra-cflags="-I/usr/local/cuda/include" --extra-ldflags="-L/usr/local/cuda/lib64" --disable-static --enable-shared --nvccflags="-gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -O2" && make -j$(nproc) && make install && ldconfig && cd .. && rm -rf ffmpeg
19
+
20
+ set_user: chutes
21
+ run_command:
22
+ - uv pip install --upgrade setuptools wheel
23
+ - uv pip install huggingface_hub==0.19.4 minio
24
+ set_user: chutes
25
+ set_workdir: /app
26
+
27
+ NodeSelector:
28
+ gpu_count: 1
29
+ min_vram_gb_per_gpu: 16
30
+
31
+ Chute:
32
+ shutdown_after_seconds: 600
33
+ concurrency: 1
34
+ max_instances: 3
35
+ scaling_threshold: 0.5
miner.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import shutil
3
+ import subprocess
4
+ import re
5
+ import time
6
+
7
+
8
+ class Miner:
9
+ """
10
+ Minimal upscaling miner using ffmpeg with NVENC GPU acceleration.
11
+ Uses CUDA hardware decoding, scale_cuda for GPU-based scaling,
12
+ and NVENC for hardware encoding.
13
+ Miners should fork this and improve upon it.
14
+
15
+ Required interface:
16
+ - Class must be named `Miner`
17
+ - __init__(self, path_hf_repo: Path) -> None
18
+ - process_video(self, input_path: Path, task_type: str) -> Path
19
+ - File must be named `miner.py` in the root of the HF repo
20
+ """
21
+
22
+ def __init__(self, path_hf_repo: Path) -> None:
23
+ self.repo_path = path_hf_repo
24
+
25
+ def __repr__(self) -> str:
26
+ return "UpscalingMiner(ffmpeg+nvenc)"
27
+
28
+ @staticmethod
29
+ def _run_cmd(cmd: list[str], step_name: str) -> None:
30
+ print(f"[miner] Running {step_name}: {' '.join(cmd)}")
31
+ start = time.time()
32
+ # NOTE: `close_fds` is required for Chutes, else it would trigger `aegis[integ] FATAL: security violation (secure authorization fd not valid)`
33
+ result = subprocess.run(cmd, capture_output=True, text=True, close_fds=False)
34
+ elapsed = time.time() - start
35
+ if result.stdout:
36
+ print(f"[miner] {step_name} stdout:\n{result.stdout}")
37
+ if result.stderr:
38
+ print(f"[miner] {step_name} stderr:\n{result.stderr}")
39
+ if result.returncode != 0:
40
+ raise subprocess.CalledProcessError(
41
+ result.returncode, cmd, result.stdout, result.stderr
42
+ )
43
+ print(f"[miner] {step_name} completed in {elapsed:.2f}s (exit code {result.returncode})")
44
+
45
+ def process_video(self, input_path: Path, task_type: str) -> Path:
46
+ scale_factor = 4 if task_type == "SD24K" else 2
47
+ output_path = input_path.with_name(f"{input_path.stem}_upscaled.mp4")
48
+
49
+ print(f"[miner] process_video called: input={input_path}, task_type={task_type}, scale={scale_factor}")
50
+ print(f"[miner] Input file exists: {input_path.exists()}, size: {input_path.stat().st_size if input_path.exists() else 'N/A'} bytes")
51
+
52
+ # Check tool availability
53
+ ffmpeg_path = shutil.which("ffmpeg")
54
+ print(f"[miner] ffmpeg location: {ffmpeg_path or 'NOT FOUND'}")
55
+
56
+ # Use hevc_nvenc to avoid h264_nvenc 4096px width limit
57
+ codec = "hevc_nvenc"
58
+
59
+ # GPU-accelerated upscale: CUDA decode -> scale_cuda -> NVENC encode
60
+ self._run_cmd(
61
+ [
62
+ "ffmpeg",
63
+ "-hwaccel", "cuda",
64
+ "-hwaccel_output_format", "cuda",
65
+ "-i", str(input_path),
66
+ "-vf", f"scale_cuda=iw*{scale_factor}:ih*{scale_factor}",
67
+ "-c:v", codec, "-preset", "p4", "-cq", "23",
68
+ "-c:a", "copy",
69
+ str(output_path),
70
+ ],
71
+ step_name="ffmpeg-nvenc-upscale",
72
+ )
73
+ print(f"[miner] Upscaled file exists: {output_path.exists()}, size: {output_path.stat().st_size if output_path.exists() else 'N/A'} bytes")
74
+
75
+ return output_path