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

@ -98,6 +98,47 @@ def get_unique_filename(filepath: str) -> str:
counter += 1
def get_video_duration(video_path: str, ffmpeg_path: str) -> Optional[float]:
"""
Get the duration of a video file in seconds using FFmpeg.
Args:
video_path: Path to the video file
ffmpeg_path: Path to FFmpeg executable
Returns:
float: Duration in seconds, or None if failed
"""
if not os.path.exists(video_path):
return None
try:
# Use ffprobe (comes with ffmpeg) to get duration
ffprobe_path = ffmpeg_path.replace('ffmpeg', 'ffprobe')
cmd = [
ffprobe_path,
'-v', 'error',
'-show_entries', 'format=duration',
'-of', 'default=noprint_wrappers=1:nokey=1',
video_path
]
result = subprocess.run(
cmd,
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0 and result.stdout.strip():
return float(result.stdout.strip())
except Exception:
pass
return None
def verify_streamlink() -> bool:
"""
Verify that streamlink is available.