swap back to nvenc/HEVC and redefine hosts accordingly
This commit is contained in:
+40
-15
@@ -11,10 +11,34 @@ import shutil
|
||||
import time
|
||||
|
||||
# Distributed mode requires tqdm and ffmpeg_distributed.py (SSH, Unix select.poll); on Windows use WSL or Linux.
|
||||
DISTRIBUTED_HOSTS_DEFAULT = ["Pyro", "RenderScrap", "root@GuiltsCurse", "PostIrony", "root@Godzilla"]
|
||||
DISTRIBUTED_REMOTE_ARGS_DEFAULT = "-c:v libaom-av1 -crf 0 -b:v 9000k -maxrate 9000k -bufsize 18000k -cpu-used 8 -row-mt 1 -an"
|
||||
# Workers = (ssh_host, gpu_index). Unraid (GuiltsCurse, Godzilla) excluded; RenderScrap has 2 GPUs.
|
||||
DISTRIBUTED_WORKERS_DEFAULT = [
|
||||
("Pyro", 0),
|
||||
("RenderScrap", 0),
|
||||
("RenderScrap", 1),
|
||||
("PostIrony", 0),
|
||||
]
|
||||
DISTRIBUTED_REMOTE_ARGS_DEFAULT = "-c:v hevc_nvenc -preset p7 -tune hq -rc vbr -rc-lookahead 32 -spatial-aq 1 -aq-strength 15 -cq 0 -b:v 9000k -maxrate 9000k -bufsize 18000k -an"
|
||||
DISTRIBUTED_SEGMENT_SECONDS = 60
|
||||
|
||||
|
||||
def _parse_workers_env(s):
|
||||
"""Parse DISTRIBUTED_WORKERS e.g. 'Pyro:0,RenderScrap:0,RenderScrap:1,PostIrony:0' -> [(host, gpu_id), ...]."""
|
||||
out = []
|
||||
for part in (s or "").strip().split(","):
|
||||
part = part.strip()
|
||||
if not part:
|
||||
continue
|
||||
if ":" in part:
|
||||
host, gpu = part.rsplit(":", 1)
|
||||
try:
|
||||
out.append((host.strip(), int(gpu.strip())))
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
out.append((part, 0))
|
||||
return out
|
||||
|
||||
# ANSI color codes
|
||||
class Colors:
|
||||
PURPLE = '\033[95m'
|
||||
@@ -342,9 +366,9 @@ def encode_dvr(input_file, output_dir, gpu):
|
||||
f"{Colors.RED}Unexpected error encoding {input_path}: {e}{Colors.ENDC}")
|
||||
|
||||
|
||||
def encode_dvr_distributed(input_file, output_dir, hosts, segment_seconds=60, remote_args=None, concat_args="-c:a copy", probe_host=None, probe_path=None, remote_ffmpeg_path=None):
|
||||
"""Encode one file using ffmpeg_distributed (split -> farm -> concat). Segment temp dirs go under script dir/tmp/.
|
||||
If probe_host and probe_path are set, ffprobe runs there (faster when input is on NAS)."""
|
||||
def encode_dvr_distributed(input_file, output_dir, workers, segment_seconds=60, remote_args=None, concat_args="-c:a copy", probe_host=None, probe_path=None, remote_ffmpeg_path=None):
|
||||
"""Encode one file using ffmpeg_distributed (split -> farm -> concat). workers = [(host, gpu_id), ...].
|
||||
Segment temp dirs go under script dir/tmp/. If probe_host and probe_path are set, ffprobe runs there (faster when input is on NAS)."""
|
||||
input_path = Path(input_file).resolve()
|
||||
output_path = (Path(output_dir) / f"{input_path.stem}{input_path.suffix}").resolve()
|
||||
if output_path.exists():
|
||||
@@ -366,11 +390,11 @@ def encode_dvr_distributed(input_file, output_dir, hosts, segment_seconds=60, re
|
||||
try:
|
||||
os.chdir(output_dir)
|
||||
from ffmpeg_distributed import encode as distributed_encode
|
||||
safe_log_info(f"Distributed encode: {input_path} -> {output_path} (hosts: {hosts})")
|
||||
print(f"{Colors.BLUE}Distributed encode (AV1): {input_path.name}{Colors.ENDC}")
|
||||
safe_log_info(f"Distributed encode: {input_path} -> {output_path} (workers: {workers})")
|
||||
print(f"{Colors.BLUE}Distributed encode (HEVC): {input_path.name}{Colors.ENDC}")
|
||||
remote_ffmpeg = remote_ffmpeg_path or os.environ.get("DISTRIBUTED_REMOTE_FFMPEG_PATH")
|
||||
distributed_encode(
|
||||
hosts,
|
||||
workers,
|
||||
str(input_path),
|
||||
str(output_path),
|
||||
segment_seconds=segment_seconds,
|
||||
@@ -399,13 +423,14 @@ if __name__ == "__main__":
|
||||
output_dir = "output"
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
hosts_str = os.environ.get("DISTRIBUTED_HOSTS")
|
||||
if hosts_str:
|
||||
hosts = [h.strip() for h in hosts_str.split(",") if h.strip()]
|
||||
workers_str = os.environ.get("DISTRIBUTED_WORKERS")
|
||||
if workers_str:
|
||||
workers = _parse_workers_env(workers_str)
|
||||
else:
|
||||
hosts = DISTRIBUTED_HOSTS_DEFAULT
|
||||
print(f"{Colors.BLUE}Using hosts: {', '.join(hosts)}{Colors.ENDC}")
|
||||
safe_log_info(f"Distributed mode; hosts: {hosts}")
|
||||
workers = DISTRIBUTED_WORKERS_DEFAULT
|
||||
workers_desc = ", ".join(f"{h}:gpu{g}" for h, g in workers)
|
||||
print(f"{Colors.BLUE}Using workers: {workers_desc}{Colors.ENDC}")
|
||||
safe_log_info(f"Distributed mode; workers: {workers}")
|
||||
|
||||
files = [f for f in os.listdir(input_dir) if f.endswith(('.mp4', '.DVR.mp4'))]
|
||||
total_files = len(files)
|
||||
@@ -419,4 +444,4 @@ if __name__ == "__main__":
|
||||
input_file = os.path.join(input_dir, file)
|
||||
safe_log_info(f"Processing file {i}/{total_files}: {file}")
|
||||
print(f"\n{Colors.BLUE}Processing file {i}/{total_files}: {file}{Colors.ENDC}")
|
||||
encode_dvr_distributed(input_file, output_dir, hosts, segment_seconds=DISTRIBUTED_SEGMENT_SECONDS)
|
||||
encode_dvr_distributed(input_file, output_dir, workers, segment_seconds=DISTRIBUTED_SEGMENT_SECONDS)
|
||||
Reference in New Issue
Block a user