ffmpeg dist working with av1
This commit is contained in:
+22
-5
@@ -1,3 +1,4 @@
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
@@ -9,10 +10,10 @@ from datetime import datetime
|
||||
import shutil
|
||||
import time
|
||||
|
||||
# Distributed encode defaults (AV1 CQ 0, maxrate 9000k; override via DISTRIBUTED_REMOTE_ARGS / DISTRIBUTED_HOSTS).
|
||||
# Distributed encode defaults (AV1 libaom: crf 0, maxrate 9000k; -cpu-used 8 = faster, -threads 0 = use all cores; override via DISTRIBUTED_REMOTE_ARGS).
|
||||
# Distributed mode requires tqdm and ffmpeg_distributed.py (SSH, Unix select.poll); on Windows use WSL or Linux.
|
||||
DISTRIBUTED_HOSTS_DEFAULT = ["PostIrony", "Pyro", "RenderScrap", "root@GuiltsCurse", "root@Godzilla"]
|
||||
DISTRIBUTED_REMOTE_ARGS_DEFAULT = "-c:v libsvtav1 -crf 0 -b:v 9000k -maxrate 9000k -bufsize 18000k -an"
|
||||
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 -threads 0 -an"
|
||||
DISTRIBUTED_SEGMENT_SECONDS = 60
|
||||
|
||||
# ANSI color codes
|
||||
@@ -342,8 +343,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"):
|
||||
"""Encode one file using ffmpeg_distributed (split -> farm -> concat). CWD is set to output_dir for temp files."""
|
||||
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)."""
|
||||
input_path = Path(input_file).resolve()
|
||||
output_path = (Path(output_dir) / f"{input_path.stem}{input_path.suffix}").resolve()
|
||||
if output_path.exists():
|
||||
@@ -351,12 +353,23 @@ def encode_dvr_distributed(input_file, output_dir, hosts, segment_seconds=60, re
|
||||
print(f"{Colors.YELLOW}Skipping {input_path} - output already exists{Colors.ENDC}")
|
||||
return
|
||||
remote_args = remote_args or os.environ.get("DISTRIBUTED_REMOTE_ARGS", DISTRIBUTED_REMOTE_ARGS_DEFAULT)
|
||||
probe_host = probe_host or os.environ.get("PROBE_HOST")
|
||||
if probe_path is None and probe_host and os.environ.get("PROBE_PATH_PREFIX"):
|
||||
prefix = os.environ.get("PROBE_PATH_PREFIX", "").rstrip("/")
|
||||
probe_path = f"{prefix}/{input_path.name}"
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
tmp_base = script_dir / "tmp"
|
||||
tmp_base.mkdir(exist_ok=True)
|
||||
path_for_hash = os.path.abspath(os.path.expanduser(str(input_path)))
|
||||
segment_hash = hashlib.md5(path_for_hash.encode()).hexdigest()
|
||||
tmp_dir = str(tmp_base / f"ffmpeg_segments_{segment_hash}")
|
||||
cwd = os.getcwd()
|
||||
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}")
|
||||
remote_ffmpeg = remote_ffmpeg_path or os.environ.get("DISTRIBUTED_REMOTE_FFMPEG_PATH")
|
||||
distributed_encode(
|
||||
hosts,
|
||||
str(input_path),
|
||||
@@ -364,6 +377,10 @@ def encode_dvr_distributed(input_file, output_dir, hosts, segment_seconds=60, re
|
||||
segment_seconds=segment_seconds,
|
||||
remote_args=remote_args,
|
||||
concat_args=concat_args,
|
||||
tmp_dir=tmp_dir,
|
||||
probe_host=probe_host,
|
||||
probe_path=probe_path,
|
||||
remote_ffmpeg_path=remote_ffmpeg,
|
||||
)
|
||||
if output_path.exists():
|
||||
safe_log_info(f"Successfully encoded: {output_path}", f"{Colors.GREEN}Successfully encoded: {output_path}{Colors.ENDC}")
|
||||
|
||||
Reference in New Issue
Block a user