fix encode vod python errors
This commit is contained in:
@@ -5,6 +5,7 @@ import json
|
||||
import logging
|
||||
from datetime import datetime
|
||||
import shutil
|
||||
import time
|
||||
|
||||
# ANSI color codes
|
||||
class Colors:
|
||||
@@ -30,7 +31,14 @@ def get_gpu_selection():
|
||||
log_dir = "logs"
|
||||
os.makedirs(log_dir, exist_ok=True)
|
||||
log_file = os.path.join(log_dir, f"encode_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log")
|
||||
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Configure logging with Windows-safe settings
|
||||
logging.basicConfig(
|
||||
filename=log_file,
|
||||
level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||
filemode='w' # Explicitly set write mode
|
||||
)
|
||||
|
||||
def get_file_info(input_file):
|
||||
cmd = [
|
||||
@@ -106,7 +114,9 @@ def encode_dvr(input_file, output_dir, gpu):
|
||||
# FFmpeg command with NVIDIA HEVC encoder and maximum quality
|
||||
cmd = [
|
||||
'ffmpeg',
|
||||
'-v', 'verbose',
|
||||
'-v', 'info', # Lower verbosity to reduce noise
|
||||
'-stats', # Emit periodic stats
|
||||
'-stats_period', '1.0', # Update stats every 1s (more stable)
|
||||
'-i', str(input_path),
|
||||
'-c:v', 'hevc_nvenc',
|
||||
'-gpu', gpu,
|
||||
@@ -130,22 +140,31 @@ def encode_dvr(input_file, output_dir, gpu):
|
||||
cmd.append(str(output_path))
|
||||
|
||||
try:
|
||||
# Run FFmpeg and capture output
|
||||
# Run FFmpeg and capture combined output (avoid dual-pipe deadlocks on Windows)
|
||||
process = subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
universal_newlines=True
|
||||
stderr=subprocess.STDOUT,
|
||||
universal_newlines=True,
|
||||
bufsize=1
|
||||
)
|
||||
|
||||
# Log FFmpeg output in real-time
|
||||
while True:
|
||||
output = process.stderr.readline()
|
||||
if output == '' and process.poll() is not None:
|
||||
|
||||
# Stream output line-by-line from a single pipe
|
||||
for line in iter(process.stdout.readline, ''):
|
||||
if not line:
|
||||
break
|
||||
if output:
|
||||
logging.info(f"FFmpeg: {output.strip()}")
|
||||
print(f"{Colors.PURPLE}FFmpeg: {output.strip()}{Colors.ENDC}")
|
||||
text = line.strip()
|
||||
try:
|
||||
if text.startswith('frame=') or ' fps=' in text:
|
||||
logging.info(f"Progress: {text}")
|
||||
print(f"{Colors.PURPLE}Progress: {text}{Colors.ENDC}")
|
||||
else:
|
||||
logging.info(f"FFmpeg: {text}")
|
||||
print(f"{Colors.GREEN}FFmpeg: {text}{Colors.ENDC}")
|
||||
except (OSError, IOError):
|
||||
pass
|
||||
|
||||
process.wait()
|
||||
|
||||
if process.returncode == 0:
|
||||
# Get output file info
|
||||
|
||||
Reference in New Issue
Block a user