Add video duration handling for chat rendering and merging

This commit is contained in:
MaddoScientisto 2026-02-10 08:04:08 +01:00
commit cdef8cf9bb
4 changed files with 126 additions and 19 deletions

View file

@ -191,6 +191,7 @@ class StreamProcessor:
return False
print(f'{Fore.YELLOW}Merging video and chat ({layout})...{Style.RESET_ALL}')
print(f'{Fore.CYAN} This may take several minutes depending on video length{Style.RESET_ALL}')
try:
if layout == 'overlay':
@ -222,6 +223,7 @@ class StreamProcessor:
if self.hwaccel_type and self.hwaccel_type != 'none':
encoder = get_hwaccel_encoder(self.hwaccel_type)
cmd.extend(['-c:v', encoder])
print(f'{Fore.CYAN} Using hardware encoder: {encoder}{Style.RESET_ALL}')
if 'nvenc' in encoder:
cmd.extend(['-preset', 'p4', '-cq', '18'])
@ -232,6 +234,7 @@ class StreamProcessor:
else:
cmd.extend(['-preset', 'medium', '-crf', '18'])
else:
print(f'{Fore.CYAN} Using software encoder: libx264{Style.RESET_ALL}')
cmd.extend(['-c:v', 'libx264', '-preset', 'medium', '-crf', '18'])
# Audio codec
@ -244,19 +247,20 @@ class StreamProcessor:
cmd.append(output_path)
# Run FFmpeg
if self.ffmpeg_progress:
result = subprocess.call(cmd)
else:
result = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT)
# Run FFmpeg with visible output to show progress
print(f'{Fore.CYAN} Processing...{Style.RESET_ALL}')
result = subprocess.call(cmd)
if result == 0:
print(f'{Fore.GREEN}✓ Video and chat merged successfully{Style.RESET_ALL}')
return True
else:
print(f'{Fore.RED}✗ Merge failed with exit code: {result}{Style.RESET_ALL}')
print(f'{Fore.YELLOW} Check FFmpeg output above for details{Style.RESET_ALL}')
return False
except Exception as e:
print(f'{Fore.RED}✗ Merge failed: {str(e)}{Style.RESET_ALL}')
import traceback
traceback.print_exc()
return False