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

@ -120,7 +120,8 @@ class ContentDownloader:
print(f'{Fore.RED}✗ Chat download failed: {str(e)}{Style.RESET_ALL}')
return False
def render_chat(self, json_path: str, video_path: str, output_args: str) -> bool:
def render_chat(self, json_path: str, video_path: str, output_args: str,
video_duration: Optional[float] = None) -> bool:
"""
Render chat JSON as a video.
@ -128,6 +129,7 @@ class ContentDownloader:
json_path: Path to chat JSON file
video_path: Path to save rendered chat video
output_args: FFmpeg output arguments for encoding
video_duration: Optional video duration in seconds to trim chat to match
Returns:
bool: True if succeeded, False otherwise
@ -164,6 +166,13 @@ class ContentDownloader:
'--collision', 'Rename'
]
# Trim chat to match video duration if provided
if video_duration is not None and video_duration > 0:
# Format duration as seconds with 1 decimal place
duration_str = f'{video_duration:.1f}s'
chat_settings.extend(['-e', duration_str])
print(f'{Fore.CYAN} Trimming chat to match video duration: {duration_str}{Style.RESET_ALL}')
# Add output args using = syntax to avoid parsing issues
if output_args:
chat_settings.append(f'--output-args={output_args}')
@ -188,7 +197,8 @@ class ContentDownloader:
return False
def download_and_render_chat(self, vod_info: Dict[str, Any], json_path: str,
video_path: str, output_args: str) -> bool:
video_path: str, output_args: str,
video_duration: Optional[float] = None) -> bool:
"""
Download chat logs and render them as video.
@ -197,6 +207,7 @@ class ContentDownloader:
json_path: Path to save chat JSON
video_path: Path to save rendered chat video
output_args: FFmpeg output arguments for encoding
video_duration: Optional video duration in seconds to trim chat to match
Returns:
bool: True if succeeded, False otherwise
@ -213,8 +224,8 @@ class ContentDownloader:
if not self.download_chat_json(vod_id, json_path):
return False
# Render chat video
return self.render_chat(json_path, video_path, output_args)
# Render chat video with optional duration trimming
return self.render_chat(json_path, video_path, output_args, video_duration=video_duration)
def start_live_chat_download(self, vod_id: str, json_path: str) -> Optional[subprocess.Popen]:
"""