fixed locks
This commit is contained in:
@@ -151,10 +151,11 @@ def run_vmaf_check(reference, distorted, status_callback=None):
|
||||
return -1.0
|
||||
|
||||
# --- Core Logic ---
|
||||
def process_file(filepath, log_category, lock_dir, log_dir, encoders, worker_id=0, status_cb=None):
|
||||
def process_file(filepath, log_category, lock_dir, log_dir, encoders, category_root=None, worker_id=0, status_cb=None):
|
||||
"""
|
||||
Process a single file.
|
||||
status_cb: function(worker_id, filename, status_text, color)
|
||||
category_root: Root directory (tv_dir or content_dir) for relative path calculation
|
||||
"""
|
||||
av1_enc, hevc_enc, hw_type = encoders
|
||||
filepath = Path(filepath)
|
||||
@@ -172,7 +173,7 @@ def process_file(filepath, log_category, lock_dir, log_dir, encoders, worker_id=
|
||||
return
|
||||
|
||||
# 1. Lock Check (Shared Storage)
|
||||
lock_file = common.acquire_lock(lock_dir, filepath)
|
||||
lock_file = common.acquire_lock(lock_dir, filepath, category_root)
|
||||
if not lock_file:
|
||||
return # Locked or skipped
|
||||
|
||||
@@ -354,6 +355,9 @@ def process_file(filepath, log_category, lock_dir, log_dir, encoders, worker_id=
|
||||
# Mark as processed to prevent re-encoding in future runs
|
||||
common.mark_processed(log_dir, filepath, chosen_codec, vmaf_score, final_savings)
|
||||
|
||||
# Mark lock as completed (keep it for future runs)
|
||||
common.mark_lock_completed(lock_file)
|
||||
|
||||
update("Done", "green")
|
||||
if status_cb: status_cb(worker_id, filename, f"STATS:SAVED:{saved_bytes}", "green")
|
||||
else:
|
||||
@@ -368,8 +372,10 @@ def process_file(filepath, log_category, lock_dir, log_dir, encoders, worker_id=
|
||||
|
||||
except Exception as e:
|
||||
update(f"Error: {str(e)[:30]}", "red")
|
||||
# On error, delete lock so file can be retried
|
||||
if lock_file and lock_file.exists():
|
||||
lock_file.unlink()
|
||||
finally:
|
||||
if lock_file.exists(): lock_file.unlink()
|
||||
update("Idle", "dim")
|
||||
|
||||
def main():
|
||||
@@ -463,9 +469,15 @@ def main():
|
||||
# 4. Execute
|
||||
print(f"\n🚀 Processing {len(tasks)} files...")
|
||||
|
||||
# Build category root map
|
||||
category_roots = {
|
||||
"tv_shows": Path(args.tv_dir),
|
||||
"content": Path(args.content_dir)
|
||||
}
|
||||
|
||||
with ThreadPoolExecutor(max_workers=args.jobs) as executor:
|
||||
futures = {
|
||||
executor.submit(process_file, f, cat, lock_dir, log_dir, (av1, hevc, hw)): f
|
||||
executor.submit(process_file, f, cat, lock_dir, log_dir, (av1, hevc, hw), category_roots.get(cat)): f
|
||||
for f, cat in tasks
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user